annotate src/elhash.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 2f8bb876ab1d
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1 /* Implementation of the hash table lisp object type.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995, 1996 Ben Wing.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
4 Copyright (C) 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCNTABILITY or
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "lisp.h"
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
27 #include "bytecode.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
30 Lisp_Object Qhash_tablep;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
31 static Lisp_Object Qhashtable, Qhash_table;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
32 static Lisp_Object Qweakness, Qvalue, Qkey_value;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
33 static Lisp_Object Vall_weak_hash_tables;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
34 static Lisp_Object Qrehash_size, Qrehash_threshold;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
35 static Lisp_Object Q_size, Q_test, Q_weakness, Q_rehash_size, Q_rehash_threshold;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
36
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
37 /* obsolete as of 19990901 in xemacs-21.2 */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
38 static Lisp_Object Qweak, Qkey_weak, Qvalue_weak, Qkey_value_weak;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
39 static Lisp_Object Qnon_weak, Q_type;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
40
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
41 typedef struct hentry
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
42 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
43 Lisp_Object key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
44 Lisp_Object value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
45 } hentry;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
47 struct Lisp_Hash_Table
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 struct lcrecord_header header;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
50 size_t size;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
51 size_t count;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
52 size_t rehash_count;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
53 double rehash_size;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
54 double rehash_threshold;
394
7d59cb494b73 Import from CVS: tag r21-2-12
cvs
parents: 380
diff changeset
55 size_t golden_ratio;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
56 hash_table_hash_function_t hash_function;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
57 hash_table_test_function_t test_function;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
58 hentry *hentries;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
59 enum hash_table_weakness weakness;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
60 Lisp_Object next_weak; /* Used to chain together all of the weak
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
61 hash tables. Don't mark through this. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
64 #define HENTRY_CLEAR_P(hentry) ((*(EMACS_UINT*)(&((hentry)->key))) == 0)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
65 #define CLEAR_HENTRY(hentry) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
66 ((*(EMACS_UINT*)(&((hentry)->key))) = 0, \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
67 (*(EMACS_UINT*)(&((hentry)->value))) = 0)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
68
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
69 #define HASH_TABLE_DEFAULT_SIZE 16
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
70 #define HASH_TABLE_DEFAULT_REHASH_SIZE 1.3
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
71 #define HASH_TABLE_MIN_SIZE 10
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
72
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
73 #define HASH_CODE(key, ht) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
74 ((((ht)->hash_function ? (ht)->hash_function (key) : LISP_HASH (key)) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
75 * (ht)->golden_ratio) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
76 % (ht)->size)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
77
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
78 #define KEYS_EQUAL_P(key1, key2, testfun) \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
79 (EQ (key1, key2) || ((testfun) && (testfun) (key1, key2)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
80
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
81 #define LINEAR_PROBING_LOOP(probe, entries, size) \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
82 for (; \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
83 !HENTRY_CLEAR_P (probe) || \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
84 (probe == entries + size ? \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
85 (probe = entries, !HENTRY_CLEAR_P (probe)) : 0); \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
86 probe++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
87
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
88 #ifndef ERROR_CHECK_HASH_TABLE
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
89 # ifdef ERROR_CHECK_TYPECHECK
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
90 # define ERROR_CHECK_HASH_TABLE 1
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
91 # else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
92 # define ERROR_CHECK_HASH_TABLE 0
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
93 # endif
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
94 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
96 #if ERROR_CHECK_HASH_TABLE
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
97 static void
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
98 check_hash_table_invariants (Lisp_Hash_Table *ht)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
100 assert (ht->count < ht->size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
101 assert (ht->count <= ht->rehash_count);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
102 assert (ht->rehash_count < ht->size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
103 assert ((double) ht->count * ht->rehash_threshold - 1 <= (double) ht->rehash_count);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
104 assert (HENTRY_CLEAR_P (ht->hentries + ht->size));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
105 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
106 #else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
107 #define check_hash_table_invariants(ht)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
108 #endif
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
109
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
110 /* We use linear probing instead of double hashing, despite its lack
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
111 of blessing by Knuth and company, because, as a result of the
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
112 increasing discrepancy between CPU speeds and memory speeds, cache
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
113 behavior is becoming increasingly important, e.g:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
114
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
115 For a trivial loop, the penalty for non-sequential access of an array is:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
116 - a factor of 3-4 on Pentium Pro 200 Mhz
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
117 - a factor of 10 on Ultrasparc 300 Mhz */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
119 /* Return a suitable size for a hash table, with at least SIZE slots. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
120 static size_t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
121 hash_table_size (size_t requested_size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
122 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
123 /* Return some prime near, but greater than or equal to, SIZE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
124 Decades from the time of writing, someone will have a system large
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
125 enough that the list below will be too short... */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
126 static const size_t primes [] =
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
127 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
128 19, 29, 41, 59, 79, 107, 149, 197, 263, 347, 457, 599, 787, 1031,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
129 1361, 1777, 2333, 3037, 3967, 5167, 6719, 8737, 11369, 14783,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
130 19219, 24989, 32491, 42257, 54941, 71429, 92861, 120721, 156941,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
131 204047, 265271, 344857, 448321, 582821, 757693, 985003, 1280519,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
132 1664681, 2164111, 2813353, 3657361, 4754591, 6180989, 8035301,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
133 10445899, 13579681, 17653589, 22949669, 29834603, 38784989,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
134 50420551, 65546729, 85210757, 110774011, 144006217, 187208107,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
135 243370577, 316381771, 411296309, 534685237, 695090819, 903618083,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
136 1174703521, 1527114613, 1985248999, 2580823717UL, 3355070839UL
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
137 };
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
138 /* We've heard of binary search. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
139 int low, high;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
140 for (low = 0, high = countof (primes) - 1; high - low > 1;)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
142 /* Loop Invariant: size < primes [high] */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
143 int mid = (low + high) / 2;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
144 if (primes [mid] < requested_size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
145 low = mid;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
146 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
147 high = mid;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
149 return primes [high];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
151
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
152
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
153 #if 0 /* I don't think these are needed any more.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
154 If using the general lisp_object_equal_*() functions
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
155 causes efficiency problems, these can be resurrected. --ben */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
156 /* equality and hash functions for Lisp strings */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
157 int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
158 lisp_string_equal (Lisp_Object str1, Lisp_Object str2)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
159 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
160 /* This is wrong anyway. You can't use strcmp() on Lisp strings,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
161 because they can contain zero characters. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
162 return !strcmp ((char *) XSTRING_DATA (str1), (char *) XSTRING_DATA (str2));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
163 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
164
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
165 static hashcode_t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
166 lisp_string_hash (Lisp_Object obj)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
167 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
168 return hash_string (XSTRING_DATA (str), XSTRING_LENGTH (str));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
169 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
170
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
171 #endif /* 0 */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
172
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
173 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
174 lisp_object_eql_equal (Lisp_Object obj1, Lisp_Object obj2)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
175 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
176 return EQ (obj1, obj2) || (FLOATP (obj1) && internal_equal (obj1, obj2, 0));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
177 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
178
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
179 static hashcode_t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
180 lisp_object_eql_hash (Lisp_Object obj)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
181 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
182 return FLOATP (obj) ? internal_hash (obj, 0) : LISP_HASH (obj);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
183 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
184
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
185 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
186 lisp_object_equal_equal (Lisp_Object obj1, Lisp_Object obj2)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
187 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
188 return internal_equal (obj1, obj2, 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
189 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
190
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
191 static hashcode_t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
192 lisp_object_equal_hash (Lisp_Object obj)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
193 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
194 return internal_hash (obj, 0);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
195 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
196
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
197
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
198 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
199 mark_hash_table (Lisp_Object obj)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
200 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
201 Lisp_Hash_Table *ht = XHASH_TABLE (obj);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
202
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
203 /* If the hash table is weak, we don't want to mark the keys and
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
204 values (we scan over them after everything else has been marked,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
205 and mark or remove them as necessary). */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
206 if (ht->weakness == HASH_TABLE_NON_WEAK)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
207 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
208 hentry *e, *sentinel;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
209
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
210 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
211 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
212 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
213 mark_object (e->key);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
214 mark_object (e->value);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
215 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
216 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
217 return Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
218 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
219
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
220 /* Equality of hash tables. Two hash tables are equal when they are of
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
221 the same weakness and test function, they have the same number of
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
222 elements, and for each key in the hash table, the values are `equal'.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
223
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
224 This is similar to Common Lisp `equalp' of hash tables, with the
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
225 difference that CL requires the keys to be compared with the test
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
226 function, which we don't do. Doing that would require consing, and
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
227 consing is a bad idea in `equal'. Anyway, our method should provide
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
228 the same result -- if the keys are not equal according to the test
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
229 function, then Fgethash() in hash_table_equal_mapper() will fail. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
230 static int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
231 hash_table_equal (Lisp_Object hash_table1, Lisp_Object hash_table2, int depth)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
232 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
233 Lisp_Hash_Table *ht1 = XHASH_TABLE (hash_table1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
234 Lisp_Hash_Table *ht2 = XHASH_TABLE (hash_table2);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
235 hentry *e, *sentinel;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
236
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
237 if ((ht1->test_function != ht2->test_function) ||
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
238 (ht1->weakness != ht2->weakness) ||
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
239 (ht1->count != ht2->count))
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
240 return 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
241
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
242 depth++;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
243
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
244 for (e = ht1->hentries, sentinel = e + ht1->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
245 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
246 /* Look up the key in the other hash table, and compare the values. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
247 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
248 Lisp_Object value_in_other = Fgethash (e->key, hash_table2, Qunbound);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
249 if (UNBOUNDP (value_in_other) ||
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
250 !internal_equal (e->value, value_in_other, depth))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
251 return 0; /* Give up */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
252 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
253
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
254 return 1;
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
255 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
256
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
257 /* This is not a great hash function, but it _is_ correct and fast.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
258 Examining all entries is too expensive, and examining a random
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
259 subset does not yield a correct hash function. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
260 static hashcode_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
261 hash_table_hash (Lisp_Object hash_table, int depth)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
262 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
263 return XHASH_TABLE (hash_table)->count;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
264 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
265
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
266
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
267 /* Printing hash tables.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
268
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
269 This is non-trivial, because we use a readable structure-style
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
270 syntax for hash tables. This means that a typical hash table will be
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
271 readably printed in the form of:
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
272
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
273 #s(hash-table size 2 data (key1 value1 key2 value2))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
274
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
275 The supported hash table structure keywords and their values are:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
276 `test' (eql (or nil), eq or equal)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
277 `size' (a natnum or nil)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
278 `rehash-size' (a float)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
279 `rehash-threshold' (a float)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
280 `weakness' (nil, t, key or value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
281 `data' (a list)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
282
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
283 If `print-readably' is nil, then a simpler syntax is used, for example
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
284
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
285 #<hash-table size 2/13 data (key1 value1 key2 value2) 0x874d>
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
286
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
287 The data is truncated to four pairs, and the rest is shown with
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
288 `...'. This printer does not cons. */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
289
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
290
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
291 /* Print the data of the hash table. This maps through a Lisp
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
292 hash table and prints key/value pairs using PRINTCHARFUN. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
293 static void
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
294 print_hash_table_data (Lisp_Hash_Table *ht, Lisp_Object printcharfun)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
295 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
296 int count = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
297 hentry *e, *sentinel;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
298
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
299 write_c_string (" data (", printcharfun);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
300
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
301 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
302 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
303 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
304 if (count > 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
305 write_c_string (" ", printcharfun);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
306 if (!print_readably && count > 3)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
307 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
308 write_c_string ("...", printcharfun);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
309 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
310 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
311 print_internal (e->key, printcharfun, 1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
312 write_c_string (" ", printcharfun);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
313 print_internal (e->value, printcharfun, 1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
314 count++;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
315 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
316
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
317 write_c_string (")", printcharfun);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
318 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
319
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
320 static void
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
321 print_hash_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
322 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
323 Lisp_Hash_Table *ht = XHASH_TABLE (obj);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
324 char buf[128];
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
325
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
326 write_c_string (print_readably ? "#s(hash-table" : "#<hash-table",
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
327 printcharfun);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
328
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
329 /* These checks have a kludgy look to them, but they are safe.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
330 Due to nature of hashing, you cannot use arbitrary
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
331 test functions anyway. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
332 if (!ht->test_function)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
333 write_c_string (" test eq", printcharfun);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
334 else if (ht->test_function == lisp_object_equal_equal)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
335 write_c_string (" test equal", printcharfun);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
336 else if (ht->test_function == lisp_object_eql_equal)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 223
diff changeset
337 DO_NOTHING;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
338 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
339 abort ();
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
340
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
341 if (ht->count || !print_readably)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
342 {
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
343 if (print_readably)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
344 sprintf (buf, " size %lu", (unsigned long) ht->count);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
345 else
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
346 sprintf (buf, " size %lu/%lu",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
347 (unsigned long) ht->count,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
348 (unsigned long) ht->size);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
349 write_c_string (buf, printcharfun);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
350 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
351
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
352 if (ht->weakness != HASH_TABLE_NON_WEAK)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
353 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
354 sprintf (buf, " weakness %s",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
355 (ht->weakness == HASH_TABLE_WEAK ? "t" :
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
356 ht->weakness == HASH_TABLE_KEY_WEAK ? "key" :
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
357 ht->weakness == HASH_TABLE_VALUE_WEAK ? "value" :
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
358 ht->weakness == HASH_TABLE_KEY_VALUE_WEAK ? "key-value" :
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
359 "you-d-better-not-see-this"));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
360 write_c_string (buf, printcharfun);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
361 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
362
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
363 if (ht->count)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
364 print_hash_table_data (ht, printcharfun);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
365
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (print_readably)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
367 write_c_string (")", printcharfun);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
368 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
369 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
370 sprintf (buf, " 0x%x>", ht->header.uid);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
371 write_c_string (buf, printcharfun);
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
372 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
373 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
374
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
375 static void
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
376 finalize_hash_table (void *header, int for_disksave)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
377 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
378 if (!for_disksave)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
379 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
380 Lisp_Hash_Table *ht = (Lisp_Hash_Table *) header;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
381
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
382 xfree (ht->hentries);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
383 ht->hentries = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
384 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
385 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
386
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
387 static const struct lrecord_description hentry_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
388 { XD_LISP_OBJECT, offsetof (hentry, key) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
389 { XD_LISP_OBJECT, offsetof (hentry, value) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
390 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
391 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
392
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
393 static const struct struct_description hentry_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
394 sizeof (hentry),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
395 hentry_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
396 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
397
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
398 const struct lrecord_description hash_table_description[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
399 { XD_SIZE_T, offsetof (Lisp_Hash_Table, size) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
400 { XD_STRUCT_PTR, offsetof (Lisp_Hash_Table, hentries), XD_INDIRECT(0, 1), &hentry_description },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
401 { XD_LO_LINK, offsetof (Lisp_Hash_Table, next_weak) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
402 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
403 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
404
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
405 DEFINE_LRECORD_IMPLEMENTATION ("hash-table", hash_table,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
406 mark_hash_table, print_hash_table,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
407 finalize_hash_table,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
408 hash_table_equal, hash_table_hash,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
409 hash_table_description,
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
410 Lisp_Hash_Table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
411
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
412 static Lisp_Hash_Table *
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
413 xhash_table (Lisp_Object hash_table)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
414 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
415 if (!gc_in_progress)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
416 CHECK_HASH_TABLE (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
417 check_hash_table_invariants (XHASH_TABLE (hash_table));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
418 return XHASH_TABLE (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
419 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
420
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
421
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
422 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
423 /* Creation of Hash Tables */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
424 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
425
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
426 /* Creation of hash tables, without error-checking. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
427 static void
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
428 compute_hash_table_derived_values (Lisp_Hash_Table *ht)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
429 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
430 ht->rehash_count = (size_t)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
431 ((double) ht->size * ht->rehash_threshold);
394
7d59cb494b73 Import from CVS: tag r21-2-12
cvs
parents: 380
diff changeset
432 ht->golden_ratio = (size_t)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
433 ((double) ht->size * (.6180339887 / (double) sizeof (Lisp_Object)));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
434 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
435
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
436 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
437 make_general_lisp_hash_table (enum hash_table_test test,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
438 size_t size,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
439 double rehash_size,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
440 double rehash_threshold,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
441 enum hash_table_weakness weakness)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
442 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
443 Lisp_Object hash_table;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
444 Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
445
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
446 switch (test)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
447 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
448 case HASH_TABLE_EQ:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
449 ht->test_function = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
450 ht->hash_function = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
451 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
452
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
453 case HASH_TABLE_EQL:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
454 ht->test_function = lisp_object_eql_equal;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
455 ht->hash_function = lisp_object_eql_hash;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
456 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
457
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
458 case HASH_TABLE_EQUAL:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
459 ht->test_function = lisp_object_equal_equal;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
460 ht->hash_function = lisp_object_equal_hash;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
461 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
462
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
463 default:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
464 abort ();
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
465 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
466
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
467 ht->weakness = weakness;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
468
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
469 ht->rehash_size =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
470 rehash_size > 1.0 ? rehash_size : HASH_TABLE_DEFAULT_REHASH_SIZE;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
471
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
472 ht->rehash_threshold =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
473 rehash_threshold > 0.0 ? rehash_threshold :
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
474 size > 4096 && !ht->test_function ? 0.7 : 0.6;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
475
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
476 if (size < HASH_TABLE_MIN_SIZE)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
477 size = HASH_TABLE_MIN_SIZE;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
478 ht->size = hash_table_size ((size_t) (((double) size / ht->rehash_threshold)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
479 + 1.0));
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
480 ht->count = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
481
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
482 compute_hash_table_derived_values (ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
483
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
484 /* We leave room for one never-occupied sentinel hentry at the end. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
485 ht->hentries = xnew_array (hentry, ht->size + 1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
486
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
487 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
488 hentry *e, *sentinel;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
489 for (e = ht->hentries, sentinel = e + ht->size; e <= sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
490 CLEAR_HENTRY (e);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
491 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
492
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
493 XSETHASH_TABLE (hash_table, ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
494
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
495 if (weakness == HASH_TABLE_NON_WEAK)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
496 ht->next_weak = Qunbound;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
497 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
498 ht->next_weak = Vall_weak_hash_tables, Vall_weak_hash_tables = hash_table;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
499
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
500 return hash_table;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
501 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
502
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
503 Lisp_Object
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
504 make_lisp_hash_table (size_t size,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
505 enum hash_table_weakness weakness,
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
506 enum hash_table_test test)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
507 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
508 return make_general_lisp_hash_table (test, size, -1.0, -1.0, weakness);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
509 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
510
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
511 /* Pretty reading of hash tables.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
512
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
513 Here we use the existing structures mechanism (which is,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
514 unfortunately, pretty cumbersome) for validating and instantiating
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
515 the hash tables. The idea is that the side-effect of reading a
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
516 #s(hash-table PLIST) object is creation of a hash table with desired
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
517 properties, and that the hash table is returned. */
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
518
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
519 /* Validation functions: each keyword provides its own validation
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
520 function. The errors should maybe be continuable, but it is
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
521 unclear how this would cope with ERRB. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
522 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
523 hash_table_size_validate (Lisp_Object keyword, Lisp_Object value,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
524 Error_behavior errb)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
525 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
526 if (NATNUMP (value))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
527 return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
528
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
529 maybe_signal_error (Qwrong_type_argument, list2 (Qnatnump, value),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
530 Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
531 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
532 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
533
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
534 static size_t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
535 decode_hash_table_size (Lisp_Object obj)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
536 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
537 return NILP (obj) ? HASH_TABLE_DEFAULT_SIZE : XINT (obj);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
538 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
539
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
540 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
541 hash_table_weakness_validate (Lisp_Object keyword, Lisp_Object value,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
542 Error_behavior errb)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
543 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
544 if (EQ (value, Qnil)) return 1;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
545 if (EQ (value, Qt)) return 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
546 if (EQ (value, Qkey)) return 1;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
547 if (EQ (value, Qkey_value)) return 1;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
548 if (EQ (value, Qvalue)) return 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
549
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
550 /* Following values are obsolete as of 19990901 in xemacs-21.2 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
551 if (EQ (value, Qnon_weak)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
552 if (EQ (value, Qweak)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
553 if (EQ (value, Qkey_weak)) return 1;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
554 if (EQ (value, Qkey_value_weak)) return 1;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
555 if (EQ (value, Qvalue_weak)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
556
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
557 maybe_signal_simple_error ("Invalid hash table weakness",
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
558 value, Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
559 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
560 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
561
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
562 static enum hash_table_weakness
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
563 decode_hash_table_weakness (Lisp_Object obj)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
564 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
565 if (EQ (obj, Qnil)) return HASH_TABLE_NON_WEAK;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
566 if (EQ (obj, Qt)) return HASH_TABLE_WEAK;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
567 if (EQ (obj, Qkey)) return HASH_TABLE_KEY_WEAK;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
568 if (EQ (obj, Qkey_value)) return HASH_TABLE_KEY_VALUE_WEAK;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
569 if (EQ (obj, Qvalue)) return HASH_TABLE_VALUE_WEAK;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
570
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
571 /* Following values are obsolete as of 19990901 in xemacs-21.2 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
572 if (EQ (obj, Qnon_weak)) return HASH_TABLE_NON_WEAK;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
573 if (EQ (obj, Qweak)) return HASH_TABLE_WEAK;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
574 if (EQ (obj, Qkey_weak)) return HASH_TABLE_KEY_WEAK;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
575 if (EQ (obj, Qkey_value_weak)) return HASH_TABLE_KEY_VALUE_WEAK;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
576 if (EQ (obj, Qvalue_weak)) return HASH_TABLE_VALUE_WEAK;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
577
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
578 signal_simple_error ("Invalid hash table weakness", obj);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
579 return HASH_TABLE_NON_WEAK; /* not reached */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
580 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
581
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
582 static int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
583 hash_table_test_validate (Lisp_Object keyword, Lisp_Object value,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
584 Error_behavior errb)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
585 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
586 if (EQ (value, Qnil)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
587 if (EQ (value, Qeq)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
588 if (EQ (value, Qequal)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
589 if (EQ (value, Qeql)) return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
590
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
591 maybe_signal_simple_error ("Invalid hash table test",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
592 value, Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
593 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
594 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
595
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
596 static enum hash_table_test
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
597 decode_hash_table_test (Lisp_Object obj)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
598 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
599 if (EQ (obj, Qnil)) return HASH_TABLE_EQL;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
600 if (EQ (obj, Qeq)) return HASH_TABLE_EQ;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
601 if (EQ (obj, Qequal)) return HASH_TABLE_EQUAL;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
602 if (EQ (obj, Qeql)) return HASH_TABLE_EQL;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
603
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
604 signal_simple_error ("Invalid hash table test", obj);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
605 return HASH_TABLE_EQ; /* not reached */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
606 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
607
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
608 static int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
609 hash_table_rehash_size_validate (Lisp_Object keyword, Lisp_Object value,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
610 Error_behavior errb)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
611 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
612 if (!FLOATP (value))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
613 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
614 maybe_signal_error (Qwrong_type_argument, list2 (Qfloatp, value),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
615 Qhash_table, errb);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
616 return 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
617 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
618
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
619 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
620 double rehash_size = XFLOAT_DATA (value);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
621 if (rehash_size <= 1.0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
622 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
623 maybe_signal_simple_error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
624 ("Hash table rehash size must be greater than 1.0",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
625 value, Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
626 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
627 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
628 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
629
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
630 return 1;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
631 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
632
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
633 static double
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
634 decode_hash_table_rehash_size (Lisp_Object rehash_size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
635 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
636 return NILP (rehash_size) ? -1.0 : XFLOAT_DATA (rehash_size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
637 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
638
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
639 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
640 hash_table_rehash_threshold_validate (Lisp_Object keyword, Lisp_Object value,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
641 Error_behavior errb)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
642 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
643 if (!FLOATP (value))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
644 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
645 maybe_signal_error (Qwrong_type_argument, list2 (Qfloatp, value),
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
646 Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
647 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
648 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
649
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
650 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
651 double rehash_threshold = XFLOAT_DATA (value);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
652 if (rehash_threshold <= 0.0 || rehash_threshold >= 1.0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
653 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
654 maybe_signal_simple_error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
655 ("Hash table rehash threshold must be between 0.0 and 1.0",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
656 value, Qhash_table, errb);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
657 return 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
658 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
659 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
660
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
661 return 1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
662 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
663
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
664 static double
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
665 decode_hash_table_rehash_threshold (Lisp_Object rehash_threshold)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
666 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
667 return NILP (rehash_threshold) ? -1.0 : XFLOAT_DATA (rehash_threshold);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
668 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
669
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
670 static int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
671 hash_table_data_validate (Lisp_Object keyword, Lisp_Object value,
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
672 Error_behavior errb)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
673 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
674 int len;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
675
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
676 GET_EXTERNAL_LIST_LENGTH (value, len);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
677
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
678 if (len & 1)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
679 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
680 maybe_signal_simple_error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
681 ("Hash table data must have alternating key/value pairs",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
682 value, Qhash_table, errb);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
683 return 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
684 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
685 return 1;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
686 }
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
687
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
688 /* The actual instantiation of a hash table. This does practically no
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
689 error checking, because it relies on the fact that the paranoid
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
690 functions above have error-checked everything to the last details.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
691 If this assumption is wrong, we will get a crash immediately (with
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
692 error-checking compiled in), and we'll know if there is a bug in
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
693 the structure mechanism. So there. */
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
694 static Lisp_Object
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
695 hash_table_instantiate (Lisp_Object plist)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
696 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
697 Lisp_Object hash_table;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
698 Lisp_Object test = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
699 Lisp_Object size = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
700 Lisp_Object rehash_size = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
701 Lisp_Object rehash_threshold = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
702 Lisp_Object weakness = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
703 Lisp_Object data = Qnil;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
704
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
705 while (!NILP (plist))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
706 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
707 Lisp_Object key, value;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
708 key = XCAR (plist); plist = XCDR (plist);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
709 value = XCAR (plist); plist = XCDR (plist);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
710
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
711 if (EQ (key, Qtest)) test = value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
712 else if (EQ (key, Qsize)) size = value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
713 else if (EQ (key, Qrehash_size)) rehash_size = value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
714 else if (EQ (key, Qrehash_threshold)) rehash_threshold = value;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
715 else if (EQ (key, Qweakness)) weakness = value;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
716 else if (EQ (key, Qdata)) data = value;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
717 else if (EQ (key, Qtype))/*obsolete*/ weakness = value;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
718 else
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
719 abort ();
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
720 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
721
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
722 /* Create the hash table. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
723 hash_table = make_general_lisp_hash_table
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
724 (decode_hash_table_test (test),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
725 decode_hash_table_size (size),
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
726 decode_hash_table_rehash_size (rehash_size),
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
727 decode_hash_table_rehash_threshold (rehash_threshold),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
728 decode_hash_table_weakness (weakness));
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
729
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
730 /* I'm not sure whether this can GC, but better safe than sorry. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
731 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
732 struct gcpro gcpro1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
733 GCPRO1 (hash_table);
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
734
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
735 /* And fill it with data. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
736 while (!NILP (data))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
737 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
738 Lisp_Object key, value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
739 key = XCAR (data); data = XCDR (data);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
740 value = XCAR (data); data = XCDR (data);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
741 Fputhash (key, value, hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
742 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
743 UNGCPRO;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
744 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
745
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
746 return hash_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 static void
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
750 structure_type_create_hash_table_structure_name (Lisp_Object structure_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
752 struct structure_type *st;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
754 st = define_structure_type (structure_name, 0, hash_table_instantiate);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
755 define_structure_type_keyword (st, Qtest, hash_table_test_validate);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
756 define_structure_type_keyword (st, Qsize, hash_table_size_validate);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
757 define_structure_type_keyword (st, Qrehash_size, hash_table_rehash_size_validate);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
758 define_structure_type_keyword (st, Qrehash_threshold, hash_table_rehash_threshold_validate);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
759 define_structure_type_keyword (st, Qweakness, hash_table_weakness_validate);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
760 define_structure_type_keyword (st, Qdata, hash_table_data_validate);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
761
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
762 /* obsolete as of 19990901 in xemacs-21.2 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
763 define_structure_type_keyword (st, Qtype, hash_table_weakness_validate);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
766 /* Create a built-in Lisp structure type named `hash-table'.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
767 We make #s(hashtable ...) equivalent to #s(hash-table ...),
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
768 for backward compatibility.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
769 This is called from emacs.c. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 void
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
771 structure_type_create_hash_table (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
773 structure_type_create_hash_table_structure_name (Qhash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
774 structure_type_create_hash_table_structure_name (Qhashtable); /* compat */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
778 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
779 /* Definition of Lisp-visible methods */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
780 /************************************************************************/
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
782 DEFUN ("hash-table-p", Fhash_table_p, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
783 Return t if OBJECT is a hash table, else nil.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
784 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
785 (object))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
787 return HASH_TABLEP (object) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
790 DEFUN ("make-hash-table", Fmake_hash_table, 0, MANY, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
791 Return a new empty hash table object.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
792 Use Common Lisp style keywords to specify hash table properties.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
793 (make-hash-table &key test size rehash-size rehash-threshold weakness)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
794
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
795 Keyword :test can be `eq', `eql' (default) or `equal'.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
796 Comparison between keys is done using this function.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
797 If speed is important, consider using `eq'.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
798 When storing strings in the hash table, you will likely need to use `equal'.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
799
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
800 Keyword :size specifies the number of keys likely to be inserted.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
801 This number of entries can be inserted without enlarging the hash table.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
802
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
803 Keyword :rehash-size must be a float greater than 1.0, and specifies
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
804 the factor by which to increase the size of the hash table when enlarging.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
805
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
806 Keyword :rehash-threshold must be a float between 0.0 and 1.0,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
807 and specifies the load factor of the hash table which triggers enlarging.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
808
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
809 Non-standard keyword :weakness can be `nil' (default), `t', `key', `value'
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
810 or `key-value'.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
811
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
812 A weak hash table is one whose pointers do not count as GC referents:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
813 for any key-value pair in the hash table, if the only remaining pointer
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
814 to either the key or the value is in a weak hash table, then the pair
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
815 will be removed from the hash table, and the key and value collected.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
816 A non-weak hash table (or any other pointer) would prevent the object
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
817 from being collected.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
818
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
819 A key-weak hash table is similar to a fully-weak hash table except that
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
820 a key-value pair will be removed only if the key remains unmarked
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
821 outside of weak hash tables. The pair will remain in the hash table if
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
822 the key is pointed to by something other than a weak hash table, even
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
823 if the value is not.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
824
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
825 A value-weak hash table is similar to a fully-weak hash table except
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
826 that a key-value pair will be removed only if the value remains
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
827 unmarked outside of weak hash tables. The pair will remain in the
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
828 hash table if the value is pointed to by something other than a weak
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
829 hash table, even if the key is not.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
830
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
831 A key-value-weak hash table is similar to a fully-weak hash table except
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
832 that a key-value pair will be removed only if the value and the key remain
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
833 unmarked outside of weak hash tables. The pair will remain in the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
834 hash table if the value or key are pointed to by something other than a weak
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
835 hash table, even if the other is not.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
836 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
837 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
839 int i = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
840 Lisp_Object test = Qnil;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
841 Lisp_Object size = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
842 Lisp_Object rehash_size = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
843 Lisp_Object rehash_threshold = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
844 Lisp_Object weakness = Qnil;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
845
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
846 while (i + 1 < nargs)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
847 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
848 Lisp_Object keyword = args[i++];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
849 Lisp_Object value = args[i++];
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
850
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
851 if (EQ (keyword, Q_test)) test = value;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
852 else if (EQ (keyword, Q_size)) size = value;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
853 else if (EQ (keyword, Q_rehash_size)) rehash_size = value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
854 else if (EQ (keyword, Q_rehash_threshold)) rehash_threshold = value;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
855 else if (EQ (keyword, Q_weakness)) weakness = value;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
856 else if (EQ (keyword, Q_type))/*obsolete*/ weakness = value;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
857 else signal_simple_error ("Invalid hash table property keyword", keyword);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
858 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
859
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
860 if (i < nargs)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
861 signal_simple_error ("Hash table property requires a value", args[i]);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
862
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
863 #define VALIDATE_VAR(var) \
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
864 if (!NILP (var)) hash_table_##var##_validate (Q##var, var, ERROR_ME);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
865
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
866 VALIDATE_VAR (test);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
867 VALIDATE_VAR (size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
868 VALIDATE_VAR (rehash_size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
869 VALIDATE_VAR (rehash_threshold);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
870 VALIDATE_VAR (weakness);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
871
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
872 return make_general_lisp_hash_table
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
873 (decode_hash_table_test (test),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
874 decode_hash_table_size (size),
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
875 decode_hash_table_rehash_size (rehash_size),
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
876 decode_hash_table_rehash_threshold (rehash_threshold),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
877 decode_hash_table_weakness (weakness));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
880 DEFUN ("copy-hash-table", Fcopy_hash_table, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
881 Return a new hash table containing the same keys and values as HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
882 The keys and values will not themselves be copied.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
883 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
884 (hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
886 const Lisp_Hash_Table *ht_old = xhash_table (hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
887 Lisp_Hash_Table *ht = alloc_lcrecord_type (Lisp_Hash_Table, &lrecord_hash_table);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
888
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
889 copy_lcrecord (ht, ht_old);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
890
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
891 ht->hentries = xnew_array (hentry, ht_old->size + 1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
892 memcpy (ht->hentries, ht_old->hentries, (ht_old->size + 1) * sizeof (hentry));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
893
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
894 XSETHASH_TABLE (hash_table, ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
895
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
896 if (! EQ (ht->next_weak, Qunbound))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
897 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
898 ht->next_weak = Vall_weak_hash_tables;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
899 Vall_weak_hash_tables = hash_table;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
900 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
901
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
902 return hash_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
905 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
906 resize_hash_table (Lisp_Hash_Table *ht, size_t new_size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
908 hentry *old_entries, *new_entries, *sentinel, *e;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
909 size_t old_size;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
910
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
911 old_size = ht->size;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
912 ht->size = new_size;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
913
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
914 old_entries = ht->hentries;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
915
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
916 ht->hentries = xnew_array_and_zero (hentry, new_size + 1);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
917 new_entries = ht->hentries;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
918
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
919 compute_hash_table_derived_values (ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
920
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
921 for (e = old_entries, sentinel = e + old_size; e < sentinel; e++)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
922 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
923 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
924 hentry *probe = new_entries + HASH_CODE (e->key, ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
925 LINEAR_PROBING_LOOP (probe, new_entries, new_size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
926 ;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
927 *probe = *e;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
928 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
930 if (!DUMPEDP (old_entries))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
931 xfree (old_entries);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
932 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
933
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
934 /* After a hash table has been saved to disk and later restored by the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
935 portable dumper, it contains the same objects, but their addresses
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
936 and thus their HASH_CODEs have changed. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
937 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
938 pdump_reorganize_hash_table (Lisp_Object hash_table)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
939 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
940 const Lisp_Hash_Table *ht = xhash_table (hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
941 hentry *new_entries = xnew_array_and_zero (hentry, ht->size + 1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
942 hentry *e, *sentinel;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
943
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
944 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
945 if (!HENTRY_CLEAR_P (e))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
946 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
947 hentry *probe = new_entries + HASH_CODE (e->key, ht);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
948 LINEAR_PROBING_LOOP (probe, new_entries, ht->size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
949 ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
950 *probe = *e;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
951 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
952
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
953 memcpy (ht->hentries, new_entries, ht->size * sizeof (hentry));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
954
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
955 xfree (new_entries);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
956 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
957
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
958 static void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
959 enlarge_hash_table (Lisp_Hash_Table *ht)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
960 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
961 size_t new_size =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
962 hash_table_size ((size_t) ((double) ht->size * ht->rehash_size));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
963 resize_hash_table (ht, new_size);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
964 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
965
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
966 static hentry *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
967 find_hentry (Lisp_Object key, const Lisp_Hash_Table *ht)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
968 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
969 hash_table_test_function_t test_function = ht->test_function;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
970 hentry *entries = ht->hentries;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
971 hentry *probe = entries + HASH_CODE (key, ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
972
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
973 LINEAR_PROBING_LOOP (probe, entries, ht->size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
974 if (KEYS_EQUAL_P (probe->key, key, test_function))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
977 return probe;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
978 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
980 DEFUN ("gethash", Fgethash, 2, 3, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
981 Find hash value for KEY in HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
982 If there is no corresponding value, return DEFAULT (which defaults to nil).
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
983 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
984 (key, hash_table, default_))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
985 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
986 const Lisp_Hash_Table *ht = xhash_table (hash_table);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
987 hentry *e = find_hentry (key, ht);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
989 return HENTRY_CLEAR_P (e) ? default_ : e->value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
992 DEFUN ("puthash", Fputhash, 3, 3, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
993 Hash KEY to VALUE in HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
994 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
995 (key, value, hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
997 Lisp_Hash_Table *ht = xhash_table (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
998 hentry *e = find_hentry (key, ht);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1000 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1001 return e->value = value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1003 e->key = key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1004 e->value = value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1005
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1006 if (++ht->count >= ht->rehash_count)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1007 enlarge_hash_table (ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1008
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1009 return value;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1012 /* Remove hentry pointed at by PROBE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1013 Subsequent entries are removed and reinserted.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1014 We don't use tombstones - too wasteful. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1015 static void
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1016 remhash_1 (Lisp_Hash_Table *ht, hentry *entries, hentry *probe)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1018 size_t size = ht->size;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1019 CLEAR_HENTRY (probe);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1020 probe++;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1021 ht->count--;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1023 LINEAR_PROBING_LOOP (probe, entries, size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1025 Lisp_Object key = probe->key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1026 hentry *probe2 = entries + HASH_CODE (key, ht);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1027 LINEAR_PROBING_LOOP (probe2, entries, size)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1028 if (EQ (probe2->key, key))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1029 /* hentry at probe doesn't need to move. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1030 goto continue_outer_loop;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1031 /* Move hentry from probe to new home at probe2. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1032 *probe2 = *probe;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1033 CLEAR_HENTRY (probe);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1034 continue_outer_loop: continue;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1038 DEFUN ("remhash", Fremhash, 2, 2, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1039 Remove the entry for KEY from HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1040 Do nothing if there is no entry for KEY in HASH-TABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1041 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1042 (key, hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1044 Lisp_Hash_Table *ht = xhash_table (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1045 hentry *e = find_hentry (key, ht);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1047 if (HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1048 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1050 remhash_1 (ht, ht->hentries, e);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1051 return Qt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1054 DEFUN ("clrhash", Fclrhash, 1, 1, 0, /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1055 Remove all entries from HASH-TABLE, leaving it empty.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1056 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1057 (hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1059 Lisp_Hash_Table *ht = xhash_table (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1060 hentry *e, *sentinel;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1061
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1062 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1063 CLEAR_HENTRY (e);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1064 ht->count = 0;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1065
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1066 return hash_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1069 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1070 /* Accessor Functions */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1071 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1072
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1073 DEFUN ("hash-table-count", Fhash_table_count, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1074 Return the number of entries in HASH-TABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1075 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1076 (hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1078 return make_int (xhash_table (hash_table)->count);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1081 DEFUN ("hash-table-test", Fhash_table_test, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1082 Return the test function of HASH-TABLE.
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1083 This can be one of `eq', `eql' or `equal'.
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1084 */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1085 (hash_table))
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1086 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1087 hash_table_test_function_t fun = xhash_table (hash_table)->test_function;
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1088
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1089 return (fun == lisp_object_eql_equal ? Qeql :
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1090 fun == lisp_object_equal_equal ? Qequal :
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1091 Qeq);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1092 }
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1093
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1094 DEFUN ("hash-table-size", Fhash_table_size, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1095 Return the size of HASH-TABLE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1096 This is the current number of slots in HASH-TABLE, whether occupied or not.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1097 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1098 (hash_table))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1099 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1100 return make_int (xhash_table (hash_table)->size);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1101 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1102
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1103 DEFUN ("hash-table-rehash-size", Fhash_table_rehash_size, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1104 Return the current rehash size of HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1105 This is a float greater than 1.0; the factor by which HASH-TABLE
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1106 is enlarged when the rehash threshold is exceeded.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1107 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1108 (hash_table))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1109 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1110 return make_float (xhash_table (hash_table)->rehash_size);
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 241
diff changeset
1111 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1113 DEFUN ("hash-table-rehash-threshold", Fhash_table_rehash_threshold, 1, 1, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1114 Return the current rehash threshold of HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1115 This is a float between 0.0 and 1.0; the maximum `load factor' of HASH-TABLE,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1116 beyond which the HASH-TABLE is enlarged by rehashing.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1117 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1118 (hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1120 return make_float (xhash_table (hash_table)->rehash_threshold);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1121 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1122
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1123 DEFUN ("hash-table-weakness", Fhash_table_weakness, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1124 Return the weakness of HASH-TABLE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1125 This can be one of `nil', `t', `key' or `value'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1126 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1127 (hash_table))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1128 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1129 switch (xhash_table (hash_table)->weakness)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1130 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1131 case HASH_TABLE_WEAK: return Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1132 case HASH_TABLE_KEY_WEAK: return Qkey;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1133 case HASH_TABLE_KEY_VALUE_WEAK: return Qkey_value;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1134 case HASH_TABLE_VALUE_WEAK: return Qvalue;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1135 default: return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1136 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1137 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1138
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1139 /* obsolete as of 19990901 in xemacs-21.2 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1140 DEFUN ("hash-table-type", Fhash_table_type, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1141 Return the type of HASH-TABLE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1142 This can be one of `non-weak', `weak', `key-weak' or `value-weak'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1143 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1144 (hash_table))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1145 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1146 switch (xhash_table (hash_table)->weakness)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1147 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1148 case HASH_TABLE_WEAK: return Qweak;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1149 case HASH_TABLE_KEY_WEAK: return Qkey_weak;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1150 case HASH_TABLE_KEY_VALUE_WEAK: return Qkey_value_weak;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1151 case HASH_TABLE_VALUE_WEAK: return Qvalue_weak;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1152 default: return Qnon_weak;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1153 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1156 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1157 /* Mapping Functions */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1158 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1159 DEFUN ("maphash", Fmaphash, 2, 2, 0, /*
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1160 Map FUNCTION over entries in HASH-TABLE, calling it with two args,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1161 each key and value in HASH-TABLE.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1162
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1163 FUNCTION may not modify HASH-TABLE, with the one exception that FUNCTION
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1164 may remhash or puthash the entry currently being processed by FUNCTION.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1165 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1166 (function, hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1168 const Lisp_Hash_Table *ht = xhash_table (hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1169 const hentry *e, *sentinel;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1171 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1172 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1173 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1174 Lisp_Object args[3], key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1175 again:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1176 key = e->key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1177 args[0] = function;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1178 args[1] = key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1179 args[2] = e->value;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1180 Ffuncall (countof (args), args);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1181 /* Has FUNCTION done a remhash? */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1182 if (!EQ (key, e->key) && !HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1183 goto again;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1184 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1189 /* Map *C* function FUNCTION over the elements of a lisp hash table. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 void
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1191 elisp_maphash (maphash_function_t function,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1192 Lisp_Object hash_table, void *extra_arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1194 const Lisp_Hash_Table *ht = XHASH_TABLE (hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1195 const hentry *e, *sentinel;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1197 for (e = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1198 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1199 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1200 Lisp_Object key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1201 again:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1202 key = e->key;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1203 if (function (key, e->value, extra_arg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1204 return;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1205 /* Has FUNCTION done a remhash? */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1206 if (!EQ (key, e->key) && !HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1207 goto again;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1208 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1211 /* Remove all elements of a lisp hash table satisfying *C* predicate PREDICATE. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 void
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1213 elisp_map_remhash (maphash_function_t predicate,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1214 Lisp_Object hash_table, void *extra_arg)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1216 Lisp_Hash_Table *ht = XHASH_TABLE (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1217 hentry *e, *entries, *sentinel;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1219 for (e = entries = ht->hentries, sentinel = e + ht->size; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1220 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1221 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1222 again:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1223 if (predicate (e->key, e->value, extra_arg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1224 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1225 remhash_1 (ht, entries, e);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1226 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1227 goto again;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1228 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1229 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1232
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1233 /************************************************************************/
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1234 /* garbage collecting weak hash tables */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1235 /************************************************************************/
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1236 #define MARK_OBJ(obj) do { \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1237 Lisp_Object mo_obj = (obj); \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1238 if (!marked_p (mo_obj)) \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1239 { \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1240 mark_object (mo_obj); \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1241 did_mark = 1; \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1242 } \
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1243 } while (0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1244
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1246 /* Complete the marking for semi-weak hash tables. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1248 finish_marking_weak_hash_tables (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1250 Lisp_Object hash_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 int did_mark = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1253 for (hash_table = Vall_weak_hash_tables;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1254 !NILP (hash_table);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1255 hash_table = XHASH_TABLE (hash_table)->next_weak)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1257 const Lisp_Hash_Table *ht = XHASH_TABLE (hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1258 const hentry *e = ht->hentries;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1259 const hentry *sentinel = e + ht->size;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1260
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1261 if (! marked_p (hash_table))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1262 /* The hash table is probably garbage. Ignore it. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1263 continue;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1265 /* Now, scan over all the pairs. For all pairs that are
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1266 half-marked, we may need to mark the other half if we're
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1267 keeping this pair. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1268 switch (ht->weakness)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1270 case HASH_TABLE_KEY_WEAK:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1271 for (; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1272 if (!HENTRY_CLEAR_P (e))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1273 if (marked_p (e->key))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1274 MARK_OBJ (e->value);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1275 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1277 case HASH_TABLE_VALUE_WEAK:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1278 for (; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1279 if (!HENTRY_CLEAR_P (e))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1280 if (marked_p (e->value))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1281 MARK_OBJ (e->key);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1282 break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1284 case HASH_TABLE_KEY_VALUE_WEAK:
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1285 for (; e < sentinel; e++)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1286 if (!HENTRY_CLEAR_P (e))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1287 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1288 if (marked_p (e->value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1289 MARK_OBJ (e->key);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1290 else if (marked_p (e->key))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1291 MARK_OBJ (e->value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1292 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1293 break;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1294
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1295 case HASH_TABLE_KEY_CAR_WEAK:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1296 for (; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1297 if (!HENTRY_CLEAR_P (e))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1298 if (!CONSP (e->key) || marked_p (XCAR (e->key)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1299 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1300 MARK_OBJ (e->key);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1301 MARK_OBJ (e->value);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1302 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1303 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1304
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1305 case HASH_TABLE_VALUE_CAR_WEAK:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1306 for (; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1307 if (!HENTRY_CLEAR_P (e))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1308 if (!CONSP (e->value) || marked_p (XCAR (e->value)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1309 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1310 MARK_OBJ (e->key);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1311 MARK_OBJ (e->value);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1312 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1313 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1314
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1315 default:
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1316 break;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1317 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 return did_mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1323 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1324 prune_weak_hash_tables (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1326 Lisp_Object hash_table, prev = Qnil;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1327 for (hash_table = Vall_weak_hash_tables;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1328 !NILP (hash_table);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1329 hash_table = XHASH_TABLE (hash_table)->next_weak)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1331 if (! marked_p (hash_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1333 /* This hash table itself is garbage. Remove it from the list. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1334 if (NILP (prev))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1335 Vall_weak_hash_tables = XHASH_TABLE (hash_table)->next_weak;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 else
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1337 XHASH_TABLE (prev)->next_weak = XHASH_TABLE (hash_table)->next_weak;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 /* Now, scan over all the pairs. Remove all of the pairs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 in which the key or value, or both, is unmarked
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1343 (depending on the weakness of the hash table). */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1344 Lisp_Hash_Table *ht = XHASH_TABLE (hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1345 hentry *entries = ht->hentries;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1346 hentry *sentinel = entries + ht->size;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1347 hentry *e;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1348
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1349 for (e = entries; e < sentinel; e++)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1350 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1351 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1352 again:
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1353 if (!marked_p (e->key) || !marked_p (e->value))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1354 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1355 remhash_1 (ht, entries, e);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1356 if (!HENTRY_CLEAR_P (e))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1357 goto again;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1358 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1359 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1360
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1361 prev = hash_table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 /* Return a hash value for an array of Lisp_Objects of size SIZE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1368 hashcode_t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 internal_array_hash (Lisp_Object *arr, int size, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 int i;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1372 hashcode_t hash = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1373 depth++;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 if (size <= 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 for (i = 0; i < size; i++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1378 hash = HASH2 (hash, internal_hash (arr[i], depth));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
1381
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 /* just pick five elements scattered throughout the array.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 A slightly better approach would be to offset by some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 noise factor from the points chosen below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 for (i = 0; i < 5; i++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1386 hash = HASH2 (hash, internal_hash (arr[i*size/5], depth));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
1387
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 /* Return a hash value for a Lisp_Object. This is for use when hashing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 objects with the comparison being `equal' (for `eq', you can just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 use the Lisp_Object itself as the hash value). You need to make a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 tradeoff between the speed of the hash function and how good the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 hashing is. In particular, the hash function needs to be FAST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 so you can't just traipse down the whole tree hashing everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 together. Most of the time, objects will differ in the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 few elements you hash. Thus, we only go to a short depth (5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 and only hash at most 5 elements out of a vector. Theoretically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 we could still take 5^5 time (a big big number) to compute a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 hash, but practically this won't ever happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1403 hashcode_t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 internal_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 if (depth > 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 if (CONSP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 /* no point in worrying about tail recursion, since we're not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 going very deep */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 return HASH2 (internal_hash (XCAR (obj), depth + 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 internal_hash (XCDR (obj), depth + 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1415 if (STRINGP (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1417 return hash_string (XSTRING_DATA (obj), XSTRING_LENGTH (obj));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1418 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1419 if (LRECORDP (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1421 const struct lrecord_implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
1422 *imp = XRECORD_LHEADER_IMPLEMENTATION (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 if (imp->hash)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1424 return imp->hash (obj, depth);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 return LISP_HASH (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1430 DEFUN ("sxhash", Fsxhash, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1431 Return a hash value for OBJECT.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1432 (equal obj1 obj2) implies (= (sxhash obj1) (sxhash obj2)).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1433 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1434 (object))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1435 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1436 return make_int (internal_hash (object, 0));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1437 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1438
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1439 #if 0
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1440 xxDEFUN ("internal-hash-value", Finternal_hash_value, 1, 1, 0, /*
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1441 Hash value of OBJECT. For debugging.
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1442 The value is returned as (HIGH . LOW).
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1443 */
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1444 (object))
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1445 {
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1446 /* This function is pretty 32bit-centric. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1447 hashcode_t hash = internal_hash (object, 0);
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1448 return Fcons (hash >> 16, hash & 0xffff);
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1449 }
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1450 #endif
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1451
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 syms_of_elhash (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
1460 INIT_LRECORD_IMPLEMENTATION (hash_table);
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
1461
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1462 DEFSUBR (Fhash_table_p);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1463 DEFSUBR (Fmake_hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1464 DEFSUBR (Fcopy_hash_table);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1465 DEFSUBR (Fgethash);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1466 DEFSUBR (Fremhash);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1467 DEFSUBR (Fputhash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1468 DEFSUBR (Fclrhash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1469 DEFSUBR (Fmaphash);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1470 DEFSUBR (Fhash_table_count);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1471 DEFSUBR (Fhash_table_test);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1472 DEFSUBR (Fhash_table_size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1473 DEFSUBR (Fhash_table_rehash_size);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1474 DEFSUBR (Fhash_table_rehash_threshold);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1475 DEFSUBR (Fhash_table_weakness);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1476 DEFSUBR (Fhash_table_type); /* obsolete */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1477 DEFSUBR (Fsxhash);
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1478 #if 0
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1479 DEFSUBR (Finternal_hash_value);
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 231
diff changeset
1480 #endif
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1481
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1482 defsymbol (&Qhash_tablep, "hash-table-p");
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1483 defsymbol (&Qhash_table, "hash-table");
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 211
diff changeset
1484 defsymbol (&Qhashtable, "hashtable");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1485 defsymbol (&Qweakness, "weakness");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1486 defsymbol (&Qvalue, "value");
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1487 defsymbol (&Qkey_value, "key-value");
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1488 defsymbol (&Qrehash_size, "rehash-size");
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1489 defsymbol (&Qrehash_threshold, "rehash-threshold");
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1490
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1491 defsymbol (&Qweak, "weak"); /* obsolete */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1492 defsymbol (&Qkey_weak, "key-weak"); /* obsolete */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 404
diff changeset
1493 defsymbol (&Qkey_value_weak, "key-value-weak"); /* obsolete */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1494 defsymbol (&Qvalue_weak, "value-weak"); /* obsolete */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1495 defsymbol (&Qnon_weak, "non-weak"); /* obsolete */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1496
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1497 defkeyword (&Q_test, ":test");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1498 defkeyword (&Q_size, ":size");
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1499 defkeyword (&Q_rehash_size, ":rehash-size");
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1500 defkeyword (&Q_rehash_threshold, ":rehash-threshold");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1501 defkeyword (&Q_weakness, ":weakness");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1502 defkeyword (&Q_type, ":type"); /* obsolete */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 vars_of_elhash (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1508 /* This must NOT be staticpro'd */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
1509 Vall_weak_hash_tables = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 394
diff changeset
1510 pdump_wire_list (&Vall_weak_hash_tables);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 }