Mercurial > hg > xemacs-beta
annotate src/elhash.c @ 5411:fd714e8ba81e
Converted to GPLv3 or later. Written by Stephen Turnbull hence.GPLv2 or later.
author | Mats Lidell <matsl@xemacs.org> |
---|---|
date | Sun, 24 Oct 2010 00:20:52 +0200 |
parents | 308d34e9f07d |
children | 8d29f1c4bb98 |
rev | line source |
---|---|
428 | 1 /* Implementation of the hash table lisp object type. |
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
3 Copyright (C) 1995, 1996, 2002, 2004, 2010 Ben Wing. |
428 | 4 Copyright (C) 1997 Free Software Foundation, Inc. |
5 | |
6 This file is part of XEmacs. | |
7 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
428 | 9 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
11 option) any later version. |
428 | 12 |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
5232
33899241a6a8
Fix typo in permission notice of elhash.c.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5222
diff
changeset
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
428 | 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5277
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 20 |
21 /* Synched up with: Not in FSF. */ | |
22 | |
1292 | 23 /* Author: Lost in the mists of history. At least back to Lucid 19.3, |
24 circa Sep 1992. Early hash table implementation allowed only `eq' as a | |
25 test -- other tests possible only when these objects were created from | |
26 the C code. | |
27 | |
28 Expansion to allow general `equal'-test Lisp-creatable tables, and hash | |
29 methods for the various Lisp objects in existence at the time, added | |
30 during 19.12 I think (early 1995?), by Ben Wing. | |
31 | |
32 Weak hash tables added by Jamie (maybe?) early on, perhaps around 19.6, | |
33 maybe earlier; again, only possible through the C code, and only | |
34 supported fully weak hash tables. Expansion to other kinds of weakness, | |
35 and exporting of the interface to Lisp, by Ben Wing during 19.12 | |
36 (early-mid 1995) or maybe 19.13 cycle (mid 1995). | |
37 | |
38 Expansion to full Common Lisp spec and interface, redoing of the | |
39 implementation, by Martin Buchholz, 1997? (Former hash table | |
40 implementation used "double hashing", I'm pretty sure, and was weirdly | |
41 tied into the generic hash.c code. Martin completely separated them.) | |
42 */ | |
43 | |
489 | 44 /* This file implements the hash table lisp object type. |
45 | |
504 | 46 This implementation was mostly written by Martin Buchholz in 1997. |
47 | |
48 The Lisp-level API (derived from Common Lisp) is almost completely | |
49 compatible with GNU Emacs 21, even though the implementations are | |
50 totally independent. | |
51 | |
489 | 52 The hash table technique used is "linear probing". Collisions are |
53 resolved by putting the item in the next empty place in the array | |
54 following the collision. Finding a hash entry performs a linear | |
55 search in the cluster starting at the hash value. | |
56 | |
57 On deletions from the hash table, the entries immediately following | |
58 the deleted entry are re-entered in the hash table. We do not have | |
59 a special way to mark deleted entries (known as "tombstones"). | |
60 | |
61 At the end of the hash entries ("hentries"), we leave room for an | |
62 entry that is always empty (the "sentinel"). | |
63 | |
64 The traditional literature on hash table implementation | |
65 (e.g. Knuth) suggests that too much "primary clustering" occurs | |
66 with linear probing. However, this literature was written when | |
67 locality of reference was not a factor. The discrepancy between | |
68 CPU speeds and memory speeds is increasing, and the speed of access | |
69 to memory is highly dependent on memory caches which work best when | |
70 there is high locality of data reference. Random access to memory | |
71 is up to 20 times as expensive as access to the nearest address | |
72 (and getting worse). So linear probing makes sense. | |
73 | |
74 But the representation doesn't actually matter that much with the | |
75 current elisp engine. Funcall is sufficiently slow that the choice | |
76 of hash table implementation is noise. */ | |
77 | |
428 | 78 #include <config.h> |
79 #include "lisp.h" | |
80 #include "bytecode.h" | |
81 #include "elhash.h" | |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
82 #include "gc.h" |
489 | 83 #include "opaque.h" |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
84 #include "buffer.h" |
428 | 85 |
86 Lisp_Object Qhash_tablep; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
87 Lisp_Object Qeq, Qeql, Qequal, Qequalp; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
88 Lisp_Object Qeq_hash, Qeql_hash, Qequal_hash, Qequalp_hash; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
89 |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
90 static Lisp_Object Qhashtable, Qhash_table, Qmake_hash_table; |
442 | 91 static Lisp_Object Qweakness, Qvalue, Qkey_or_value, Qkey_and_value; |
428 | 92 static Lisp_Object Vall_weak_hash_tables; |
93 static Lisp_Object Qrehash_size, Qrehash_threshold; | |
94 static Lisp_Object Q_size, Q_test, Q_weakness, Q_rehash_size, Q_rehash_threshold; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
95 static Lisp_Object Vhash_table_test_eq, Vhash_table_test_eql; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
96 static Lisp_Object Vhash_table_test_weak_list; |
428 | 97 |
98 /* obsolete as of 19990901 in xemacs-21.2 */ | |
442 | 99 static Lisp_Object Qweak, Qkey_weak, Qvalue_weak, Qkey_or_value_weak; |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
100 static Lisp_Object Qnon_weak; |
428 | 101 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
102 /* A hash table test, with its associated hash function. equal_function may |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
103 call lisp_equal_function, and hash_function similarly may call |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
104 lisp_hash_function. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
105 struct Hash_Table_Test |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
106 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
107 NORMAL_LISP_OBJECT_HEADER header; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
108 Lisp_Object name; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
109 hash_table_equal_function_t equal_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
110 hash_table_hash_function_t hash_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
111 Lisp_Object lisp_equal_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
112 Lisp_Object lisp_hash_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
113 }; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
114 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
115 static Lisp_Object |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
116 mark_hash_table_test (Lisp_Object obj) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
117 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
118 Hash_Table_Test *http = XHASH_TABLE_TEST (obj); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
119 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
120 mark_object (http->name); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
121 mark_object (http->lisp_equal_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
122 mark_object (http->lisp_hash_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
123 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
124 return Qnil; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
125 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
126 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
127 static const struct memory_description hash_table_test_description_1[] = |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
128 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
129 { XD_LISP_OBJECT, offsetof (struct Hash_Table_Test, name) }, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
130 { XD_LISP_OBJECT, offsetof (struct Hash_Table_Test, lisp_equal_function) }, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
131 { XD_LISP_OBJECT, offsetof (struct Hash_Table_Test, lisp_hash_function) }, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
132 { XD_END } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
133 }; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
134 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
135 static const struct sized_memory_description hash_table_test_description = |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
136 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
137 sizeof (struct Hash_Table_Test), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
138 hash_table_test_description_1 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
139 }; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
140 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
141 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("hash-table-test", hash_table_test, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
142 mark_hash_table_test, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
143 hash_table_test_description_1, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
144 Hash_Table_Test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
145 /* A hash table. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
146 |
428 | 147 struct Lisp_Hash_Table |
148 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
149 NORMAL_LISP_OBJECT_HEADER header; |
665 | 150 Elemcount size; |
151 Elemcount count; | |
152 Elemcount rehash_count; | |
428 | 153 double rehash_size; |
154 double rehash_threshold; | |
665 | 155 Elemcount golden_ratio; |
1204 | 156 htentry *hentries; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
157 Lisp_Object test; |
428 | 158 enum hash_table_weakness weakness; |
159 Lisp_Object next_weak; /* Used to chain together all of the weak | |
160 hash tables. Don't mark through this. */ | |
161 }; | |
162 | |
1204 | 163 #define CLEAR_HTENTRY(htentry) \ |
164 ((*(EMACS_UINT*)(&((htentry)->key))) = 0, \ | |
165 (*(EMACS_UINT*)(&((htentry)->value))) = 0) | |
428 | 166 |
167 #define HASH_TABLE_DEFAULT_SIZE 16 | |
168 #define HASH_TABLE_DEFAULT_REHASH_SIZE 1.3 | |
169 #define HASH_TABLE_MIN_SIZE 10 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
170 #define HASH_TABLE_DEFAULT_REHASH_THRESHOLD(size, test) \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
171 (((size) > 4096 && EQ (Vhash_table_test_eq, test)) ? 0.7 : 0.6) |
428 | 172 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
173 #define HASHCODE(key, ht, http) \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
174 ((((!EQ (Vhash_table_test_eq, ht->test)) ? \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
175 (http)->hash_function (http, key) : \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
176 LISP_HASH (key)) * (ht)->golden_ratio) % (ht)->size) |
428 | 177 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
178 #define KEYS_EQUAL_P(key1, key2, test, http) \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
179 (EQ (key1, key2) || ((!EQ (Vhash_table_test_eq, test) && \ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
180 (http->equal_function) (http, key1, key2)))) |
428 | 181 |
182 #define LINEAR_PROBING_LOOP(probe, entries, size) \ | |
183 for (; \ | |
1204 | 184 !HTENTRY_CLEAR_P (probe) || \ |
428 | 185 (probe == entries + size ? \ |
1204 | 186 (probe = entries, !HTENTRY_CLEAR_P (probe)) : 0); \ |
428 | 187 probe++) |
188 | |
800 | 189 #ifdef ERROR_CHECK_STRUCTURES |
428 | 190 static void |
191 check_hash_table_invariants (Lisp_Hash_Table *ht) | |
192 { | |
193 assert (ht->count < ht->size); | |
194 assert (ht->count <= ht->rehash_count); | |
195 assert (ht->rehash_count < ht->size); | |
196 assert ((double) ht->count * ht->rehash_threshold - 1 <= (double) ht->rehash_count); | |
1204 | 197 assert (HTENTRY_CLEAR_P (ht->hentries + ht->size)); |
428 | 198 } |
199 #else | |
200 #define check_hash_table_invariants(ht) | |
201 #endif | |
202 | |
203 /* Return a suitable size for a hash table, with at least SIZE slots. */ | |
665 | 204 static Elemcount |
205 hash_table_size (Elemcount requested_size) | |
428 | 206 { |
207 /* Return some prime near, but greater than or equal to, SIZE. | |
208 Decades from the time of writing, someone will have a system large | |
209 enough that the list below will be too short... */ | |
665 | 210 static const Elemcount primes [] = |
428 | 211 { |
212 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031, | |
213 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783, | |
214 19219, 24989, 32491, 42257, 54941, 71429, 92861, 120721, 156941, | |
215 204047, 265271, 344857, 448321, 582821, 757693, 985003, 1280519, | |
216 1664681, 2164111, 2813353, 3657361, 4754591, 6180989, 8035301, | |
217 10445899, 13579681, 17653589, 22949669, 29834603, 38784989, | |
218 50420551, 65546729, 85210757, 110774011, 144006217, 187208107, | |
219 243370577, 316381771, 411296309, 534685237, 695090819, 903618083, | |
647 | 220 1174703521, 1527114613, 1985248999 /* , 2580823717UL, 3355070839UL */ |
428 | 221 }; |
222 /* We've heard of binary search. */ | |
223 int low, high; | |
224 for (low = 0, high = countof (primes) - 1; high - low > 1;) | |
225 { | |
226 /* Loop Invariant: size < primes [high] */ | |
227 int mid = (low + high) / 2; | |
228 if (primes [mid] < requested_size) | |
229 low = mid; | |
230 else | |
231 high = mid; | |
232 } | |
233 return primes [high]; | |
234 } | |
235 | |
236 | |
237 | |
238 static int | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
239 lisp_object_eql_equal (const Hash_Table_Test *UNUSED (http), Lisp_Object obj1, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
240 Lisp_Object obj2) |
428 | 241 { |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4820
diff
changeset
|
242 return EQ (obj1, obj2) || |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4820
diff
changeset
|
243 (NON_FIXNUM_NUMBER_P (obj1) && internal_equal (obj1, obj2, 0)); |
428 | 244 } |
245 | |
665 | 246 static Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
247 lisp_object_eql_hash (const Hash_Table_Test *UNUSED (http), Lisp_Object obj) |
428 | 248 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
249 return NON_FIXNUM_NUMBER_P (obj) ? |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
250 internal_hash (obj, 0, 0) : LISP_HASH (obj); |
428 | 251 } |
252 | |
253 static int | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
254 lisp_object_equal_equal (const Hash_Table_Test *UNUSED (http), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
255 Lisp_Object obj1, Lisp_Object obj2) |
428 | 256 { |
257 return internal_equal (obj1, obj2, 0); | |
258 } | |
259 | |
665 | 260 static Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
261 lisp_object_equal_hash (const Hash_Table_Test *UNUSED (http), Lisp_Object obj) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
262 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
263 return internal_hash (obj, 0, 0); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
264 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
265 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
266 static Hashcode |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
267 lisp_object_equalp_hash (const Hash_Table_Test *UNUSED (http), Lisp_Object obj) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
268 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
269 return internal_hash (obj, 0, 1); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
270 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
271 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
272 static int |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
273 lisp_object_equalp_equal (const Hash_Table_Test *UNUSED (http), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
274 Lisp_Object obj1, Lisp_Object obj2) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
275 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
276 return internal_equalp (obj1, obj2, 0); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
277 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
278 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
279 static Hashcode |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
280 lisp_object_general_hash (const Hash_Table_Test *http, Lisp_Object obj) |
428 | 281 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
282 struct gcpro gcpro1; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
283 Lisp_Object args[2] = { http->lisp_hash_function, obj }, res; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
284 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
285 /* Make sure any weakly referenced objects don't get collected before the |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
286 funcall: */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
287 GCPRO1 (args[0]); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
288 gcpro1.nvars = countof (args); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
289 res = IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
290 UNGCPRO; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
291 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
292 if (INTP (res)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
293 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
294 return (Hashcode) (XINT (res)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
295 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
296 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
297 #ifdef HAVE_BIGNUM |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
298 if (BIGNUMP (res)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
299 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
300 if (bignum_fits_emacs_int_p (XBIGNUM_DATA (res))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
301 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
302 return (Hashcode) bignum_to_emacs_int (XBIGNUM_DATA (res)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
303 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
304 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
305 signal_error (Qrange_error, "Not a valid hash code", res); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
306 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
307 #endif |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
308 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
309 dead_wrong_type_argument (Qintegerp, res); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
310 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
311 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
312 static int |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
313 lisp_object_general_equal (const Hash_Table_Test *http, Lisp_Object obj1, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
314 Lisp_Object obj2) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
315 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
316 struct gcpro gcpro1; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
317 Lisp_Object args[] = { http->lisp_equal_function, obj1, obj2 }, res; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
318 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
319 GCPRO1 (args[0]); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
320 gcpro1.nvars = countof (args); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
321 res = IGNORE_MULTIPLE_VALUES (Ffuncall (countof (args), args)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
322 UNGCPRO; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
323 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
324 return !(NILP (res)); |
428 | 325 } |
326 | |
327 | |
328 static Lisp_Object | |
329 mark_hash_table (Lisp_Object obj) | |
330 { | |
331 Lisp_Hash_Table *ht = XHASH_TABLE (obj); | |
332 | |
333 /* If the hash table is weak, we don't want to mark the keys and | |
334 values (we scan over them after everything else has been marked, | |
335 and mark or remove them as necessary). */ | |
336 if (ht->weakness == HASH_TABLE_NON_WEAK) | |
337 { | |
1204 | 338 htentry *e, *sentinel; |
428 | 339 |
340 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++) | |
1204 | 341 if (!HTENTRY_CLEAR_P (e)) |
428 | 342 { |
343 mark_object (e->key); | |
344 mark_object (e->value); | |
345 } | |
346 } | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
347 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
348 mark_object (ht->test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
349 |
428 | 350 return Qnil; |
351 } | |
352 | |
353 /* Equality of hash tables. Two hash tables are equal when they are of | |
354 the same weakness and test function, they have the same number of | |
355 elements, and for each key in the hash table, the values are `equal'. | |
356 | |
357 This is similar to Common Lisp `equalp' of hash tables, with the | |
358 difference that CL requires the keys to be compared with the test | |
359 function, which we don't do. Doing that would require consing, and | |
360 consing is a bad idea in `equal'. Anyway, our method should provide | |
361 the same result -- if the keys are not equal according to the test | |
362 function, then Fgethash() in hash_table_equal_mapper() will fail. */ | |
363 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
364 hash_table_equal (Lisp_Object hash_table1, Lisp_Object hash_table2, int depth, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
365 int foldcase) |
428 | 366 { |
367 Lisp_Hash_Table *ht1 = XHASH_TABLE (hash_table1); | |
368 Lisp_Hash_Table *ht2 = XHASH_TABLE (hash_table2); | |
1204 | 369 htentry *e, *sentinel; |
428 | 370 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
371 if (!(EQ (ht1->test, ht2->test)) || |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
372 (ht1->weakness != ht2->weakness) || |
428 | 373 (ht1->count != ht2->count)) |
374 return 0; | |
375 | |
376 depth++; | |
377 | |
378 for (e = ht1->hentries, sentinel = e + ht1->size; e < sentinel; e++) | |
1204 | 379 if (!HTENTRY_CLEAR_P (e)) |
428 | 380 /* Look up the key in the other hash table, and compare the values. */ |
381 { | |
382 Lisp_Object value_in_other = Fgethash (e->key, hash_table2, Qunbound); | |
383 if (UNBOUNDP (value_in_other) || | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4885
diff
changeset
|
384 !internal_equal_0 (e->value, value_in_other, depth, foldcase)) |
428 | 385 return 0; /* Give up */ |
386 } | |
387 | |
388 return 1; | |
389 } | |
442 | 390 |
391 /* This is not a great hash function, but it _is_ correct and fast. | |
392 Examining all entries is too expensive, and examining a random | |
393 subset does not yield a correct hash function. */ | |
665 | 394 static Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
395 hash_table_hash (Lisp_Object hash_table, int UNUSED (depth), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
396 int UNUSED (equalp)) |
442 | 397 { |
398 return XHASH_TABLE (hash_table)->count; | |
399 } | |
400 | |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
401 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
402 |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
403 struct hash_table_stats |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
404 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
405 struct usage_stats u; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
406 Bytecount hentries; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
407 }; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
408 |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
409 static void |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
410 hash_table_memory_usage (Lisp_Object hashtab, |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
411 struct generic_usage_stats *gustats) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
412 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
413 Lisp_Hash_Table *ht = XHASH_TABLE (hashtab); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
414 struct hash_table_stats *stats = (struct hash_table_stats *) gustats; |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
415 stats->hentries += |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
416 malloced_storage_size (ht->hentries, |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
417 sizeof (htentry) * (ht->size + 1), |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
418 &stats->u); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
419 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
420 |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
421 #endif /* MEMORY_USAGE_STATS */ |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
422 |
428 | 423 |
424 /* Printing hash tables. | |
425 | |
426 This is non-trivial, because we use a readable structure-style | |
427 syntax for hash tables. This means that a typical hash table will be | |
428 readably printed in the form of: | |
429 | |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
430 #s(hash-table :size 2 :data (key1 value1 key2 value2)) |
428 | 431 |
432 The supported hash table structure keywords and their values are: | |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
433 `:test' (eql (or nil), eq or equal) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
434 `:size' (a natnum or nil) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
435 `:rehash-size' (a float) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
436 `:rehash-threshold' (a float) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
437 `:weakness' (nil, key, value, key-and-value, or key-or-value) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
438 `:data' (a list) |
428 | 439 |
430 | 440 If `print-readably' is nil, then a simpler syntax is used, for example |
428 | 441 |
442 #<hash-table size 2/13 data (key1 value1 key2 value2) 0x874d> | |
443 | |
444 The data is truncated to four pairs, and the rest is shown with | |
445 `...'. This printer does not cons. */ | |
446 | |
447 | |
448 /* Print the data of the hash table. This maps through a Lisp | |
449 hash table and prints key/value pairs using PRINTCHARFUN. */ | |
450 static void | |
451 print_hash_table_data (Lisp_Hash_Table *ht, Lisp_Object printcharfun) | |
452 { | |
453 int count = 0; | |
1204 | 454 htentry *e, *sentinel; |
428 | 455 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
456 write_ascstring (printcharfun, " :data ("); |
428 | 457 |
458 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++) | |
1204 | 459 if (!HTENTRY_CLEAR_P (e)) |
428 | 460 { |
461 if (count > 0) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
462 write_ascstring (printcharfun, " "); |
428 | 463 if (!print_readably && count > 3) |
464 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
465 write_ascstring (printcharfun, "..."); |
428 | 466 break; |
467 } | |
468 print_internal (e->key, printcharfun, 1); | |
800 | 469 write_fmt_string_lisp (printcharfun, " %S", 1, e->value); |
428 | 470 count++; |
471 } | |
472 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
473 write_ascstring (printcharfun, ")"); |
428 | 474 } |
475 | |
476 static void | |
2286 | 477 print_hash_table (Lisp_Object obj, Lisp_Object printcharfun, |
478 int UNUSED (escapeflag)) | |
428 | 479 { |
480 Lisp_Hash_Table *ht = XHASH_TABLE (obj); | |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
481 Ascbyte pigbuf[350]; |
428 | 482 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
483 write_ascstring (printcharfun, |
826 | 484 print_readably ? "#s(hash-table" : "#<hash-table"); |
428 | 485 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
486 if (!(EQ (ht->test, Vhash_table_test_eql))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
487 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
488 write_fmt_string_lisp (printcharfun, " :test %S", |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
489 1, XHASH_TABLE_TEST (ht->test)->name); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
490 } |
428 | 491 |
492 if (ht->count || !print_readably) | |
493 { | |
494 if (print_readably) | |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
495 write_fmt_string (printcharfun, " :size %ld", (long) ht->count); |
428 | 496 else |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
497 write_fmt_string (printcharfun, " :size %ld/%ld", (long) ht->count, |
800 | 498 (long) ht->size); |
428 | 499 } |
500 | |
501 if (ht->weakness != HASH_TABLE_NON_WEAK) | |
502 { | |
800 | 503 write_fmt_string |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
504 (printcharfun, " :weakness %s", |
800 | 505 (ht->weakness == HASH_TABLE_WEAK ? "key-and-value" : |
506 ht->weakness == HASH_TABLE_KEY_WEAK ? "key" : | |
507 ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" : | |
508 ht->weakness == HASH_TABLE_KEY_VALUE_WEAK ? "key-or-value" : | |
509 "you-d-better-not-see-this")); | |
428 | 510 } |
511 | |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
512 if (ht->rehash_size != HASH_TABLE_DEFAULT_REHASH_SIZE) |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
513 { |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
514 float_to_string (pigbuf, ht->rehash_size); |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
515 write_fmt_string (printcharfun, " :rehash-size %s", pigbuf); |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
516 } |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
517 |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
518 if (ht->rehash_threshold |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
519 != HASH_TABLE_DEFAULT_REHASH_THRESHOLD (ht->size, ht->test)) |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
520 { |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
521 float_to_string (pigbuf, ht->rehash_threshold); |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
522 write_fmt_string (printcharfun, " :rehash-threshold %s", pigbuf); |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
523 } |
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
524 |
428 | 525 if (ht->count) |
526 print_hash_table_data (ht, printcharfun); | |
527 | |
528 if (print_readably) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4820
diff
changeset
|
529 write_ascstring (printcharfun, ")"); |
428 | 530 else |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
531 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj)); |
428 | 532 } |
533 | |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
534 #ifdef ERROR_CHECK_STRUCTURES |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
535 #define USED_IF_ERROR_CHECK_STRUCTURES(x) x |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
536 #else |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
537 #define USED_IF_ERROR_CHECK_STRUCTURES(x) UNUSED (x) |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
538 #endif |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
539 |
4117 | 540 #ifndef NEW_GC |
428 | 541 static void |
4117 | 542 free_hentries (htentry *hentries, |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
543 Elemcount USED_IF_ERROR_CHECK_STRUCTURES (size)) |
489 | 544 { |
800 | 545 #ifdef ERROR_CHECK_STRUCTURES |
489 | 546 /* Ensure a crash if other code uses the discarded entries afterwards. */ |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
547 deadbeef_memory (hentries, |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
548 (Rawbyte *) (hentries + size) - (Rawbyte *) hentries); |
489 | 549 #endif |
550 | |
551 if (!DUMPEDP (hentries)) | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
552 xfree (hentries); |
489 | 553 } |
554 | |
555 static void | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
556 finalize_hash_table (Lisp_Object obj) |
428 | 557 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
558 Lisp_Hash_Table *ht = XHASH_TABLE (obj); |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
559 free_hentries (ht->hentries, ht->size); |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
560 ht->hentries = 0; |
428 | 561 } |
3263 | 562 #endif /* not NEW_GC */ |
428 | 563 |
1204 | 564 static const struct memory_description htentry_description_1[] = { |
565 { XD_LISP_OBJECT, offsetof (htentry, key) }, | |
566 { XD_LISP_OBJECT, offsetof (htentry, value) }, | |
428 | 567 { XD_END } |
568 }; | |
569 | |
1204 | 570 static const struct sized_memory_description htentry_description = { |
571 sizeof (htentry), | |
572 htentry_description_1 | |
428 | 573 }; |
574 | |
3092 | 575 #ifdef NEW_GC |
576 static const struct memory_description htentry_weak_description_1[] = { | |
577 { XD_LISP_OBJECT, offsetof (htentry, key), 0, { 0 }, XD_FLAG_NO_KKCC}, | |
578 { XD_LISP_OBJECT, offsetof (htentry, value), 0, { 0 }, XD_FLAG_NO_KKCC}, | |
579 { XD_END } | |
580 }; | |
581 | |
582 static const struct sized_memory_description htentry_weak_description = { | |
583 sizeof (htentry), | |
584 htentry_weak_description_1 | |
585 }; | |
586 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
587 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("hash-table-entry", hash_table_entry, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
588 0, htentry_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
589 Lisp_Hash_Table_Entry); |
3092 | 590 #endif /* NEW_GC */ |
591 | |
1204 | 592 static const struct memory_description htentry_union_description_1[] = { |
593 /* Note: XD_INDIRECT in this table refers to the surrounding table, | |
594 and so this will work. */ | |
3092 | 595 #ifdef NEW_GC |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
596 { XD_INLINE_LISP_OBJECT_BLOCK_PTR, HASH_TABLE_NON_WEAK, |
3092 | 597 XD_INDIRECT (0, 1), { &htentry_description } }, |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
598 { XD_INLINE_LISP_OBJECT_BLOCK_PTR, 0, XD_INDIRECT (0, 1), |
3092 | 599 { &htentry_weak_description }, XD_FLAG_UNION_DEFAULT_ENTRY }, |
600 #else /* not NEW_GC */ | |
2367 | 601 { XD_BLOCK_PTR, HASH_TABLE_NON_WEAK, XD_INDIRECT (0, 1), |
2551 | 602 { &htentry_description } }, |
603 { XD_BLOCK_PTR, 0, XD_INDIRECT (0, 1), { &htentry_description }, | |
1204 | 604 XD_FLAG_UNION_DEFAULT_ENTRY | XD_FLAG_NO_KKCC }, |
3092 | 605 #endif /* not NEW_GC */ |
1204 | 606 { XD_END } |
607 }; | |
608 | |
609 static const struct sized_memory_description htentry_union_description = { | |
610 sizeof (htentry *), | |
611 htentry_union_description_1 | |
612 }; | |
613 | |
614 const struct memory_description hash_table_description[] = { | |
615 { XD_ELEMCOUNT, offsetof (Lisp_Hash_Table, size) }, | |
616 { XD_INT, offsetof (Lisp_Hash_Table, weakness) }, | |
617 { XD_UNION, offsetof (Lisp_Hash_Table, hentries), XD_INDIRECT (1, 0), | |
2551 | 618 { &htentry_union_description } }, |
440 | 619 { XD_LO_LINK, offsetof (Lisp_Hash_Table, next_weak) }, |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
620 { XD_LISP_OBJECT,offsetof (Lisp_Hash_Table, test) }, |
428 | 621 { XD_END } |
622 }; | |
623 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
624 DEFINE_DUMPABLE_LISP_OBJECT ("hash-table", hash_table, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
625 mark_hash_table, print_hash_table, |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
626 IF_OLD_GC (finalize_hash_table), |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
627 hash_table_equal, hash_table_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
628 hash_table_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
629 Lisp_Hash_Table); |
428 | 630 |
631 static Lisp_Hash_Table * | |
632 xhash_table (Lisp_Object hash_table) | |
633 { | |
1123 | 634 /* #### What's going on here? Why the gc_in_progress check? */ |
428 | 635 if (!gc_in_progress) |
636 CHECK_HASH_TABLE (hash_table); | |
637 check_hash_table_invariants (XHASH_TABLE (hash_table)); | |
638 return XHASH_TABLE (hash_table); | |
639 } | |
640 | |
641 | |
642 /************************************************************************/ | |
643 /* Creation of Hash Tables */ | |
644 /************************************************************************/ | |
645 | |
646 /* Creation of hash tables, without error-checking. */ | |
647 static void | |
648 compute_hash_table_derived_values (Lisp_Hash_Table *ht) | |
649 { | |
665 | 650 ht->rehash_count = (Elemcount) |
438 | 651 ((double) ht->size * ht->rehash_threshold); |
665 | 652 ht->golden_ratio = (Elemcount) |
428 | 653 ((double) ht->size * (.6180339887 / (double) sizeof (Lisp_Object))); |
654 } | |
655 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
656 static htentry * |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
657 allocate_hash_table_entries (Elemcount size) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
658 { |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
659 #ifdef NEW_GC |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
660 return XHASH_TABLE_ENTRY (alloc_lrecord_array |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
661 (size, &lrecord_hash_table_entry)); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
662 #else /* not NEW_GC */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
663 return xnew_array_and_zero (htentry, size); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
664 #endif /* not NEW_GC */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
665 } |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
666 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
667 static Lisp_Object decode_hash_table_test (Lisp_Object obj); |
450 | 668 |
669 Lisp_Object | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
670 make_general_lisp_hash_table (Lisp_Object test, |
665 | 671 Elemcount size, |
428 | 672 double rehash_size, |
673 double rehash_threshold, | |
674 enum hash_table_weakness weakness) | |
675 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
676 Lisp_Object hash_table = ALLOC_NORMAL_LISP_OBJECT (hash_table); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
677 Lisp_Hash_Table *ht = XHASH_TABLE (hash_table); |
428 | 678 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
679 assert (HASH_TABLE_TESTP (test)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
680 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
681 ht->test = test; |
438 | 682 ht->weakness = weakness; |
683 | |
684 ht->rehash_size = | |
685 rehash_size > 1.0 ? rehash_size : HASH_TABLE_DEFAULT_REHASH_SIZE; | |
686 | |
687 ht->rehash_threshold = | |
688 rehash_threshold > 0.0 ? rehash_threshold : | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
689 HASH_TABLE_DEFAULT_REHASH_THRESHOLD (size, ht->test); |
438 | 690 |
428 | 691 if (size < HASH_TABLE_MIN_SIZE) |
692 size = HASH_TABLE_MIN_SIZE; | |
665 | 693 ht->size = hash_table_size ((Elemcount) (((double) size / ht->rehash_threshold) |
438 | 694 + 1.0)); |
428 | 695 ht->count = 0; |
438 | 696 |
428 | 697 compute_hash_table_derived_values (ht); |
698 | |
1204 | 699 /* We leave room for one never-occupied sentinel htentry at the end. */ |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
700 ht->hentries = allocate_hash_table_entries (ht->size + 1); |
428 | 701 |
702 if (weakness == HASH_TABLE_NON_WEAK) | |
703 ht->next_weak = Qunbound; | |
704 else | |
705 ht->next_weak = Vall_weak_hash_tables, Vall_weak_hash_tables = hash_table; | |
706 | |
707 return hash_table; | |
708 } | |
709 | |
710 Lisp_Object | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
711 make_lisp_hash_table (Elemcount size, enum hash_table_weakness weakness, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
712 Lisp_Object test) |
428 | 713 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
714 test = decode_hash_table_test (test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
715 return make_general_lisp_hash_table (test, size, -1.0, -1.0, weakness); |
428 | 716 } |
717 | |
718 /* Pretty reading of hash tables. | |
719 | |
720 Here we use the existing structures mechanism (which is, | |
721 unfortunately, pretty cumbersome) for validating and instantiating | |
722 the hash tables. The idea is that the side-effect of reading a | |
723 #s(hash-table PLIST) object is creation of a hash table with desired | |
724 properties, and that the hash table is returned. */ | |
725 | |
726 /* Validation functions: each keyword provides its own validation | |
727 function. The errors should maybe be continuable, but it is | |
728 unclear how this would cope with ERRB. */ | |
729 static int | |
2286 | 730 hash_table_size_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
731 Error_Behavior errb) | |
428 | 732 { |
733 if (NATNUMP (value)) | |
734 return 1; | |
735 | |
563 | 736 maybe_signal_error_1 (Qwrong_type_argument, list2 (Qnatnump, value), |
2286 | 737 Qhash_table, errb); |
428 | 738 return 0; |
739 } | |
740 | |
665 | 741 static Elemcount |
428 | 742 decode_hash_table_size (Lisp_Object obj) |
743 { | |
744 return NILP (obj) ? HASH_TABLE_DEFAULT_SIZE : XINT (obj); | |
745 } | |
746 | |
747 static int | |
2286 | 748 hash_table_weakness_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
578 | 749 Error_Behavior errb) |
428 | 750 { |
442 | 751 if (EQ (value, Qnil)) return 1; |
752 if (EQ (value, Qt)) return 1; | |
753 if (EQ (value, Qkey)) return 1; | |
754 if (EQ (value, Qkey_and_value)) return 1; | |
755 if (EQ (value, Qkey_or_value)) return 1; | |
756 if (EQ (value, Qvalue)) return 1; | |
428 | 757 |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
758 #ifdef NEED_TO_HANDLE_21_4_CODE |
428 | 759 /* Following values are obsolete as of 19990901 in xemacs-21.2 */ |
442 | 760 if (EQ (value, Qnon_weak)) return 1; |
761 if (EQ (value, Qweak)) return 1; | |
762 if (EQ (value, Qkey_weak)) return 1; | |
763 if (EQ (value, Qkey_or_value_weak)) return 1; | |
764 if (EQ (value, Qvalue_weak)) return 1; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
765 #endif |
428 | 766 |
563 | 767 maybe_invalid_constant ("Invalid hash table weakness", |
428 | 768 value, Qhash_table, errb); |
769 return 0; | |
770 } | |
771 | |
772 static enum hash_table_weakness | |
773 decode_hash_table_weakness (Lisp_Object obj) | |
774 { | |
442 | 775 if (EQ (obj, Qnil)) return HASH_TABLE_NON_WEAK; |
776 if (EQ (obj, Qt)) return HASH_TABLE_WEAK; | |
777 if (EQ (obj, Qkey_and_value)) return HASH_TABLE_WEAK; | |
778 if (EQ (obj, Qkey)) return HASH_TABLE_KEY_WEAK; | |
779 if (EQ (obj, Qkey_or_value)) return HASH_TABLE_KEY_VALUE_WEAK; | |
780 if (EQ (obj, Qvalue)) return HASH_TABLE_VALUE_WEAK; | |
428 | 781 |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
782 #ifdef NEED_TO_HANDLE_21_4_CODE |
428 | 783 /* Following values are obsolete as of 19990901 in xemacs-21.2 */ |
442 | 784 if (EQ (obj, Qnon_weak)) return HASH_TABLE_NON_WEAK; |
785 if (EQ (obj, Qweak)) return HASH_TABLE_WEAK; | |
786 if (EQ (obj, Qkey_weak)) return HASH_TABLE_KEY_WEAK; | |
787 if (EQ (obj, Qkey_or_value_weak)) return HASH_TABLE_KEY_VALUE_WEAK; | |
788 if (EQ (obj, Qvalue_weak)) return HASH_TABLE_VALUE_WEAK; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
789 #endif |
428 | 790 |
563 | 791 invalid_constant ("Invalid hash table weakness", obj); |
1204 | 792 RETURN_NOT_REACHED (HASH_TABLE_NON_WEAK); |
428 | 793 } |
794 | |
795 static int | |
2286 | 796 hash_table_test_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
797 Error_Behavior errb) | |
428 | 798 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
799 Lisp_Object lookup; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
800 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
801 if (NILP (value)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
802 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
803 return 1; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
804 } |
428 | 805 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
806 lookup = Fassq (value, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
807 if (NILP (lookup)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
808 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
809 maybe_invalid_constant ("Invalid hash table test", |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
810 value, Qhash_table, errb); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
811 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
812 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
813 return 1; |
428 | 814 } |
815 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
816 static Lisp_Object |
428 | 817 decode_hash_table_test (Lisp_Object obj) |
818 { | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
819 Lisp_Object result; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
820 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
821 if (NILP (obj)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
822 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
823 obj = Qeql; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
824 } |
428 | 825 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
826 result = Fassq (obj, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
827 if (NILP (result)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
828 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
829 invalid_constant ("Invalid hash table test", obj); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
830 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
831 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
832 return XCDR (result); |
428 | 833 } |
834 | |
835 static int | |
2286 | 836 hash_table_rehash_size_validate (Lisp_Object UNUSED (keyword), |
837 Lisp_Object value, Error_Behavior errb) | |
428 | 838 { |
839 if (!FLOATP (value)) | |
840 { | |
563 | 841 maybe_signal_error_1 (Qwrong_type_argument, list2 (Qfloatp, value), |
428 | 842 Qhash_table, errb); |
843 return 0; | |
844 } | |
845 | |
846 { | |
847 double rehash_size = XFLOAT_DATA (value); | |
848 if (rehash_size <= 1.0) | |
849 { | |
563 | 850 maybe_invalid_argument |
428 | 851 ("Hash table rehash size must be greater than 1.0", |
852 value, Qhash_table, errb); | |
853 return 0; | |
854 } | |
855 } | |
856 | |
857 return 1; | |
858 } | |
859 | |
860 static double | |
861 decode_hash_table_rehash_size (Lisp_Object rehash_size) | |
862 { | |
4585
871eb054b34a
Document non-obvious usages.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4410
diff
changeset
|
863 /* -1.0 signals make_general_lisp_hash_table to use the default. */ |
428 | 864 return NILP (rehash_size) ? -1.0 : XFLOAT_DATA (rehash_size); |
865 } | |
866 | |
867 static int | |
2286 | 868 hash_table_rehash_threshold_validate (Lisp_Object UNUSED (keyword), |
869 Lisp_Object value, Error_Behavior errb) | |
428 | 870 { |
871 if (!FLOATP (value)) | |
872 { | |
563 | 873 maybe_signal_error_1 (Qwrong_type_argument, list2 (Qfloatp, value), |
428 | 874 Qhash_table, errb); |
875 return 0; | |
876 } | |
877 | |
878 { | |
879 double rehash_threshold = XFLOAT_DATA (value); | |
880 if (rehash_threshold <= 0.0 || rehash_threshold >= 1.0) | |
881 { | |
563 | 882 maybe_invalid_argument |
428 | 883 ("Hash table rehash threshold must be between 0.0 and 1.0", |
884 value, Qhash_table, errb); | |
885 return 0; | |
886 } | |
887 } | |
888 | |
889 return 1; | |
890 } | |
891 | |
892 static double | |
893 decode_hash_table_rehash_threshold (Lisp_Object rehash_threshold) | |
894 { | |
4585
871eb054b34a
Document non-obvious usages.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4410
diff
changeset
|
895 /* -1.0 signals make_general_lisp_hash_table to use the default. */ |
428 | 896 return NILP (rehash_threshold) ? -1.0 : XFLOAT_DATA (rehash_threshold); |
897 } | |
898 | |
899 static int | |
2286 | 900 hash_table_data_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
901 Error_Behavior errb) | |
428 | 902 { |
903 int len; | |
904 | |
4585
871eb054b34a
Document non-obvious usages.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4410
diff
changeset
|
905 /* Check for improper lists while getting length. */ |
428 | 906 GET_EXTERNAL_LIST_LENGTH (value, len); |
907 | |
908 if (len & 1) | |
909 { | |
563 | 910 maybe_sferror |
428 | 911 ("Hash table data must have alternating key/value pairs", |
912 value, Qhash_table, errb); | |
913 return 0; | |
914 } | |
4585
871eb054b34a
Document non-obvious usages.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4410
diff
changeset
|
915 |
428 | 916 return 1; |
917 } | |
918 | |
919 /* The actual instantiation of a hash table. This does practically no | |
920 error checking, because it relies on the fact that the paranoid | |
921 functions above have error-checked everything to the last details. | |
922 If this assumption is wrong, we will get a crash immediately (with | |
923 error-checking compiled in), and we'll know if there is a bug in | |
924 the structure mechanism. So there. */ | |
925 static Lisp_Object | |
926 hash_table_instantiate (Lisp_Object plist) | |
927 { | |
928 Lisp_Object hash_table; | |
929 Lisp_Object test = Qnil; | |
930 Lisp_Object size = Qnil; | |
931 Lisp_Object rehash_size = Qnil; | |
932 Lisp_Object rehash_threshold = Qnil; | |
933 Lisp_Object weakness = Qnil; | |
934 Lisp_Object data = Qnil; | |
935 | |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
936 if (KEYWORDP (Fcar (plist))) |
428 | 937 { |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
938 PROPERTY_LIST_LOOP_3 (key, value, plist) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
939 { |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
940 if (EQ (key, Q_test)) test = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
941 else if (EQ (key, Q_size)) size = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
942 else if (EQ (key, Q_rehash_size)) rehash_size = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
943 else if (EQ (key, Q_rehash_threshold)) rehash_threshold = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
944 else if (EQ (key, Q_weakness)) weakness = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
945 else if (EQ (key, Q_data)) data = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
946 else if (!KEYWORDP (key)) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
947 signal_error (Qinvalid_read_syntax, |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
948 "can't mix keyword and non-keyword hash table syntax", |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
949 key); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
950 else ABORT(); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
951 } |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
952 } |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
953 else |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
954 { |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
955 PROPERTY_LIST_LOOP_3 (key, value, plist) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
956 { |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
957 if (EQ (key, Qtest)) test = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
958 else if (EQ (key, Qsize)) size = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
959 else if (EQ (key, Qrehash_size)) rehash_size = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
960 else if (EQ (key, Qrehash_threshold)) rehash_threshold = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
961 else if (EQ (key, Qweakness)) weakness = value; |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
962 else if (EQ (key, Qdata)) data = value; |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
963 #ifdef NEED_TO_HANDLE_21_4_CODE |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
964 else if (EQ (key, Qtype))/*obsolete*/ weakness = value; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
965 #endif |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
966 else if (KEYWORDP (key)) |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
967 signal_error (Qinvalid_read_syntax, |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
968 "can't mix keyword and non-keyword hash table syntax", |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
969 key); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
970 else ABORT(); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
971 } |
428 | 972 } |
973 | |
974 /* Create the hash table. */ | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
975 hash_table = make_general_lisp_hash_table |
428 | 976 (decode_hash_table_test (test), |
977 decode_hash_table_size (size), | |
978 decode_hash_table_rehash_size (rehash_size), | |
979 decode_hash_table_rehash_threshold (rehash_threshold), | |
980 decode_hash_table_weakness (weakness)); | |
981 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
982 /* This can GC with a user-specified test. */ |
428 | 983 { |
984 struct gcpro gcpro1; | |
985 GCPRO1 (hash_table); | |
986 | |
987 /* And fill it with data. */ | |
988 while (!NILP (data)) | |
989 { | |
990 Lisp_Object key, value; | |
991 key = XCAR (data); data = XCDR (data); | |
992 value = XCAR (data); data = XCDR (data); | |
993 Fputhash (key, value, hash_table); | |
994 } | |
995 UNGCPRO; | |
996 } | |
997 | |
998 return hash_table; | |
999 } | |
1000 | |
1001 static void | |
1002 structure_type_create_hash_table_structure_name (Lisp_Object structure_name) | |
1003 { | |
1004 struct structure_type *st; | |
1005 | |
1006 st = define_structure_type (structure_name, 0, hash_table_instantiate); | |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1007 |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1008 /* First the keyword syntax: */ |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1009 define_structure_type_keyword (st, Q_test, hash_table_test_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1010 define_structure_type_keyword (st, Q_size, hash_table_size_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1011 define_structure_type_keyword (st, Q_rehash_size, hash_table_rehash_size_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1012 define_structure_type_keyword (st, Q_rehash_threshold, hash_table_rehash_threshold_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1013 define_structure_type_keyword (st, Q_weakness, hash_table_weakness_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1014 define_structure_type_keyword (st, Q_data, hash_table_data_validate); |
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1015 |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
1016 #ifdef NEED_TO_HANDLE_21_4_CODE |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
1017 /* Next the mutually exclusive, older, non-keyword syntax: */ |
428 | 1018 define_structure_type_keyword (st, Qtest, hash_table_test_validate); |
1019 define_structure_type_keyword (st, Qsize, hash_table_size_validate); | |
1020 define_structure_type_keyword (st, Qrehash_size, hash_table_rehash_size_validate); | |
1021 define_structure_type_keyword (st, Qrehash_threshold, hash_table_rehash_threshold_validate); | |
1022 define_structure_type_keyword (st, Qweakness, hash_table_weakness_validate); | |
1023 define_structure_type_keyword (st, Qdata, hash_table_data_validate); | |
1024 | |
1025 /* obsolete as of 19990901 in xemacs-21.2 */ | |
1026 define_structure_type_keyword (st, Qtype, hash_table_weakness_validate); | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1027 #endif |
428 | 1028 } |
1029 | |
1030 /* Create a built-in Lisp structure type named `hash-table'. | |
1031 We make #s(hashtable ...) equivalent to #s(hash-table ...), | |
1032 for backward compatibility. | |
1033 This is called from emacs.c. */ | |
1034 void | |
1035 structure_type_create_hash_table (void) | |
1036 { | |
1037 structure_type_create_hash_table_structure_name (Qhash_table); | |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
1038 #ifdef NEED_TO_HANDLE_21_4_CODE |
428 | 1039 structure_type_create_hash_table_structure_name (Qhashtable); /* compat */ |
5222
18c0b5909d16
Use keywords in structure syntax; new #define, NEED_TO_HANDLE_21_4_CODE 1
Aidan Kehoe <kehoea@parhasard.net>
parents:
5193
diff
changeset
|
1040 #endif |
428 | 1041 } |
1042 | |
1043 | |
1044 /************************************************************************/ | |
1045 /* Definition of Lisp-visible methods */ | |
1046 /************************************************************************/ | |
1047 | |
1048 DEFUN ("hash-table-p", Fhash_table_p, 1, 1, 0, /* | |
1049 Return t if OBJECT is a hash table, else nil. | |
1050 */ | |
1051 (object)) | |
1052 { | |
1053 return HASH_TABLEP (object) ? Qt : Qnil; | |
1054 } | |
1055 | |
1056 DEFUN ("make-hash-table", Fmake_hash_table, 0, MANY, 0, /* | |
1057 Return a new empty hash table object. | |
1058 Use Common Lisp style keywords to specify hash table properties. | |
1059 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1060 Keyword :test can be `eq', `eql' (default), `equal' or `equalp'. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1061 Comparison between keys is done using this function. If speed is important, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1062 consider using `eq'. When storing strings in the hash table, you will |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1063 likely need to use `equal' or `equalp' (for case-insensitivity). With other |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1064 objects, consider using a test function defined with |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1065 `define-hash-table-test', an emacs extension to this Common Lisp hash table |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1066 API. |
428 | 1067 |
1068 Keyword :size specifies the number of keys likely to be inserted. | |
1069 This number of entries can be inserted without enlarging the hash table. | |
1070 | |
1071 Keyword :rehash-size must be a float greater than 1.0, and specifies | |
1072 the factor by which to increase the size of the hash table when enlarging. | |
1073 | |
1074 Keyword :rehash-threshold must be a float between 0.0 and 1.0, | |
1075 and specifies the load factor of the hash table which triggers enlarging. | |
1076 | |
442 | 1077 Non-standard keyword :weakness can be `nil' (default), `t', `key-and-value', |
1078 `key', `value' or `key-or-value'. `t' is an alias for `key-and-value'. | |
428 | 1079 |
442 | 1080 A key-and-value-weak hash table, also known as a fully-weak or simply |
1081 as a weak hash table, is one whose pointers do not count as GC | |
1082 referents: for any key-value pair in the hash table, if the only | |
1083 remaining pointer to either the key or the value is in a weak hash | |
1084 table, then the pair will be removed from the hash table, and the key | |
1085 and value collected. A non-weak hash table (or any other pointer) | |
1086 would prevent the object from being collected. | |
428 | 1087 |
1088 A key-weak hash table is similar to a fully-weak hash table except that | |
1089 a key-value pair will be removed only if the key remains unmarked | |
1090 outside of weak hash tables. The pair will remain in the hash table if | |
1091 the key is pointed to by something other than a weak hash table, even | |
1092 if the value is not. | |
1093 | |
1094 A value-weak hash table is similar to a fully-weak hash table except | |
1095 that a key-value pair will be removed only if the value remains | |
1096 unmarked outside of weak hash tables. The pair will remain in the | |
1097 hash table if the value is pointed to by something other than a weak | |
1098 hash table, even if the key is not. | |
442 | 1099 |
1100 A key-or-value-weak hash table is similar to a fully-weak hash table except | |
1101 that a key-value pair will be removed only if the value and the key remain | |
1102 unmarked outside of weak hash tables. The pair will remain in the | |
1103 hash table if the value or key are pointed to by something other than a weak | |
1104 hash table, even if the other is not. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4585
diff
changeset
|
1105 |
4777
c69aeb86b2a3
Serialise non-default hash table rehash thresholds correctly; use this.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4693
diff
changeset
|
1106 arguments: (&key TEST SIZE REHASH-SIZE REHASH-THRESHOLD WEAKNESS) |
428 | 1107 */ |
1108 (int nargs, Lisp_Object *args)) | |
1109 { | |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
1110 #ifndef NEED_TO_HANDLE_21_4_CODE |
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
1111 PARSE_KEYWORDS (Fmake_hash_table, nargs, args, 5, |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1112 (test, size, rehash_size, rehash_threshold, weakness), |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
1113 NULL); |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1114 #else |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
1115 PARSE_KEYWORDS (Fmake_hash_table, nargs, args, 6, |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1116 (test, size, rehash_size, rehash_threshold, weakness, |
5277
d804e621add0
Simplify the API of PARSE_KEYWORDS for callers.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5232
diff
changeset
|
1117 type), (type = Qunbound, weakness = Qunbound)); |
428 | 1118 |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1119 if (EQ (weakness, Qunbound)) |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1120 { |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1121 if (EQ (weakness, Qunbound) && !EQ (type, Qunbound)) |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1122 { |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1123 weakness = type; |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1124 } |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1125 else |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1126 { |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1127 weakness = Qnil; |
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1128 } |
428 | 1129 } |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
1130 #endif |
428 | 1131 |
1132 #define VALIDATE_VAR(var) \ | |
1133 if (!NILP (var)) hash_table_##var##_validate (Q##var, var, ERROR_ME); | |
1134 | |
1135 VALIDATE_VAR (test); | |
1136 VALIDATE_VAR (size); | |
1137 VALIDATE_VAR (rehash_size); | |
1138 VALIDATE_VAR (rehash_threshold); | |
1139 VALIDATE_VAR (weakness); | |
1140 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1141 return make_general_lisp_hash_table |
428 | 1142 (decode_hash_table_test (test), |
1143 decode_hash_table_size (size), | |
1144 decode_hash_table_rehash_size (rehash_size), | |
1145 decode_hash_table_rehash_threshold (rehash_threshold), | |
1146 decode_hash_table_weakness (weakness)); | |
1147 } | |
1148 | |
1149 DEFUN ("copy-hash-table", Fcopy_hash_table, 1, 1, 0, /* | |
1150 Return a new hash table containing the same keys and values as HASH-TABLE. | |
1151 The keys and values will not themselves be copied. | |
1152 */ | |
1153 (hash_table)) | |
1154 { | |
442 | 1155 const Lisp_Hash_Table *ht_old = xhash_table (hash_table); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1156 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (hash_table); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
1157 Lisp_Hash_Table *ht = XHASH_TABLE (obj); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1158 copy_lisp_object (obj, hash_table); |
428 | 1159 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1160 /* We leave room for one never-occupied sentinel htentry at the end. */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1161 ht->hentries = allocate_hash_table_entries (ht_old->size + 1); |
1204 | 1162 memcpy (ht->hentries, ht_old->hentries, (ht_old->size + 1) * sizeof (htentry)); |
428 | 1163 |
1164 if (! EQ (ht->next_weak, Qunbound)) | |
1165 { | |
1166 ht->next_weak = Vall_weak_hash_tables; | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
1167 Vall_weak_hash_tables = obj; |
428 | 1168 } |
1169 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
1170 return obj; |
428 | 1171 } |
1172 | |
1173 static void | |
665 | 1174 resize_hash_table (Lisp_Hash_Table *ht, Elemcount new_size) |
428 | 1175 { |
1204 | 1176 htentry *old_entries, *new_entries, *sentinel, *e; |
665 | 1177 Elemcount old_size; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1178 Hash_Table_Test *http = XHASH_TABLE_TEST (ht->test); |
428 | 1179 |
1180 old_size = ht->size; | |
1181 ht->size = new_size; | |
1182 | |
1183 old_entries = ht->hentries; | |
1184 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1185 /* We leave room for one never-occupied sentinel htentry at the end. */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1186 ht->hentries = allocate_hash_table_entries (new_size + 1); |
428 | 1187 new_entries = ht->hentries; |
1188 | |
1189 compute_hash_table_derived_values (ht); | |
1190 | |
440 | 1191 for (e = old_entries, sentinel = e + old_size; e < sentinel; e++) |
1204 | 1192 if (!HTENTRY_CLEAR_P (e)) |
428 | 1193 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1194 htentry *probe = new_entries + HASHCODE (e->key, ht, http); |
428 | 1195 LINEAR_PROBING_LOOP (probe, new_entries, new_size) |
1196 ; | |
1197 *probe = *e; | |
1198 } | |
1199 | |
4117 | 1200 #ifndef NEW_GC |
489 | 1201 free_hentries (old_entries, old_size); |
4117 | 1202 #endif /* not NEW_GC */ |
428 | 1203 } |
1204 | |
440 | 1205 /* After a hash table has been saved to disk and later restored by the |
1206 portable dumper, it contains the same objects, but their addresses | |
665 | 1207 and thus their HASHCODEs have changed. */ |
428 | 1208 void |
440 | 1209 pdump_reorganize_hash_table (Lisp_Object hash_table) |
428 | 1210 { |
442 | 1211 const Lisp_Hash_Table *ht = xhash_table (hash_table); |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1212 /* We leave room for one never-occupied sentinel htentry at the end. */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1213 htentry *new_entries = allocate_hash_table_entries (ht->size + 1); |
1204 | 1214 htentry *e, *sentinel; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1215 Hash_Table_Test *http = XHASH_TABLE_TEST (ht->test); |
440 | 1216 |
1217 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++) | |
1204 | 1218 if (!HTENTRY_CLEAR_P (e)) |
440 | 1219 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1220 htentry *probe = new_entries + HASHCODE (e->key, ht, http); |
440 | 1221 LINEAR_PROBING_LOOP (probe, new_entries, ht->size) |
1222 ; | |
1223 *probe = *e; | |
1224 } | |
1225 | |
1204 | 1226 memcpy (ht->hentries, new_entries, ht->size * sizeof (htentry)); |
440 | 1227 |
4117 | 1228 #ifndef NEW_GC |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
1229 xfree (new_entries); |
3092 | 1230 #endif /* not NEW_GC */ |
428 | 1231 } |
1232 | |
1233 static void | |
1234 enlarge_hash_table (Lisp_Hash_Table *ht) | |
1235 { | |
665 | 1236 Elemcount new_size = |
1237 hash_table_size ((Elemcount) ((double) ht->size * ht->rehash_size)); | |
428 | 1238 resize_hash_table (ht, new_size); |
1239 } | |
1240 | |
4072 | 1241 htentry * |
1204 | 1242 find_htentry (Lisp_Object key, const Lisp_Hash_Table *ht) |
428 | 1243 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1244 Lisp_Object test = ht->test; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1245 Hash_Table_Test *http = XHASH_TABLE_TEST (test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1246 |
1204 | 1247 htentry *entries = ht->hentries; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1248 htentry *probe = entries + HASHCODE (key, ht, http); |
428 | 1249 |
1250 LINEAR_PROBING_LOOP (probe, entries, ht->size) | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1251 if (KEYS_EQUAL_P (probe->key, key, test, http)) |
428 | 1252 break; |
1253 | |
1254 return probe; | |
1255 } | |
1256 | |
2421 | 1257 /* A version of Fputhash() that increments the value by the specified |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1258 amount and dispenses with all error checks. Assumes that tables does |
2421 | 1259 comparison using EQ. Used by the profiling routines to avoid |
1260 overhead -- profiling overhead was being recorded at up to 15% of the | |
1261 total time. */ | |
1262 | |
1263 void | |
1264 inchash_eq (Lisp_Object key, Lisp_Object table, EMACS_INT offset) | |
1265 { | |
1266 Lisp_Hash_Table *ht = XHASH_TABLE (table); | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1267 Hash_Table_Test *http = XHASH_TABLE_TEST (ht->test); |
2421 | 1268 htentry *entries = ht->hentries; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1269 htentry *probe = entries + HASHCODE (key, ht, http); |
2421 | 1270 |
1271 LINEAR_PROBING_LOOP (probe, entries, ht->size) | |
1272 if (EQ (probe->key, key)) | |
1273 break; | |
1274 | |
1275 if (!HTENTRY_CLEAR_P (probe)) | |
1276 probe->value = make_int (XINT (probe->value) + offset); | |
1277 else | |
1278 { | |
1279 probe->key = key; | |
1280 probe->value = make_int (offset); | |
1281 | |
1282 if (++ht->count >= ht->rehash_count) | |
1283 enlarge_hash_table (ht); | |
1284 } | |
1285 } | |
1286 | |
428 | 1287 DEFUN ("gethash", Fgethash, 2, 3, 0, /* |
1288 Find hash value for KEY in HASH-TABLE. | |
1289 If there is no corresponding value, return DEFAULT (which defaults to nil). | |
1290 */ | |
1291 (key, hash_table, default_)) | |
1292 { | |
442 | 1293 const Lisp_Hash_Table *ht = xhash_table (hash_table); |
1204 | 1294 htentry *e = find_htentry (key, ht); |
428 | 1295 |
1204 | 1296 return HTENTRY_CLEAR_P (e) ? default_ : e->value; |
428 | 1297 } |
1298 | |
1299 DEFUN ("puthash", Fputhash, 3, 3, 0, /* | |
4410
aae1994dfeec
Document return values for #'puthash, #'clrhash.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4398
diff
changeset
|
1300 Hash KEY to VALUE in HASH-TABLE, and return VALUE. |
428 | 1301 */ |
1302 (key, value, hash_table)) | |
1303 { | |
1304 Lisp_Hash_Table *ht = xhash_table (hash_table); | |
1204 | 1305 htentry *e = find_htentry (key, ht); |
428 | 1306 |
1204 | 1307 if (!HTENTRY_CLEAR_P (e)) |
428 | 1308 return e->value = value; |
1309 | |
1310 e->key = key; | |
1311 e->value = value; | |
1312 | |
1313 if (++ht->count >= ht->rehash_count) | |
1314 enlarge_hash_table (ht); | |
1315 | |
1316 return value; | |
1317 } | |
1318 | |
1204 | 1319 /* Remove htentry pointed at by PROBE. |
428 | 1320 Subsequent entries are removed and reinserted. |
1321 We don't use tombstones - too wasteful. */ | |
1322 static void | |
1204 | 1323 remhash_1 (Lisp_Hash_Table *ht, htentry *entries, htentry *probe) |
428 | 1324 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1325 Hash_Table_Test *http = XHASH_TABLE_TEST (ht->test); |
665 | 1326 Elemcount size = ht->size; |
1204 | 1327 CLEAR_HTENTRY (probe); |
428 | 1328 probe++; |
1329 ht->count--; | |
1330 | |
1331 LINEAR_PROBING_LOOP (probe, entries, size) | |
1332 { | |
1333 Lisp_Object key = probe->key; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1334 htentry *probe2 = entries + HASHCODE (key, ht, http); |
428 | 1335 LINEAR_PROBING_LOOP (probe2, entries, size) |
1336 if (EQ (probe2->key, key)) | |
1204 | 1337 /* htentry at probe doesn't need to move. */ |
428 | 1338 goto continue_outer_loop; |
1204 | 1339 /* Move htentry from probe to new home at probe2. */ |
428 | 1340 *probe2 = *probe; |
1204 | 1341 CLEAR_HTENTRY (probe); |
428 | 1342 continue_outer_loop: continue; |
1343 } | |
1344 } | |
1345 | |
1346 DEFUN ("remhash", Fremhash, 2, 2, 0, /* | |
1347 Remove the entry for KEY from HASH-TABLE. | |
1348 Do nothing if there is no entry for KEY in HASH-TABLE. | |
617 | 1349 Return non-nil if an entry was removed. |
428 | 1350 */ |
1351 (key, hash_table)) | |
1352 { | |
1353 Lisp_Hash_Table *ht = xhash_table (hash_table); | |
1204 | 1354 htentry *e = find_htentry (key, ht); |
428 | 1355 |
1204 | 1356 if (HTENTRY_CLEAR_P (e)) |
428 | 1357 return Qnil; |
1358 | |
1359 remhash_1 (ht, ht->hentries, e); | |
1360 return Qt; | |
1361 } | |
1362 | |
1363 DEFUN ("clrhash", Fclrhash, 1, 1, 0, /* | |
1364 Remove all entries from HASH-TABLE, leaving it empty. | |
4410
aae1994dfeec
Document return values for #'puthash, #'clrhash.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4398
diff
changeset
|
1365 Return HASH-TABLE. |
428 | 1366 */ |
1367 (hash_table)) | |
1368 { | |
1369 Lisp_Hash_Table *ht = xhash_table (hash_table); | |
1204 | 1370 htentry *e, *sentinel; |
428 | 1371 |
1372 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++) | |
1204 | 1373 CLEAR_HTENTRY (e); |
428 | 1374 ht->count = 0; |
1375 | |
1376 return hash_table; | |
1377 } | |
1378 | |
1379 /************************************************************************/ | |
1380 /* Accessor Functions */ | |
1381 /************************************************************************/ | |
1382 | |
1383 DEFUN ("hash-table-count", Fhash_table_count, 1, 1, 0, /* | |
1384 Return the number of entries in HASH-TABLE. | |
1385 */ | |
1386 (hash_table)) | |
1387 { | |
1388 return make_int (xhash_table (hash_table)->count); | |
1389 } | |
1390 | |
1391 DEFUN ("hash-table-test", Fhash_table_test, 1, 1, 0, /* | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1392 Return HASH-TABLE's test. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1393 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1394 This can be one of `eq', `eql', `equal', `equalp', or some symbol supplied |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1395 as the NAME argument to `define-hash-table-test', which see. |
428 | 1396 */ |
1397 (hash_table)) | |
1398 { | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1399 CHECK_HASH_TABLE (hash_table); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1400 return XHASH_TABLE_TEST (XHASH_TABLE (hash_table)->test)->name; |
428 | 1401 } |
1402 | |
1403 DEFUN ("hash-table-size", Fhash_table_size, 1, 1, 0, /* | |
1404 Return the size of HASH-TABLE. | |
1405 This is the current number of slots in HASH-TABLE, whether occupied or not. | |
1406 */ | |
1407 (hash_table)) | |
1408 { | |
1409 return make_int (xhash_table (hash_table)->size); | |
1410 } | |
1411 | |
1412 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size, 1, 1, 0, /* | |
1413 Return the current rehash size of HASH-TABLE. | |
1414 This is a float greater than 1.0; the factor by which HASH-TABLE | |
1415 is enlarged when the rehash threshold is exceeded. | |
1416 */ | |
1417 (hash_table)) | |
1418 { | |
1419 return make_float (xhash_table (hash_table)->rehash_size); | |
1420 } | |
1421 | |
1422 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold, 1, 1, 0, /* | |
1423 Return the current rehash threshold of HASH-TABLE. | |
1424 This is a float between 0.0 and 1.0; the maximum `load factor' of HASH-TABLE, | |
1425 beyond which the HASH-TABLE is enlarged by rehashing. | |
1426 */ | |
1427 (hash_table)) | |
1428 { | |
438 | 1429 return make_float (xhash_table (hash_table)->rehash_threshold); |
428 | 1430 } |
1431 | |
1432 DEFUN ("hash-table-weakness", Fhash_table_weakness, 1, 1, 0, /* | |
1433 Return the weakness of HASH-TABLE. | |
442 | 1434 This can be one of `nil', `key-and-value', `key-or-value', `key' or `value'. |
428 | 1435 */ |
1436 (hash_table)) | |
1437 { | |
1438 switch (xhash_table (hash_table)->weakness) | |
1439 { | |
442 | 1440 case HASH_TABLE_WEAK: return Qkey_and_value; |
1441 case HASH_TABLE_KEY_WEAK: return Qkey; | |
1442 case HASH_TABLE_KEY_VALUE_WEAK: return Qkey_or_value; | |
1443 case HASH_TABLE_VALUE_WEAK: return Qvalue; | |
1444 default: return Qnil; | |
428 | 1445 } |
1446 } | |
1447 | |
1448 /* obsolete as of 19990901 in xemacs-21.2 */ | |
1449 DEFUN ("hash-table-type", Fhash_table_type, 1, 1, 0, /* | |
1450 Return the type of HASH-TABLE. | |
1451 This can be one of `non-weak', `weak', `key-weak' or `value-weak'. | |
1452 */ | |
1453 (hash_table)) | |
1454 { | |
1455 switch (xhash_table (hash_table)->weakness) | |
1456 { | |
442 | 1457 case HASH_TABLE_WEAK: return Qweak; |
1458 case HASH_TABLE_KEY_WEAK: return Qkey_weak; | |
1459 case HASH_TABLE_KEY_VALUE_WEAK: return Qkey_or_value_weak; | |
1460 case HASH_TABLE_VALUE_WEAK: return Qvalue_weak; | |
1461 default: return Qnon_weak; | |
428 | 1462 } |
1463 } | |
1464 | |
1465 /************************************************************************/ | |
1466 /* Mapping Functions */ | |
1467 /************************************************************************/ | |
489 | 1468 |
1469 /* We need to be careful when mapping over hash tables because the | |
1470 hash table might be modified during the mapping operation: | |
1471 - by the mapping function | |
1472 - by gc (if the hash table is weak) | |
1473 | |
1474 So we make a copy of the hentries at the beginning of the mapping | |
497 | 1475 operation, and iterate over the copy. Naturally, this is |
1476 expensive, but not as expensive as you might think, because no | |
1477 actual memory has to be collected by our notoriously inefficient | |
1478 GC; we use an unwind-protect instead to free the memory directly. | |
1479 | |
1480 We could avoid the copying by having the hash table modifiers | |
1481 puthash and remhash check for currently active mapping functions. | |
1482 Disadvantages: it's hard to get right, and IMO hash mapping | |
1483 functions are basically rare, and no extra space in the hash table | |
1484 object and no extra cpu in puthash or remhash should be wasted to | |
1485 make maphash 3% faster. From a design point of view, the basic | |
1486 functions gethash, puthash and remhash should be implementable | |
1487 without having to think about maphash. | |
1488 | |
1489 Note: We don't (yet) have Common Lisp's with-hash-table-iterator. | |
1490 If you implement this naively, you cannot have more than one | |
1491 concurrently active iterator over the same hash table. The `each' | |
1492 function in perl has this limitation. | |
1493 | |
1494 Note: We GCPRO memory on the heap, not on the stack. There is no | |
1495 obvious reason why this is bad, but as of this writing this is the | |
1496 only known occurrence of this technique in the code. | |
504 | 1497 |
1498 -- Martin | |
1499 */ | |
1500 | |
1501 /* Ben disagrees with the "copying hentries" design, and says: | |
1502 | |
1503 Another solution is the same as I've already proposed -- when | |
1504 mapping, mark the table as "change-unsafe", and in this case, use a | |
1505 secondary table to maintain changes. this could be basically a | |
1506 standard hash table, but with entries only for added or deleted | |
1507 entries in the primary table, and a marker like Qunbound to | |
1508 indicate a deleted entry. puthash, gethash and remhash need a | |
1509 single extra check for this secondary table -- totally | |
1510 insignificant speedwise. if you really cared about making | |
1511 recursive maphashes completely correct, you'd have to do a bit of | |
1512 extra work here -- when maphashing, if the secondary table exists, | |
1513 make a copy of it, and use the copy in conjunction with the primary | |
1514 table when mapping. the advantages of this are | |
1515 | |
1516 [a] easy to demonstrate correct, even with weak hashtables. | |
1517 | |
1518 [b] no extra overhead in the general maphash case -- only when you | |
1519 modify the table while maphashing, and even then the overhead is | |
1520 very small. | |
497 | 1521 */ |
1522 | |
489 | 1523 static Lisp_Object |
1524 maphash_unwind (Lisp_Object unwind_obj) | |
1525 { | |
1526 void *ptr = (void *) get_opaque_ptr (unwind_obj); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
1527 xfree (ptr); |
489 | 1528 free_opaque_ptr (unwind_obj); |
1529 return Qnil; | |
1530 } | |
1531 | |
1532 /* Return a malloced array of alternating key/value pairs from HT. */ | |
1533 static Lisp_Object * | |
1534 copy_compress_hentries (const Lisp_Hash_Table *ht) | |
1535 { | |
1536 Lisp_Object * const objs = | |
1537 /* If the hash table is empty, ht->count could be 0. */ | |
1538 xnew_array (Lisp_Object, 2 * (ht->count > 0 ? ht->count : 1)); | |
1204 | 1539 const htentry *e, *sentinel; |
489 | 1540 Lisp_Object *pobj; |
1541 | |
1542 for (e = ht->hentries, sentinel = e + ht->size, pobj = objs; e < sentinel; e++) | |
1204 | 1543 if (!HTENTRY_CLEAR_P (e)) |
489 | 1544 { |
1545 *(pobj++) = e->key; | |
1546 *(pobj++) = e->value; | |
1547 } | |
1548 | |
1549 type_checking_assert (pobj == objs + 2 * ht->count); | |
1550 | |
1551 return objs; | |
1552 } | |
1553 | |
428 | 1554 DEFUN ("maphash", Fmaphash, 2, 2, 0, /* |
1555 Map FUNCTION over entries in HASH-TABLE, calling it with two args, | |
1556 each key and value in HASH-TABLE. | |
1557 | |
489 | 1558 FUNCTION must not modify HASH-TABLE, with the one exception that FUNCTION |
428 | 1559 may remhash or puthash the entry currently being processed by FUNCTION. |
1560 */ | |
1561 (function, hash_table)) | |
1562 { | |
489 | 1563 const Lisp_Hash_Table * const ht = xhash_table (hash_table); |
1564 Lisp_Object * const objs = copy_compress_hentries (ht); | |
1565 Lisp_Object args[3]; | |
1566 const Lisp_Object *pobj, *end; | |
1567 int speccount = specpdl_depth (); | |
1568 struct gcpro gcpro1; | |
1569 | |
1570 record_unwind_protect (maphash_unwind, make_opaque_ptr ((void *)objs)); | |
1571 GCPRO1 (objs[0]); | |
1572 gcpro1.nvars = 2 * ht->count; | |
428 | 1573 |
489 | 1574 args[0] = function; |
1575 | |
1576 for (pobj = objs, end = pobj + 2 * ht->count; pobj < end; pobj += 2) | |
1577 { | |
1578 args[1] = pobj[0]; | |
1579 args[2] = pobj[1]; | |
1580 Ffuncall (countof (args), args); | |
1581 } | |
1582 | |
771 | 1583 unbind_to (speccount); |
489 | 1584 UNGCPRO; |
428 | 1585 |
1586 return Qnil; | |
1587 } | |
1588 | |
489 | 1589 /* Map *C* function FUNCTION over the elements of a non-weak lisp hash table. |
1590 FUNCTION must not modify HASH-TABLE, with the one exception that FUNCTION | |
1591 may puthash the entry currently being processed by FUNCTION. | |
1592 Mapping terminates if FUNCTION returns something other than 0. */ | |
428 | 1593 void |
489 | 1594 elisp_maphash_unsafe (maphash_function_t function, |
428 | 1595 Lisp_Object hash_table, void *extra_arg) |
1596 { | |
442 | 1597 const Lisp_Hash_Table *ht = XHASH_TABLE (hash_table); |
1204 | 1598 const htentry *e, *sentinel; |
428 | 1599 |
1600 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++) | |
1204 | 1601 if (!HTENTRY_CLEAR_P (e)) |
489 | 1602 if (function (e->key, e->value, extra_arg)) |
1603 return; | |
428 | 1604 } |
1605 | |
489 | 1606 /* Map *C* function FUNCTION over the elements of a lisp hash table. |
1607 It is safe for FUNCTION to modify HASH-TABLE. | |
1608 Mapping terminates if FUNCTION returns something other than 0. */ | |
1609 void | |
1610 elisp_maphash (maphash_function_t function, | |
1611 Lisp_Object hash_table, void *extra_arg) | |
1612 { | |
1613 const Lisp_Hash_Table * const ht = xhash_table (hash_table); | |
1614 Lisp_Object * const objs = copy_compress_hentries (ht); | |
1615 const Lisp_Object *pobj, *end; | |
1616 int speccount = specpdl_depth (); | |
1617 struct gcpro gcpro1; | |
1618 | |
1619 record_unwind_protect (maphash_unwind, make_opaque_ptr ((void *)objs)); | |
1620 GCPRO1 (objs[0]); | |
1621 gcpro1.nvars = 2 * ht->count; | |
1622 | |
1623 for (pobj = objs, end = pobj + 2 * ht->count; pobj < end; pobj += 2) | |
1624 if (function (pobj[0], pobj[1], extra_arg)) | |
1625 break; | |
1626 | |
771 | 1627 unbind_to (speccount); |
489 | 1628 UNGCPRO; |
1629 } | |
1630 | |
1631 /* Remove all elements of a lisp hash table satisfying *C* predicate PREDICATE. | |
1632 PREDICATE must not modify HASH-TABLE. */ | |
428 | 1633 void |
1634 elisp_map_remhash (maphash_function_t predicate, | |
1635 Lisp_Object hash_table, void *extra_arg) | |
1636 { | |
489 | 1637 const Lisp_Hash_Table * const ht = xhash_table (hash_table); |
1638 Lisp_Object * const objs = copy_compress_hentries (ht); | |
1639 const Lisp_Object *pobj, *end; | |
1640 int speccount = specpdl_depth (); | |
1641 struct gcpro gcpro1; | |
428 | 1642 |
489 | 1643 record_unwind_protect (maphash_unwind, make_opaque_ptr ((void *)objs)); |
1644 GCPRO1 (objs[0]); | |
1645 gcpro1.nvars = 2 * ht->count; | |
1646 | |
1647 for (pobj = objs, end = pobj + 2 * ht->count; pobj < end; pobj += 2) | |
1648 if (predicate (pobj[0], pobj[1], extra_arg)) | |
1649 Fremhash (pobj[0], hash_table); | |
1650 | |
771 | 1651 unbind_to (speccount); |
489 | 1652 UNGCPRO; |
428 | 1653 } |
1654 | |
1655 | |
1656 /************************************************************************/ | |
1657 /* garbage collecting weak hash tables */ | |
1658 /************************************************************************/ | |
1598 | 1659 #ifdef USE_KKCC |
2645 | 1660 #define MARK_OBJ(obj) do { \ |
1661 Lisp_Object mo_obj = (obj); \ | |
1662 if (!marked_p (mo_obj)) \ | |
1663 { \ | |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5158
diff
changeset
|
1664 kkcc_gc_stack_push_lisp_object_0 (mo_obj); \ |
2645 | 1665 did_mark = 1; \ |
1666 } \ | |
1598 | 1667 } while (0) |
1668 | |
1669 #else /* NO USE_KKCC */ | |
1670 | |
442 | 1671 #define MARK_OBJ(obj) do { \ |
1672 Lisp_Object mo_obj = (obj); \ | |
1673 if (!marked_p (mo_obj)) \ | |
1674 { \ | |
1675 mark_object (mo_obj); \ | |
1676 did_mark = 1; \ | |
1677 } \ | |
1678 } while (0) | |
1598 | 1679 #endif /*NO USE_KKCC */ |
442 | 1680 |
428 | 1681 |
1682 /* Complete the marking for semi-weak hash tables. */ | |
1683 int | |
1684 finish_marking_weak_hash_tables (void) | |
1685 { | |
1686 Lisp_Object hash_table; | |
1687 int did_mark = 0; | |
1688 | |
1689 for (hash_table = Vall_weak_hash_tables; | |
1690 !NILP (hash_table); | |
1691 hash_table = XHASH_TABLE (hash_table)->next_weak) | |
1692 { | |
442 | 1693 const Lisp_Hash_Table *ht = XHASH_TABLE (hash_table); |
1204 | 1694 const htentry *e = ht->hentries; |
1695 const htentry *sentinel = e + ht->size; | |
428 | 1696 |
1697 if (! marked_p (hash_table)) | |
1698 /* The hash table is probably garbage. Ignore it. */ | |
1699 continue; | |
1700 | |
1701 /* Now, scan over all the pairs. For all pairs that are | |
1702 half-marked, we may need to mark the other half if we're | |
1703 keeping this pair. */ | |
1704 switch (ht->weakness) | |
1705 { | |
1706 case HASH_TABLE_KEY_WEAK: | |
1707 for (; e < sentinel; e++) | |
1204 | 1708 if (!HTENTRY_CLEAR_P (e)) |
428 | 1709 if (marked_p (e->key)) |
1710 MARK_OBJ (e->value); | |
1711 break; | |
1712 | |
1713 case HASH_TABLE_VALUE_WEAK: | |
1714 for (; e < sentinel; e++) | |
1204 | 1715 if (!HTENTRY_CLEAR_P (e)) |
428 | 1716 if (marked_p (e->value)) |
1717 MARK_OBJ (e->key); | |
1718 break; | |
1719 | |
442 | 1720 case HASH_TABLE_KEY_VALUE_WEAK: |
1721 for (; e < sentinel; e++) | |
1204 | 1722 if (!HTENTRY_CLEAR_P (e)) |
442 | 1723 { |
1724 if (marked_p (e->value)) | |
1725 MARK_OBJ (e->key); | |
1726 else if (marked_p (e->key)) | |
1727 MARK_OBJ (e->value); | |
1728 } | |
1729 break; | |
1730 | |
428 | 1731 case HASH_TABLE_KEY_CAR_WEAK: |
1732 for (; e < sentinel; e++) | |
1204 | 1733 if (!HTENTRY_CLEAR_P (e)) |
428 | 1734 if (!CONSP (e->key) || marked_p (XCAR (e->key))) |
1735 { | |
1736 MARK_OBJ (e->key); | |
1737 MARK_OBJ (e->value); | |
1738 } | |
1739 break; | |
1740 | |
450 | 1741 /* We seem to be sprouting new weakness types at an alarming |
1742 rate. At least this is not externally visible - and in | |
1743 fact all of these KEY_CAR_* types are only used by the | |
1744 glyph code. */ | |
1745 case HASH_TABLE_KEY_CAR_VALUE_WEAK: | |
1746 for (; e < sentinel; e++) | |
1204 | 1747 if (!HTENTRY_CLEAR_P (e)) |
450 | 1748 { |
1749 if (!CONSP (e->key) || marked_p (XCAR (e->key))) | |
1750 { | |
1751 MARK_OBJ (e->key); | |
1752 MARK_OBJ (e->value); | |
1753 } | |
1754 else if (marked_p (e->value)) | |
1755 MARK_OBJ (e->key); | |
1756 } | |
1757 break; | |
1758 | |
428 | 1759 case HASH_TABLE_VALUE_CAR_WEAK: |
1760 for (; e < sentinel; e++) | |
1204 | 1761 if (!HTENTRY_CLEAR_P (e)) |
428 | 1762 if (!CONSP (e->value) || marked_p (XCAR (e->value))) |
1763 { | |
1764 MARK_OBJ (e->key); | |
1765 MARK_OBJ (e->value); | |
1766 } | |
1767 break; | |
1768 | |
1769 default: | |
1770 break; | |
1771 } | |
1772 } | |
1773 | |
1774 return did_mark; | |
1775 } | |
1776 | |
1777 void | |
1778 prune_weak_hash_tables (void) | |
1779 { | |
1780 Lisp_Object hash_table, prev = Qnil; | |
1781 for (hash_table = Vall_weak_hash_tables; | |
1782 !NILP (hash_table); | |
1783 hash_table = XHASH_TABLE (hash_table)->next_weak) | |
1784 { | |
1785 if (! marked_p (hash_table)) | |
1786 { | |
1787 /* This hash table itself is garbage. Remove it from the list. */ | |
1788 if (NILP (prev)) | |
1789 Vall_weak_hash_tables = XHASH_TABLE (hash_table)->next_weak; | |
1790 else | |
1791 XHASH_TABLE (prev)->next_weak = XHASH_TABLE (hash_table)->next_weak; | |
1792 } | |
1793 else | |
1794 { | |
1795 /* Now, scan over all the pairs. Remove all of the pairs | |
1796 in which the key or value, or both, is unmarked | |
1797 (depending on the weakness of the hash table). */ | |
1798 Lisp_Hash_Table *ht = XHASH_TABLE (hash_table); | |
1204 | 1799 htentry *entries = ht->hentries; |
1800 htentry *sentinel = entries + ht->size; | |
1801 htentry *e; | |
428 | 1802 |
1803 for (e = entries; e < sentinel; e++) | |
1204 | 1804 if (!HTENTRY_CLEAR_P (e)) |
428 | 1805 { |
1806 again: | |
1807 if (!marked_p (e->key) || !marked_p (e->value)) | |
1808 { | |
1809 remhash_1 (ht, entries, e); | |
1204 | 1810 if (!HTENTRY_CLEAR_P (e)) |
428 | 1811 goto again; |
1812 } | |
1813 } | |
1814 | |
1815 prev = hash_table; | |
1816 } | |
1817 } | |
1818 } | |
1819 | |
1820 /* Return a hash value for an array of Lisp_Objects of size SIZE. */ | |
1821 | |
665 | 1822 Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1823 internal_array_hash (Lisp_Object *arr, int size, int depth, Boolint equalp) |
428 | 1824 { |
1825 int i; | |
665 | 1826 Hashcode hash = 0; |
442 | 1827 depth++; |
428 | 1828 |
1829 if (size <= 5) | |
1830 { | |
1831 for (i = 0; i < size; i++) | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1832 hash = HASH2 (hash, internal_hash (arr[i], depth, equalp)); |
428 | 1833 return hash; |
1834 } | |
1835 | |
1836 /* just pick five elements scattered throughout the array. | |
1837 A slightly better approach would be to offset by some | |
1838 noise factor from the points chosen below. */ | |
1839 for (i = 0; i < 5; i++) | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1840 hash = HASH2 (hash, internal_hash (arr[i*size/5], depth, equalp)); |
428 | 1841 |
1842 return hash; | |
1843 } | |
1844 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1845 /* This needs to be algorithmically the same as |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1846 internal_array_hash(). Unfortunately, for strings with non-ASCII content, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1847 it has to be O(2N), I don't see a reasonable alternative to hashing |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1848 sequence relying on their length. It is O(1) for pure ASCII strings, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1849 though. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1850 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1851 static Hashcode |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1852 string_equalp_hash (Lisp_Object string) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1853 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1854 Bytecount len = XSTRING_LENGTH (string), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1855 ascii_begin = (Bytecount) XSTRING_ASCII_BEGIN (string); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1856 const Ibyte *ptr = XSTRING_DATA (string), *pend = ptr + len; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1857 Charcount clen; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1858 Hashcode hash = 0; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1859 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1860 if (len == ascii_begin) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1861 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1862 clen = len; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1863 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1864 else |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1865 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1866 clen = string_char_length (string); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1867 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1868 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1869 if (clen <= 5) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1870 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1871 while (ptr < pend) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1872 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1873 hash = HASH2 (hash, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1874 LISP_HASH (make_char (CANONCASE (NULL, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1875 itext_ichar (ptr))))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1876 INC_IBYTEPTR (ptr); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1877 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1878 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1879 else |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1880 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1881 int ii; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1882 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1883 if (clen == len) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1884 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1885 for (ii = 0; ii < 5; ii++) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1886 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1887 hash = HASH2 (hash, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1888 LISP_HASH (make_char |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1889 (CANONCASE (NULL, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1890 ptr[ii * clen / 5])))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1891 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1892 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1893 else |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1894 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1895 Charcount this_char = 0, last_char = 0; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1896 for (ii = 0; ii < 5; ii++) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1897 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1898 this_char = ii * clen / 5; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1899 ptr = itext_n_addr (ptr, this_char - last_char); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1900 last_char = this_char; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1901 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1902 hash = HASH2 (hash, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1903 LISP_HASH (make_char |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1904 (CANONCASE (NULL, itext_ichar (ptr))))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1905 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1906 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1907 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1908 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1909 return HASH2 (clen, hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1910 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1911 |
428 | 1912 /* Return a hash value for a Lisp_Object. This is for use when hashing |
1913 objects with the comparison being `equal' (for `eq', you can just | |
1914 use the Lisp_Object itself as the hash value). You need to make a | |
1915 tradeoff between the speed of the hash function and how good the | |
1916 hashing is. In particular, the hash function needs to be FAST, | |
1917 so you can't just traipse down the whole tree hashing everything | |
1918 together. Most of the time, objects will differ in the first | |
1919 few elements you hash. Thus, we only go to a short depth (5) | |
1920 and only hash at most 5 elements out of a vector. Theoretically | |
1921 we could still take 5^5 time (a big big number) to compute a | |
1922 hash, but practically this won't ever happen. */ | |
1923 | |
665 | 1924 Hashcode |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1925 internal_hash (Lisp_Object obj, int depth, Boolint equalp) |
428 | 1926 { |
1927 if (depth > 5) | |
1928 return 0; | |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1929 |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1930 if (CONSP (obj)) |
428 | 1931 { |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1932 Hashcode hash, h; |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1933 int s; |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1934 |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1935 depth += 1; |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1936 |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1937 if (!CONSP (XCDR (obj))) |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1938 { |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1939 /* special case for '(a . b) conses */ |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1940 return HASH2 (internal_hash (XCAR(obj), depth, equalp), |
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1941 internal_hash (XCDR (obj), depth, equalp)); |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1942 } |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1943 |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1944 /* Don't simply tail recurse; we want to hash lists with the |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1945 same contents in distinct orders differently. */ |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1946 hash = internal_hash (XCAR (obj), depth, equalp); |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1947 |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1948 obj = XCDR (obj); |
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1949 for (s = 1; s < 6 && CONSP (obj); obj = XCDR (obj), s++) |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1950 { |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1951 h = internal_hash (XCAR (obj), depth, equalp); |
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1952 hash = HASH3 (hash, h, s); |
4398
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1953 } |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1954 |
479443c0f95a
Have list hashes depend on the order of the contents, as is the case for vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4117
diff
changeset
|
1955 return hash; |
428 | 1956 } |
1957 if (STRINGP (obj)) | |
1958 { | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1959 if (equalp) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1960 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1961 return string_equalp_hash (obj); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1962 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1963 |
428 | 1964 return hash_string (XSTRING_DATA (obj), XSTRING_LENGTH (obj)); |
1965 } | |
1966 if (LRECORDP (obj)) | |
1967 { | |
442 | 1968 const struct lrecord_implementation |
428 | 1969 *imp = XRECORD_LHEADER_IMPLEMENTATION (obj); |
1970 if (imp->hash) | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1971 return imp->hash (obj, depth, equalp); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1972 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1973 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1974 if (equalp) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1975 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1976 if (CHARP (obj)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1977 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1978 /* Characters and numbers of the same numeric value hash |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1979 differently, which is fine, they're not equalp. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1980 return LISP_HASH (make_char (CANONCASE (NULL, XCHAR (obj)))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1981 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1982 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1983 if (INTP (obj)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1984 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1985 return FLOAT_HASHCODE_FROM_DOUBLE ((double) (XINT (obj))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1986 } |
428 | 1987 } |
1988 | |
1989 return LISP_HASH (obj); | |
1990 } | |
1991 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1992 DEFUN ("eq-hash", Feq_hash, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1993 Return a hash value for OBJECT appropriate for use with `eq.' |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1994 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1995 (object)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1996 { |
5193
41ac827cb71b
fix cygwin compile, fix warning and style in elhash.c
Ben Wing <ben@xemacs.org>
parents:
5191
diff
changeset
|
1997 return make_integer ((EMACS_INT) XPNTRVAL (object)); |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1998 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
1999 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2000 DEFUN ("eql-hash", Feql_hash, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2001 Return a hash value for OBJECT appropriate for use with `eql.' |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2002 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2003 (object)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2004 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2005 EMACS_INT hashed = lisp_object_eql_hash (NULL, object); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2006 return make_integer (hashed); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2007 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2008 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2009 DEFUN ("equal-hash", Fequal_hash, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2010 Return a hash value for OBJECT appropriate for use with `equal.' |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2011 \(equal obj1 obj2) implies (= (equal-hash obj1) (equal-hash obj2)). |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2012 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2013 (object)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2014 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2015 EMACS_INT hashed = internal_hash (object, 0, 0); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2016 return make_integer (hashed); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2017 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2018 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2019 DEFUN ("equalp-hash", Fequalp_hash, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2020 Return a hash value for OBJECT appropriate for use with `equalp.' |
428 | 2021 */ |
2022 (object)) | |
2023 { | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2024 EMACS_INT hashed = internal_hash (object, 0, 1); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2025 return make_integer (hashed); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2026 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2027 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2028 static Lisp_Object |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2029 make_hash_table_test (Lisp_Object name, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2030 hash_table_equal_function_t equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2031 hash_table_hash_function_t hash_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2032 Lisp_Object lisp_equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2033 Lisp_Object lisp_hash_function) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2034 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2035 Lisp_Object result = ALLOC_NORMAL_LISP_OBJECT (hash_table_test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2036 Hash_Table_Test *http = XHASH_TABLE_TEST (result); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2037 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2038 http->name = name; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2039 http->equal_function = equal_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2040 http->hash_function = hash_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2041 http->lisp_equal_function = lisp_equal_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2042 http->lisp_hash_function = lisp_hash_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2043 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2044 return result; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2045 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2046 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2047 Lisp_Object |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2048 define_hash_table_test (Lisp_Object name, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2049 hash_table_equal_function_t equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2050 hash_table_hash_function_t hash_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2051 Lisp_Object lisp_equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2052 Lisp_Object lisp_hash_function) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2053 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2054 Lisp_Object result = make_hash_table_test (name, equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2055 hash_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2056 lisp_equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2057 lisp_hash_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2058 XWEAK_LIST_LIST (Vhash_table_test_weak_list) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2059 = Fcons (Fcons (name, result), |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2060 XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2061 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2062 return result; |
428 | 2063 } |
2064 | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2065 DEFUN ("define-hash-table-test", Fdefine_hash_table_test, 3, 3, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2066 Define a new hash table test with name NAME, a symbol. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2067 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2068 In a hash table created with NAME as its test, use EQUAL-FUNCTION to compare |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2069 keys, and HASH-FUNCTION for computing hash codes of keys. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2070 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2071 EQUAL-FUNCTION must be a function taking two arguments and returning non-nil |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2072 if both arguments are the same. HASH-FUNCTION must be a function taking one |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2073 argument and returning an integer that is the hash code of the argument. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2074 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2075 Computation should use the whole value range of the underlying machine long |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2076 type. In XEmacs this will necessitate bignums for values above |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2077 `most-positive-fixnum' but below (1+ (* most-positive-fixnum 2)) and |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2078 analagous values below `most-negative-fixnum'. Relatively poor hashing |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2079 performance is guaranteed in a build without bignums. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2080 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2081 This function returns t if successful, and errors if NAME |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2082 cannot be defined as a hash table test. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2083 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2084 (name, equal_function, hash_function)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2085 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2086 Lisp_Object min, max, lookup; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2087 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2088 CHECK_SYMBOL (name); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2089 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2090 lookup = Fassq (name, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2091 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2092 if (!NILP (lookup)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2093 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2094 invalid_change ("Cannot redefine existing hash table test", name); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2095 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2096 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2097 min = Ffunction_min_args (equal_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2098 max = Ffunction_max_args (equal_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2099 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2100 if (!((XINT (min) <= 2) && (NILP (max) || 2 <= XINT (max)))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2101 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2102 signal_wrong_number_of_arguments_error (equal_function, 2); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2103 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2104 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2105 min = Ffunction_min_args (hash_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2106 max = Ffunction_max_args (hash_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2107 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2108 if (!((XINT (min) <= 1) && (NILP (max) || 1 <= XINT (max)))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2109 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2110 signal_wrong_number_of_arguments_error (hash_function, 1); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2111 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2112 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2113 define_hash_table_test (name, lisp_object_general_equal, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2114 lisp_object_general_hash, equal_function, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2115 hash_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2116 return Qt; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2117 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2118 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2119 DEFUN ("valid-hash-table-test-p", Fvalid_hash_table_test_p, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2120 Return t if OBJECT names a hash table test, nil otherwise. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2121 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2122 A valid hash table test is one of the symbols `eq', `eql', `equal', |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2123 `equalp', or some symbol passed as the NAME argument to |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2124 `define-hash-table-test'. As a special case, `nil' is regarded as |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2125 equivalent to `eql'. |
428 | 2126 */ |
2127 (object)) | |
2128 { | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2129 Lisp_Object lookup; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2130 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2131 if (NILP (object)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2132 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2133 return Qt; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2134 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2135 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2136 lookup = Fassq (object, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2137 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2138 if (!NILP (lookup)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2139 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2140 return Qt; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2141 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2142 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2143 return Qnil; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2144 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2145 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2146 DEFUN ("hash-table-test-list", Fhash_table_test_list, 0, 0, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2147 Return a list of symbols naming valid hash table tests. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2148 These can be passed as the value of the TEST keyword to `make-hash-table'. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2149 This list does not include nil, regarded as equivalent to `eql' by |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2150 `make-hash-table'. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2151 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2152 ()) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2153 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2154 Lisp_Object result = Qnil; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2155 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2156 LIST_LOOP_2 (test, XWEAK_LIST_LIST (Vhash_table_test_weak_list)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2157 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2158 if (!UNBOUNDP (XCAR (test))) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2159 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2160 result = Fcons (XCAR (test), result); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2161 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2162 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2163 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2164 return result; |
428 | 2165 } |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2166 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2167 DEFUN ("hash-table-test-equal-function", |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2168 Fhash_table_test_equal_function, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2169 Return the comparison function used for hash table test TEST. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2170 See `define-hash-table-test' and `make-hash-table'. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2171 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2172 (test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2173 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2174 Lisp_Object lookup; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2175 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2176 if (NILP (test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2177 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2178 test = Qeql; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2179 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2180 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2181 lookup = Fassq (test, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2182 if (NILP (lookup)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2183 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2184 invalid_argument ("Not a defined hash table test", test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2185 } |
428 | 2186 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2187 return XHASH_TABLE_TEST (XCDR (lookup))->lisp_equal_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2188 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2189 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2190 DEFUN ("hash-table-test-hash-function", |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2191 Fhash_table_test_hash_function, 1, 1, 0, /* |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2192 Return the hash function used for hash table test TEST. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2193 See `define-hash-table-test' and `make-hash-table'. |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2194 */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2195 (test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2196 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2197 Lisp_Object lookup; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2198 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2199 if (NILP (test)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2200 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2201 test = Qeql; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2202 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2203 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2204 lookup = Fassq (test, XWEAK_LIST_LIST (Vhash_table_test_weak_list)); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2205 if (NILP (lookup)) |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2206 { |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2207 invalid_argument ("Not a defined hash table test", test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2208 } |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2209 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2210 return XHASH_TABLE_TEST (XCDR (lookup))->lisp_hash_function; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2211 } |
428 | 2212 |
2213 /************************************************************************/ | |
2214 /* initialization */ | |
2215 /************************************************************************/ | |
2216 | |
2217 void | |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2218 hash_table_objects_create (void) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2219 { |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2220 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2221 OBJECT_HAS_METHOD (hash_table, memory_usage); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2222 #endif |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2223 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2224 |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2225 void |
428 | 2226 syms_of_elhash (void) |
2227 { | |
2228 DEFSUBR (Fhash_table_p); | |
2229 DEFSUBR (Fmake_hash_table); | |
2230 DEFSUBR (Fcopy_hash_table); | |
2231 DEFSUBR (Fgethash); | |
2232 DEFSUBR (Fremhash); | |
2233 DEFSUBR (Fputhash); | |
2234 DEFSUBR (Fclrhash); | |
2235 DEFSUBR (Fmaphash); | |
2236 DEFSUBR (Fhash_table_count); | |
2237 DEFSUBR (Fhash_table_test); | |
2238 DEFSUBR (Fhash_table_size); | |
2239 DEFSUBR (Fhash_table_rehash_size); | |
2240 DEFSUBR (Fhash_table_rehash_threshold); | |
2241 DEFSUBR (Fhash_table_weakness); | |
2242 DEFSUBR (Fhash_table_type); /* obsolete */ | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2243 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2244 DEFSUBR (Feq_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2245 DEFSUBR (Feql_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2246 DEFSUBR (Fequal_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2247 Ffset (intern ("sxhash"), intern ("equal-hash")); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2248 DEFSUBR (Fequalp_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2249 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2250 DEFSUBR (Fdefine_hash_table_test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2251 DEFSUBR (Fvalid_hash_table_test_p); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2252 DEFSUBR (Fhash_table_test_list); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2253 DEFSUBR (Fhash_table_test_equal_function); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2254 DEFSUBR (Fhash_table_test_hash_function); |
428 | 2255 |
563 | 2256 DEFSYMBOL_MULTIWORD_PREDICATE (Qhash_tablep); |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2257 |
563 | 2258 DEFSYMBOL (Qhash_table); |
2259 DEFSYMBOL (Qhashtable); | |
5084
6afe991b8135
Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
2260 DEFSYMBOL (Qmake_hash_table); |
563 | 2261 DEFSYMBOL (Qweakness); |
2262 DEFSYMBOL (Qvalue); | |
2263 DEFSYMBOL (Qkey_or_value); | |
2264 DEFSYMBOL (Qkey_and_value); | |
2265 DEFSYMBOL (Qrehash_size); | |
2266 DEFSYMBOL (Qrehash_threshold); | |
428 | 2267 |
563 | 2268 DEFSYMBOL (Qweak); /* obsolete */ |
2269 DEFSYMBOL (Qkey_weak); /* obsolete */ | |
2270 DEFSYMBOL (Qkey_or_value_weak); /* obsolete */ | |
2271 DEFSYMBOL (Qvalue_weak); /* obsolete */ | |
2272 DEFSYMBOL (Qnon_weak); /* obsolete */ | |
428 | 2273 |
4820
e6dec75ded0e
Use keywords, not ordinary symbols, in the structure syntax for hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4779
diff
changeset
|
2274 DEFKEYWORD (Q_data); |
563 | 2275 DEFKEYWORD (Q_test); |
2276 DEFKEYWORD (Q_size); | |
2277 DEFKEYWORD (Q_rehash_size); | |
2278 DEFKEYWORD (Q_rehash_threshold); | |
2279 DEFKEYWORD (Q_weakness); | |
428 | 2280 } |
2281 | |
2282 void | |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2283 vars_of_elhash (void) |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2284 { |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2285 Lisp_Object weak_list_list = XWEAK_LIST_LIST (Vhash_table_test_weak_list); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2286 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2287 /* This var was staticpro'd and initialised in |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2288 init_elhash_once_early, but its Vall_weak_lists isn't sane, since |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2289 that was done before vars_of_data() was called. Create a sane |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2290 weak list object now, set its list appropriately, assert that our |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2291 data haven't been garbage collected. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2292 assert (!NILP (Fassq (Qeq, weak_list_list))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2293 assert (!NILP (Fassq (Qeql, weak_list_list))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2294 assert (!NILP (Fassq (Qequal, weak_list_list))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2295 assert (!NILP (Fassq (Qequalp, weak_list_list))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2296 assert (4 == XINT (Flength (weak_list_list))); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2297 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2298 Vhash_table_test_weak_list = make_weak_list (WEAK_LIST_KEY_ASSOC); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2299 XWEAK_LIST_LIST (Vhash_table_test_weak_list) = weak_list_list; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2300 |
5158
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2301 #ifdef MEMORY_USAGE_STATS |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2302 OBJECT_HAS_PROPERTY |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2303 (hash_table, memusage_stats_list, list1 (intern ("hash-entries"))); |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2304 #endif /* MEMORY_USAGE_STATS */ |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2305 } |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2306 |
9e0b43d3095c
more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2307 void |
771 | 2308 init_elhash_once_early (void) |
428 | 2309 { |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
2310 INIT_LISP_OBJECT (hash_table); |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2311 INIT_LISP_OBJECT (hash_table_test); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2312 |
3092 | 2313 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2314 INIT_LISP_OBJECT (hash_table_entry); |
3092 | 2315 #endif /* NEW_GC */ |
771 | 2316 |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2317 /* init_elhash_once_early() is called very early, we can't have these |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2318 DEFSYMBOLs in syms_of_elhash(), unfortunately. */ |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2319 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2320 DEFSYMBOL (Qeq); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2321 DEFSYMBOL (Qeql); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2322 DEFSYMBOL (Qequal); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2323 DEFSYMBOL (Qequalp); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2324 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2325 DEFSYMBOL (Qeq_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2326 DEFSYMBOL (Qeql_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2327 DEFSYMBOL (Qequal_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2328 DEFSYMBOL (Qequalp_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2329 |
428 | 2330 /* This must NOT be staticpro'd */ |
2331 Vall_weak_hash_tables = Qnil; | |
452 | 2332 dump_add_weak_object_chain (&Vall_weak_hash_tables); |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2333 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2334 staticpro (&Vhash_table_test_weak_list); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2335 Vhash_table_test_weak_list = make_weak_list (WEAK_LIST_KEY_ASSOC); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2336 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2337 staticpro (&Vhash_table_test_eq); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2338 Vhash_table_test_eq = define_hash_table_test (Qeq, NULL, NULL, Qeq, Qeq_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2339 staticpro (&Vhash_table_test_eql); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2340 Vhash_table_test_eql |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2341 = define_hash_table_test (Qeql, lisp_object_eql_equal, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2342 lisp_object_eql_hash, Qeql, Qeql_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2343 (void) define_hash_table_test (Qequal, lisp_object_equal_equal, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2344 lisp_object_equal_hash, Qequal, Qequal_hash); |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2345 (void) define_hash_table_test (Qequalp, lisp_object_equalp_equal, |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5169
diff
changeset
|
2346 lisp_object_equalp_hash, Qequalp, Qequalp_hash); |
428 | 2347 } |