annotate src/elhash.c @ 211:78478c60bfcd r20-4b4

Import from CVS: tag r20-4b4
author cvs
date Mon, 13 Aug 2007 10:05:51 +0200
parents e45d5e7c476e
children 2c611d1463a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Lisp interface to hash tables.
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.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "hash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "bytecode.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 Lisp_Object Qhashtablep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #define LISP_OBJECTS_PER_HENTRY (sizeof (hentry) / sizeof (Lisp_Object))/* 2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
34 struct hashtable
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 unsigned int fullness;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 unsigned long (*hash_function) (CONST void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 int (*test_function) (CONST void *, CONST void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Lisp_Object zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 Lisp_Object harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 enum hashtable_type type; /* whether and how this hashtable is weak */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Lisp_Object next_weak; /* Used to chain together all of the weak
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 hashtables. Don't mark through this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 static Lisp_Object Vall_weak_hashtables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 static Lisp_Object mark_hashtable (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 static void print_hashtable (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 DEFINE_LRECORD_IMPLEMENTATION ("hashtable", hashtable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 mark_hashtable, print_hashtable, 0, 0, 0,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
53 struct hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 mark_hashtable (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
58 struct hashtable *table = XHASHTABLE (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 if (table->type != HASHTABLE_NONWEAK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 /* If the table is weak, we don't want to mark the keys and values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (we scan over them after everything else has been marked,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 and mark or remove them as necessary). Note that we will mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 the table->harray itself at the same time; it's hard to mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 that here without also marking its contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ((markobj) (table->zero_entry));
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
70 return table->harray;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
72
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 print_hashtable (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
76 struct hashtable *table = XHASHTABLE (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 error ("printing unreadable object #<hashtable 0x%x>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 table->header.uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 sprintf (buf, GETTEXT ("#<%shashtable %d/%ld 0x%x>"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (table->type == HASHTABLE_WEAK ? "weak " :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 table->type == HASHTABLE_KEY_WEAK ? "key-weak " :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 table->type == HASHTABLE_VALUE_WEAK ? "value-weak " :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 table->type == HASHTABLE_KEY_CAR_WEAK ? "key-car-weak " :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 table->type == HASHTABLE_VALUE_CAR_WEAK ? "value-car-weak " :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ""),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 table->fullness,
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
89 XVECTOR_LENGTH (table->harray) / LISP_OBJECTS_PER_HENTRY,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 table->header.uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
95 ht_copy_to_c (struct hashtable *ht, c_hashtable c_table)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
97 int len = XVECTOR_LENGTH (ht->harray);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
99 c_table->harray = (hentry *) XVECTOR_DATA (ht->harray);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 c_table->zero_set = (!GC_UNBOUNDP (ht->zero_entry));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 c_table->zero_entry = LISP_TO_VOID (ht->zero_entry);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
102 #ifndef LRECORD_VECTOR
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 if (len < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 /* #### if alloc.c mark_object() changes, this must change too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 /* barf gag retch. When a vector is marked, its len is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 made less than 0. In the prune_weak_hashtables() stage,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 we are called on vectors that are like this, and we must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 be able to deal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 assert (gc_in_progress);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 len = -1 - len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
113 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
114 c_table->size = len/LISP_OBJECTS_PER_HENTRY;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
115 c_table->fullness = ht->fullness;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 c_table->hash_function = ht->hash_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 c_table->test_function = ht->test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 XSETHASHTABLE (c_table->elisp_table, ht);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
122 ht_copy_from_c (c_hashtable c_table, struct hashtable *ht)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 struct Lisp_Vector dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 /* C is truly hateful */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 void *vec_addr
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
127 = ((char *) c_table->harray
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
128 - ((char *) &(dummy.contents[0]) - (char *) &dummy));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 XSETVECTOR (ht->harray, vec_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (c_table->zero_set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 VOID_TO_LISP (ht->zero_entry, c_table->zero_entry);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ht->zero_entry = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ht->fullness = c_table->fullness;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
139 static struct hashtable *
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 allocate_hashtable (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
142 struct hashtable *table =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
143 alloc_lcrecord_type (struct hashtable, lrecord_hashtable);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
144 table->harray = Qnil;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
145 table->zero_entry = Qunbound;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
146 table->fullness = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 table->hash_function = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 table->test_function = 0;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
149 return table;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
152 void *
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 elisp_hvector_malloc (unsigned int bytes, Lisp_Object table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 Lisp_Object new_vector;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
156 struct hashtable *ht = XHASHTABLE (table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
158 assert (bytes > XVECTOR_LENGTH (ht->harray) * sizeof (Lisp_Object));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
159 new_vector = make_vector ((bytes / sizeof (Lisp_Object)), Qnull_pointer);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
160 return (void *) XVECTOR_DATA (new_vector);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 elisp_hvector_free (void *ptr, Lisp_Object table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
166 struct hashtable *ht = XHASHTABLE (table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 #if defined (USE_ASSERTIONS) || defined (DEBUG_XEMACS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Lisp_Object current_vector = ht->harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
171 assert (((void *) XVECTOR_DATA (current_vector)) == ptr);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ht->harray = Qnil; /* Let GC do its job */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
176 DEFUN ("hashtablep", Fhashtablep, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Return t if OBJ is a hashtable, else nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
178 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
179 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
181 return HASHTABLEP (obj) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 #if 0 /* I don't think these are needed any more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 If using the general lisp_object_equal_*() functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 causes efficiency problems, these can be resurrected. --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 /* equality and hash functions for Lisp strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 lisp_string_equal (CONST void *x1, CONST void *x2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Lisp_Object str1, str2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 CVOID_TO_LISP (str1, x1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 CVOID_TO_LISP (str2, x2);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
197 return !strcmp ((char *) XSTRING_DATA (str1), (char *) XSTRING_DATA (str2));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 lisp_string_hash (CONST void *x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Lisp_Object str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 CVOID_TO_LISP (str, x);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
205 return hash_string (XSTRING_DATA (str), XSTRING_LENGTH (str));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 lisp_object_eql_equal (CONST void *x1, CONST void *x2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 Lisp_Object obj1, obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 CVOID_TO_LISP (obj1, x1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 CVOID_TO_LISP (obj2, x2);
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
216 return FLOATP (obj1) ? internal_equal (obj1, obj2, 0) : EQ (obj1, obj2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 lisp_object_eql_hash (CONST void *x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 CVOID_TO_LISP (obj, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 return internal_hash (obj, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 return LISP_HASH (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 lisp_object_equal_equal (CONST void *x1, CONST void *x2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 Lisp_Object obj1, obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 CVOID_TO_LISP (obj1, x1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 CVOID_TO_LISP (obj2, x2);
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 187
diff changeset
236 return internal_equal (obj1, obj2, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 lisp_object_equal_hash (CONST void *x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 CVOID_TO_LISP (obj, x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 return internal_hash (obj, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 make_lisp_hashtable (int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 enum hashtable_type type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 enum hashtable_test_fun test)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 Lisp_Object result;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
253 struct hashtable *table = allocate_hashtable ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 table->harray = make_vector ((compute_harray_size (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 * LISP_OBJECTS_PER_HENTRY),
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
257 Qnull_pointer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 switch (test)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 case HASHTABLE_EQ:
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
261 table->test_function = NULL;
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
262 table->hash_function = NULL;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 case HASHTABLE_EQL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 table->test_function = lisp_object_eql_equal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 table->hash_function = lisp_object_eql_hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 case HASHTABLE_EQUAL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 table->test_function = lisp_object_equal_equal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 table->hash_function = lisp_object_equal_hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 table->type = type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 XSETHASHTABLE (result, table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 if (table->type != HASHTABLE_NONWEAK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 table->next_weak = Vall_weak_hashtables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 Vall_weak_hashtables = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 table->next_weak = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
290 return result;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 static enum hashtable_test_fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 decode_hashtable_test_fun (Lisp_Object sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
296 if (NILP (sym)) return HASHTABLE_EQL;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
297 if (EQ (sym, Qeq)) return HASHTABLE_EQ;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
298 if (EQ (sym, Qequal)) return HASHTABLE_EQUAL;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
299 if (EQ (sym, Qeql)) return HASHTABLE_EQL;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
300
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 signal_simple_error ("Invalid hashtable test fun", sym);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
302 return HASHTABLE_EQ; /* not reached */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
305 DEFUN ("make-hashtable", Fmake_hashtable, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Make a hashtable of initial size SIZE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Comparison between keys is done with TEST-FUN, which must be one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 `eq', `eql', or `equal'. The default is `eql'; i.e. two keys must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 be the same object (or have the same floating-point value, for floats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 to be considered equivalent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 See also `make-weak-hashtable', `make-key-weak-hashtable', and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 `make-value-weak-hashtable'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
314 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
315 (size, test_fun))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 CHECK_NATNUM (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 return make_lisp_hashtable (XINT (size), HASHTABLE_NONWEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 decode_hashtable_test_fun (test_fun));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
322 DEFUN ("copy-hashtable", Fcopy_hashtable, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 Make a new hashtable which contains the same keys and values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 as the given table. The keys and values will not themselves be copied.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
325 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
326 (old_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 struct _C_hashtable old_htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 struct _C_hashtable new_htbl;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
330 struct hashtable *old_ht;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
331 struct hashtable *new_ht;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 Lisp_Object result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 CHECK_HASHTABLE (old_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 old_ht = XHASHTABLE (old_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ht_copy_to_c (old_ht, &old_htbl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 /* we can't just call Fmake_hashtable() here because that will make a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 table that is slightly larger than the one we're trying to copy,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 which will make copy_hash() blow up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 new_ht = allocate_hashtable ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 new_ht->fullness = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 new_ht->zero_entry = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 new_ht->hash_function = old_ht->hash_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 new_ht->test_function = old_ht->test_function;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
346 new_ht->harray = Fmake_vector (Flength (old_ht->harray), Qnull_pointer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ht_copy_to_c (new_ht, &new_htbl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 copy_hash (&new_htbl, &old_htbl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ht_copy_from_c (&new_htbl, new_ht);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 new_ht->type = old_ht->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 XSETHASHTABLE (result, new_ht);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 if (UNBOUNDP (old_ht->next_weak))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 new_ht->next_weak = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 new_ht->next_weak = Vall_weak_hashtables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Vall_weak_hashtables = result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
361 return result;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
365 DEFUN ("gethash", Fgethash, 2, 3, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
366 Find hash value for KEY in HASHTABLE.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 If there is no corresponding value, return DEFAULT (defaults to nil).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
368 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
369 (key, hashtable, default_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 CONST void *vval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 if (!gc_in_progress)
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
374 CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
375 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 if (gethash (LISP_TO_VOID (key), &htbl, &vval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 CVOID_TO_LISP (val, vval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
382 else
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
383 return default_;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
387 DEFUN ("remhash", Fremhash, 2, 2, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
388 Remove hash value for KEY in HASHTABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
389 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
390 (key, hashtable))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 struct _C_hashtable htbl;
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
393 CHECK_HASHTABLE (hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
395 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 remhash (LISP_TO_VOID (key), &htbl);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
397 ht_copy_from_c (&htbl, XHASHTABLE (hashtable));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
402 DEFUN ("puthash", Fputhash, 3, 3, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
403 Hash KEY to VAL in HASHTABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
404 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
405 (key, val, hashtable))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
407 struct hashtable *ht;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 void *vkey = LISP_TO_VOID (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
410 CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
411 ht = XHASHTABLE (hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 if (!vkey)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ht->zero_entry = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
419 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
420 GCPRO3 (key, val, hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 puthash (vkey, LISP_TO_VOID (val), &htbl);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
422 ht_copy_from_c (&htbl, XHASHTABLE (hashtable));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
425 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
428 DEFUN ("clrhash", Fclrhash, 1, 1, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
429 Remove all entries from HASHTABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
430 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
431 (hashtable))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 struct _C_hashtable htbl;
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
434 CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
435 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 clrhash (&htbl);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
437 ht_copy_from_c (&htbl, XHASHTABLE (hashtable));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
441 DEFUN ("hashtable-fullness", Fhashtable_fullness, 1, 1, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
442 Return number of entries in HASHTABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
443 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
444 (hashtable))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 struct _C_hashtable htbl;
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
447 CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
448 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
449 return make_int (htbl.fullness);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 verify_function (Lisp_Object function, CONST char *description)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 if (SYMBOLP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 if (NILP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 function = indirect_function (function, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 if (SUBRP (function) || COMPILED_FUNCTIONP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 else if (CONSP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 Lisp_Object funcar = Fcar (function);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
468 if ((SYMBOLP (funcar)) && (EQ (funcar, Qlambda) ||
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
469 EQ (funcar, Qautoload)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 signal_error (Qinvalid_function, list1 (function));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 lisp_maphash_function (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 void *void_fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Lisp_Object key, val, fn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 VOID_TO_LISP (val, void_val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 VOID_TO_LISP (fn, void_fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 call2 (fn, key, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
489 DEFUN ("maphash", Fmaphash, 2, 2, 0, /*
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
490 Map FUNCTION over entries in HASHTABLE, calling it with two args,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 each key and value in the table.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
492 */
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
493 (function, hashtable))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 verify_function (function, GETTEXT ("hashtable mapping function"));
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
499 CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
500 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
501 GCPRO2 (hashtable, function);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 maphash (lisp_maphash_function, &htbl, LISP_TO_VOID (function));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 /* This function is for mapping a *C* function over the elements of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 lisp hashtable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 void
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
512 elisp_maphash (maphash_function function, Lisp_Object hashtable, void *closure)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
516 if (!gc_in_progress) CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
517 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 maphash (function, &htbl, closure);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 void
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
522 elisp_map_remhash (remhash_predicate function, Lisp_Object hashtable,
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
523 void *closure)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
527 if (!gc_in_progress) CHECK_HASHTABLE (hashtable);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
528 ht_copy_to_c (XHASHTABLE (hashtable), &htbl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 map_remhash (function, &htbl, closure);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
530 ht_copy_from_c (&htbl, XHASHTABLE (hashtable));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 elisp_table_op (Lisp_Object table, generic_hashtable_op op, void *arg1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 void *arg2, void *arg3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 struct _C_hashtable htbl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 CHECK_HASHTABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ht_copy_to_c (XHASHTABLE (table), &htbl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (*op) (&htbl, arg1, arg2, arg3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ht_copy_from_c (&htbl, XHASHTABLE (table));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
548 DEFUN ("make-weak-hashtable", Fmake_weak_hashtable, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 Make a fully weak hashtable of initial size SIZE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 A weak hashtable is one whose pointers do not count as GC referents:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 for any key-value pair in the hashtable, if the only remaining pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 to either the key or the value is in a weak hash table, then the pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 will be removed from the table, and the key and value collected. A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 non-weak hash table (or any other pointer) would prevent the object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 from being collected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 You can also create semi-weak hashtables; see `make-key-weak-hashtable'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 and `make-value-weak-hashtable'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
559 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
560 (size, test_fun))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 CHECK_NATNUM (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 return make_lisp_hashtable (XINT (size), HASHTABLE_WEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 decode_hashtable_test_fun (test_fun));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
567 DEFUN ("make-key-weak-hashtable", Fmake_key_weak_hashtable, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 Make a key-weak hashtable of initial size SIZE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 A key-weak hashtable is similar to a fully-weak hashtable (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 `make-weak-hashtable') except that a key-value pair will be removed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 only if the key remains unmarked outside of weak hashtables. The pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 will remain in the hashtable if the key is pointed to by something other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 than a weak hashtable, even if the value is not.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
574 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
575 (size, test_fun))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 CHECK_NATNUM (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 return make_lisp_hashtable (XINT (size), HASHTABLE_KEY_WEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 decode_hashtable_test_fun (test_fun));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
582 DEFUN ("make-value-weak-hashtable", Fmake_value_weak_hashtable, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 Make a value-weak hashtable of initial size SIZE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 A value-weak hashtable is similar to a fully-weak hashtable (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 `make-weak-hashtable') except that a key-value pair will be removed only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 if the value remains unmarked outside of weak hashtables. The pair will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 remain in the hashtable if the value is pointed to by something other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 than a weak hashtable, even if the key is not.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
589 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
590 (size, test_fun))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 CHECK_NATNUM (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 return make_lisp_hashtable (XINT (size), HASHTABLE_VALUE_WEAK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 decode_hashtable_test_fun (test_fun));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 struct marking_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 int (*obj_marked_p) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 void (*markobj) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 enum hashtable_type type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 int did_mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 marking_mapper (CONST void *key, void *contents, void *closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 Lisp_Object keytem, valuetem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 struct marking_closure *fmh =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (struct marking_closure *) closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 /* This function is called over each pair in the hashtable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 We complete the marking for semi-weak hashtables. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 CVOID_TO_LISP (keytem, key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 CVOID_TO_LISP (valuetem, contents);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
616
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 switch (fmh->type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 case HASHTABLE_KEY_WEAK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 if ((fmh->obj_marked_p) (keytem) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 !(fmh->obj_marked_p) (valuetem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (fmh->markobj) (valuetem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 case HASHTABLE_VALUE_WEAK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 if ((fmh->obj_marked_p) (valuetem) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 !(fmh->obj_marked_p) (keytem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (fmh->markobj) (keytem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 case HASHTABLE_KEY_CAR_WEAK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 if (!CONSP (keytem) || (fmh->obj_marked_p) (XCAR (keytem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 if (!(fmh->obj_marked_p) (keytem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (fmh->markobj) (keytem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 if (!(fmh->obj_marked_p) (valuetem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (fmh->markobj) (valuetem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 case HASHTABLE_VALUE_CAR_WEAK:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 if (!CONSP (valuetem) || (fmh->obj_marked_p) (XCAR (valuetem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (!(fmh->obj_marked_p) (keytem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (fmh->markobj) (keytem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 if (!(fmh->obj_marked_p) (valuetem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (fmh->markobj) (valuetem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 fmh->did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 abort (); /* Huh? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
672
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 finish_marking_weak_hashtables (int (*obj_marked_p) (Lisp_Object),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 int did_mark = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 for (rest = Vall_weak_hashtables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 !GC_NILP (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 rest = XHASHTABLE (rest)->next_weak)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 enum hashtable_type type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 if (! ((*obj_marked_p) (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 /* The hashtable is probably garbage. Ignore it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 type = XHASHTABLE (rest)->type;
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
693 if (type == HASHTABLE_KEY_WEAK ||
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
694 type == HASHTABLE_VALUE_WEAK ||
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
695 type == HASHTABLE_KEY_CAR_WEAK ||
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
696 type == HASHTABLE_VALUE_CAR_WEAK)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 struct marking_closure fmh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 fmh.obj_marked_p = obj_marked_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 fmh.markobj = markobj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 fmh.type = type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 fmh.did_mark = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 /* Now, scan over all the pairs. For all pairs that are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 half-marked, we may need to mark the other half if we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 keeping this pair. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 elisp_maphash (marking_mapper, rest, &fmh);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 if (fmh.did_mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 /* #### If alloc.c mark_object changes, this must change also... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 /* Now mark the vector itself. (We don't need to call markobj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 here because we know that everything *in* it is already marked,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 we just need to prevent the vector itself from disappearing.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (The remhash above has taken care of zero_entry.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 struct Lisp_Vector *ptr = XVECTOR (XHASHTABLE (rest)->harray);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 int len = vector_length (ptr);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
721 #ifdef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
722 if (! MARKED_RECORD_P(XHASHTABLE(rest)->harray))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
723 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
724 MARK_RECORD_HEADER(&(ptr->header.lheader));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
725 did_mark = 1;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
726 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
727 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 if (len >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ptr->size = -1 - len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 did_mark = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
733 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 /* else it's already marked (remember, this function is iterated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 until marking stops) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 return did_mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 struct pruning_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 int (*obj_marked_p) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 pruning_mapper (CONST void *key, CONST void *contents, void *closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 Lisp_Object keytem, valuetem;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
751 struct pruning_closure *fmh = (struct pruning_closure *) closure;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 /* This function is called over each pair in the hashtable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 We remove the pairs that aren't completely marked (everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 that is going to stay ought to have been marked already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 by the finish_marking stage). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 CVOID_TO_LISP (keytem, key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 CVOID_TO_LISP (valuetem, contents);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
760 return ! ((*fmh->obj_marked_p) (keytem) &&
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
761 (*fmh->obj_marked_p) (valuetem));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 prune_weak_hashtables (int (*obj_marked_p) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 Lisp_Object rest, prev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 for (rest = Vall_weak_hashtables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 !GC_NILP (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 rest = XHASHTABLE (rest)->next_weak)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 if (! ((*obj_marked_p) (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 /* This table itself is garbage. Remove it from the list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 if (GC_NILP (prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 Vall_weak_hashtables = XHASHTABLE (rest)->next_weak;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 XHASHTABLE (prev)->next_weak = XHASHTABLE (rest)->next_weak;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 struct pruning_closure fmh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 fmh.obj_marked_p = obj_marked_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 /* Now, scan over all the pairs. Remove all of the pairs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 in which the key or value, or both, is unmarked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (depending on the type of weak hashtable). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 elisp_map_remhash (pruning_mapper, rest, &fmh);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 prev = rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 /* Return a hash value for an array of Lisp_Objects of size SIZE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 internal_array_hash (Lisp_Object *arr, int size, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 unsigned long hash = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 if (size <= 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 for (i = 0; i < size; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 hash = HASH2 (hash, internal_hash (arr[i], depth + 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
807
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 /* just pick five elements scattered throughout the array.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 A slightly better approach would be to offset by some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 noise factor from the points chosen below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 for (i = 0; i < 5; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 hash = HASH2 (hash, internal_hash (arr[i*size/5], depth + 1));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
813
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 /* 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
818 objects with the comparison being `equal' (for `eq', you can just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 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
820 tradeoff between the speed of the hash function and how good the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 hashing is. In particular, the hash function needs to be FAST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 so you can't just traipse down the whole tree hashing everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 together. Most of the time, objects will differ in the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 few elements you hash. Thus, we only go to a short depth (5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 and only hash at most 5 elements out of a vector. Theoretically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 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
827 hash, but practically this won't ever happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 internal_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 if (depth > 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 if (CONSP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 /* no point in worrying about tail recursion, since we're not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 going very deep */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 return HASH2 (internal_hash (XCAR (obj), depth + 1),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 internal_hash (XCDR (obj), depth + 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 else if (STRINGP (obj))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
842 return hash_string (XSTRING_DATA (obj), XSTRING_LENGTH (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 else if (VECTORP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 struct Lisp_Vector *v = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 return HASH2 (vector_length (v),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 internal_array_hash (v->contents, vector_length (v),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 depth + 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 else if (LRECORDP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 CONST struct lrecord_implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
853 *imp = XRECORD_LHEADER_IMPLEMENTATION (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 if (imp->hash)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 153
diff changeset
855 return (imp->hash) (obj, depth);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 return LISP_HASH (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 syms_of_elhash (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
869 DEFSUBR (Fmake_hashtable);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
870 DEFSUBR (Fcopy_hashtable);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
871 DEFSUBR (Fhashtablep);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
872 DEFSUBR (Fgethash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
873 DEFSUBR (Fputhash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
874 DEFSUBR (Fremhash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
875 DEFSUBR (Fclrhash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
876 DEFSUBR (Fmaphash);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
877 DEFSUBR (Fhashtable_fullness);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
878 DEFSUBR (Fmake_weak_hashtable);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
879 DEFSUBR (Fmake_key_weak_hashtable);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
880 DEFSUBR (Fmake_value_weak_hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 defsymbol (&Qhashtablep, "hashtablep");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 vars_of_elhash (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
887 /* This must NOT be staticpro'd */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 Vall_weak_hashtables = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 }