aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann1999-08-22 20:47:15 +0000
committerGerd Moellmann1999-08-22 20:47:15 +0000
commitf899c503c5703cd08e2993ae47b7f83ba9790d6e (patch)
treef6d1919a0922a2bde1f393a9211eabe3f743302f /src
parent57f3e9c9f6316042b10481648c02837c915ca085 (diff)
downloademacs-f899c503c5703cd08e2993ae47b7f83ba9790d6e.tar.gz
emacs-f899c503c5703cd08e2993ae47b7f83ba9790d6e.zip
(Qkey, Qvalue): Renamed from Qkey_weak, and Qvalue_weak.
(Qkey_value_weak): Removed. (make_hash_table): Use nil, `key', `value', t for weakness. (Fmake_hash_table): Ditto. (copy_hash_table): New. (Fcopy_hash_table): New.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c92
1 files changed, 65 insertions, 27 deletions
diff --git a/src/fns.c b/src/fns.c
index c80604a24be..a5f3afec977 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3293,8 +3293,7 @@ Lisp_Object Vweak_hash_tables;
3293 3293
3294/* Various symbols. */ 3294/* Various symbols. */
3295 3295
3296Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey_weak, Qvalue_weak; 3296Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey, Qvalue;
3297Lisp_Object Qkey_value_weak;
3298Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweak; 3297Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweak;
3299Lisp_Object Qhash_table_test; 3298Lisp_Object Qhash_table_test;
3300 3299
@@ -3567,7 +3566,7 @@ user-supplied hash function"),
3567 (table size) is >= REHASH_THRESHOLD. 3566 (table size) is >= REHASH_THRESHOLD.
3568 3567
3569 WEAK specifies the weakness of the table. If non-nil, it must be 3568 WEAK specifies the weakness of the table. If non-nil, it must be
3570 one of the symbols `key-weak', `value-weak' or `key-value-weak'. */ 3569 one of the symbols `key', `value' or t. */
3571 3570
3572Lisp_Object 3571Lisp_Object
3573make_hash_table (test, size, rehash_size, rehash_threshold, weak, 3572make_hash_table (test, size, rehash_size, rehash_threshold, weak,
@@ -3656,6 +3655,41 @@ make_hash_table (test, size, rehash_size, rehash_threshold, weak,
3656} 3655}
3657 3656
3658 3657
3658/* Return a copy of hash table H1. Keys and values are not copied,
3659 only the table itself is. */
3660
3661Lisp_Object
3662copy_hash_table (h1)
3663 struct Lisp_Hash_Table *h1;
3664{
3665 Lisp_Object table;
3666 struct Lisp_Hash_Table *h2;
3667 struct Lisp_Vector *v, *next;
3668 int len;
3669
3670 len = VECSIZE (struct Lisp_Hash_Table);
3671 v = allocate_vectorlike (len);
3672 h2 = (struct Lisp_Hash_Table *) v;
3673 next = h2->vec_next;
3674 bcopy (h1, h2, sizeof *h2);
3675 h2->vec_next = next;
3676 h2->key_and_value = Fcopy_sequence (h1->key_and_value);
3677 h2->hash = Fcopy_sequence (h1->hash);
3678 h2->next = Fcopy_sequence (h1->next);
3679 h2->index = Fcopy_sequence (h1->index);
3680 XSET_HASH_TABLE (table, h2);
3681
3682 /* Maybe add this hash table to the list of all weak hash tables. */
3683 if (!NILP (h2->weak))
3684 {
3685 h2->next_weak = Vweak_hash_tables;
3686 Vweak_hash_tables = table;
3687 }
3688
3689 return table;
3690}
3691
3692
3659/* Resize hash table H if it's too full. If H cannot be resized 3693/* Resize hash table H if it's too full. If H cannot be resized
3660 because it's already too large, throw an error. */ 3694 because it's already too large, throw an error. */
3661 3695
@@ -3901,11 +3935,11 @@ sweep_weak_hash_tables ()
3901 int i = XFASTINT (idx); 3935 int i = XFASTINT (idx);
3902 Lisp_Object next; 3936 Lisp_Object next;
3903 3937
3904 if (EQ (h->weak, Qkey_weak)) 3938 if (EQ (h->weak, Qkey))
3905 remove_p = !survives_gc_p (HASH_KEY (h, i)); 3939 remove_p = !survives_gc_p (HASH_KEY (h, i));
3906 else if (EQ (h->weak, Qvalue_weak)) 3940 else if (EQ (h->weak, Qvalue))
3907 remove_p = !survives_gc_p (HASH_VALUE (h, i)); 3941 remove_p = !survives_gc_p (HASH_VALUE (h, i));
3908 else if (EQ (h->weak, Qkey_value_weak)) 3942 else if (EQ (h->weak, Qt))
3909 remove_p = (!survives_gc_p (HASH_KEY (h, i)) 3943 remove_p = (!survives_gc_p (HASH_KEY (h, i))
3910 || !survives_gc_p (HASH_VALUE (h, i))); 3944 || !survives_gc_p (HASH_VALUE (h, i)));
3911 else 3945 else
@@ -4170,10 +4204,10 @@ multiplying the old size with that factor. Default is 1.5.\n\
4170Resize the hash table when ratio of the number of entries in the table.\n\ 4204Resize the hash table when ratio of the number of entries in the table.\n\
4171Default is 0.8.\n\ 4205Default is 0.8.\n\
4172\n\ 4206\n\
4173:WEAK WEAK -- WEAK must be one of nil, t, `key-weak', `value-weak' or\n\ 4207:WEAK WEAK -- WEAK must be one of nil, t, `key', or `value'.\n\
4174`key-value-weak'. WEAK t means the same as `key-value-weak'. Elements\n\ 4208If WEAK is not nil, the table returned is a weak table. Key/value\n\
4175 are removed from a weak hash table when their key, value or both \n\ 4209pairs are removed from a weak hash table when their key, value or both\n\
4176according to WEAKNESS are otherwise unreferenced. Default is nil.") 4210(WEAK t) are otherwise unreferenced. Default is nil.")
4177 (nargs, args) 4211 (nargs, args)
4178 int nargs; 4212 int nargs;
4179 Lisp_Object *args; 4213 Lisp_Object *args;
@@ -4237,12 +4271,10 @@ according to WEAKNESS are otherwise unreferenced. Default is nil.")
4237 /* Look for `:weak WEAK'. */ 4271 /* Look for `:weak WEAK'. */
4238 i = get_key_arg (QCweak, nargs, args, used); 4272 i = get_key_arg (QCweak, nargs, args, used);
4239 weak = i < 0 ? Qnil : args[i]; 4273 weak = i < 0 ? Qnil : args[i];
4240 if (EQ (weak, Qt))
4241 weak = Qkey_value_weak;
4242 if (!NILP (weak) 4274 if (!NILP (weak)
4243 && !EQ (weak, Qkey_weak) 4275 && !EQ (weak, Qt)
4244 && !EQ (weak, Qvalue_weak) 4276 && !EQ (weak, Qkey)
4245 && !EQ (weak, Qkey_value_weak)) 4277 && !EQ (weak, Qvalue))
4246 Fsignal (Qerror, list2 (build_string ("Illegal hash table weakness"), 4278 Fsignal (Qerror, list2 (build_string ("Illegal hash table weakness"),
4247 weak)); 4279 weak));
4248 4280
@@ -4257,6 +4289,15 @@ according to WEAKNESS are otherwise unreferenced. Default is nil.")
4257} 4289}
4258 4290
4259 4291
4292DEFUN ("copy-hash-table", Fcopy_hash_table, Scopy_hash_table, 1, 1, 0,
4293 "Return a copy of hash table TABLE.")
4294 (table)
4295 Lisp_Object table;
4296{
4297 return copy_hash_table (check_hash_table (table));
4298}
4299
4300
4260DEFUN ("makehash", Fmakehash, Smakehash, 0, MANY, 0, 4301DEFUN ("makehash", Fmakehash, Smakehash, 0, MANY, 0,
4261 "Create a new hash table.\n\ 4302 "Create a new hash table.\n\
4262Optional first argument SIZE is a hint to the implementation as\n\ 4303Optional first argument SIZE is a hint to the implementation as\n\
@@ -4266,9 +4307,8 @@ Optional second argument TEST specifies how to compare keys in\n\
4266the table. Predefined tests are `eq', `eql', and `equal'. Default\n\ 4307the table. Predefined tests are `eq', `eql', and `equal'. Default\n\
4267is `eql'. New tests can be defined with `define-hash-table-test'.\n\ 4308is `eql'. New tests can be defined with `define-hash-table-test'.\n\
4268\n\ 4309\n\
4269Optional third argument WEAK must be one of nil, t, `key-weak',\n\ 4310Optional third argument WEAK must be one of nil, t, `key',\n\
4270 `value-weak' or `key-value-weak'. WEAK t means the same as\n\ 4311 or `value'. Default is nil. Elements of weak hash tables\n\
4271 `key-value-weak'. Default is nil. Elements of weak hash tables\n\
4272are removed when their key, value or both are otherwise unreferenced.\n\ 4312are removed when their key, value or both are otherwise unreferenced.\n\
4273\n\ 4313\n\
4274The rest of the optional arguments are keyword/value pairs. The\n\ 4314The rest of the optional arguments are keyword/value pairs. The\n\
@@ -4310,9 +4350,8 @@ Default is 0.8.")
4310 /* Recognize weakness argument. */ 4350 /* Recognize weakness argument. */
4311 if (EQ (args[i], Qt) 4351 if (EQ (args[i], Qt)
4312 || NILP (args[i]) 4352 || NILP (args[i])
4313 || EQ (args[i], Qkey_weak) 4353 || EQ (args[i], Qkey)
4314 || EQ (args[i], Qvalue_weak) 4354 || EQ (args[i], Qvalue))
4315 || EQ (args[i], Qkey_value_weak))
4316 { 4355 {
4317 args2[j++] = QCweak; 4356 args2[j++] = QCweak;
4318 args2[j++] = args[i++]; 4357 args2[j++] = args[i++];
@@ -4514,17 +4553,16 @@ syms_of_fns ()
4514 staticpro (&QCrehash_threshold); 4553 staticpro (&QCrehash_threshold);
4515 QCweak = intern (":weak"); 4554 QCweak = intern (":weak");
4516 staticpro (&QCweak); 4555 staticpro (&QCweak);
4517 Qkey_weak = intern ("key-weak"); 4556 Qkey = intern ("key");
4518 staticpro (&Qkey_weak); 4557 staticpro (&Qkey);
4519 Qvalue_weak = intern ("value-weak"); 4558 Qvalue = intern ("value");
4520 staticpro (&Qvalue_weak); 4559 staticpro (&Qvalue);
4521 Qkey_value_weak = intern ("key-value-weak");
4522 staticpro (&Qkey_value_weak);
4523 Qhash_table_test = intern ("hash-table-test"); 4560 Qhash_table_test = intern ("hash-table-test");
4524 staticpro (&Qhash_table_test); 4561 staticpro (&Qhash_table_test);
4525 4562
4526 defsubr (&Ssxhash); 4563 defsubr (&Ssxhash);
4527 defsubr (&Smake_hash_table); 4564 defsubr (&Smake_hash_table);
4565 defsubr (&Scopy_hash_table);
4528 defsubr (&Smakehash); 4566 defsubr (&Smakehash);
4529 defsubr (&Shash_table_count); 4567 defsubr (&Shash_table_count);
4530 defsubr (&Shash_table_rehash_size); 4568 defsubr (&Shash_table_rehash_size);