changeset 30496:25d798a40775

(Qkey_or_value, Qkey_and_value): New variables. (syms_of_fns): Initialize new variables. (sweep_weak_table): Handle weakness `key-or-value' and `key-and-value'. (Fmake_hash_table): Recognize `key-and-value' and `key-or-value' weakness, with t meaning the same as `key-and-value'.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 27 Jul 2000 12:31:17 +0000
parents 491e0864dd18
children 66c03b43ceb8
files src/fns.c
diffstat 1 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/fns.c	Thu Jul 27 06:22:42 2000 +0000
+++ b/src/fns.c	Thu Jul 27 12:31:17 2000 +0000
@@ -3578,7 +3578,7 @@
 
 Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey, Qvalue;
 Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
-Lisp_Object Qhash_table_test;
+Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;
 
 /* Function prototypes.  */
 
@@ -3848,7 +3848,7 @@
    (table size) is >= REHASH_THRESHOLD.
 
    WEAK specifies the weakness of the table.  If non-nil, it must be
-   one of the symbols `key', `value' or t.  */
+   one of the symbols `key', `value', `key-or-value', or `key-and-value'.  */
 
 Lisp_Object
 make_hash_table (test, size, rehash_size, rehash_threshold, weak,
@@ -4225,8 +4225,10 @@
 	    remove_p = !key_known_to_survive_p;
 	  else if (EQ (h->weak, Qvalue))
 	    remove_p = !value_known_to_survive_p;
-	  else if (EQ (h->weak, Qt))
+	  else if (EQ (h->weak, Qkey_or_value))
 	    remove_p = !key_known_to_survive_p || !value_known_to_survive_p;
+	  else if (EQ (h->weak, Qkey_and_value))
+	    remove_p = !key_known_to_survive_p && !value_known_to_survive_p;
 	  else
 	    abort ();
 		      
@@ -4531,27 +4533,29 @@
 Arguments are specified as keyword/argument pairs.  The following\n\
 arguments are defined:\n\
 \n\
-:TEST TEST -- TEST must be a symbol that specifies how to compare keys.\n\
+:test TEST -- TEST must be a symbol that specifies how to compare keys.\n\
 Default is `eql'.  Predefined are the tests `eq', `eql', and `equal'.\n\
 User-supplied test and hash functions can be specified via\n\
 `define-hash-table-test'.\n\
 \n\
-:SIZE SIZE -- A hint as to how many elements will be put in the table.\n\
+:size SIZE -- A hint as to how many elements will be put in the table.\n\
 Default is 65.\n\
 \n\
-:REHASH-SIZE REHASH-SIZE - Indicates how to expand the table when\n\
+:rehash-size REHASH-SIZE - Indicates how to expand the table when\n\
 it fills up.  If REHASH-SIZE is an integer, add that many space.\n\
 If it is a float, it must be > 1.0, and the new size is computed by\n\
 multiplying the old size with that factor.  Default is 1.5.\n\
 \n\
-:REHASH-THRESHOLD THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.\n\
+:rehash-threshold THRESHOLD -- THRESHOLD must a float > 0, and <= 1.0.\n\
 Resize the hash table when ratio of the number of entries in the table.\n\
 Default is 0.8.\n\
 \n\
-:WEAKNESS WEAK -- WEAK must be one of nil, t, `key', or `value'.\n\
-If WEAK is not nil, the table returned is a weak table.  Key/value\n\
-pairs are removed from a weak hash table when their key, value or both\n\
-(WEAK t) are otherwise unreferenced.  Default is nil.")
+:weakness WEAK -- WEAK must be one of nil, t, `key', `value',\n\
+`key-or-value', or `key-and-value'.  If WEAK is not nil, the table returned\n\
+is a weak table.  Key/value pairs are removed from a weak hash table when\n\
+there are no non-weak references pointing to their key, value, one of key\n\
+or value, or both key and value, depending on WEAK.  WEAK t is equivalent
+to `key-and-value'.  Default value of WEAK is nil.")
   (nargs, args)
      int nargs;
      Lisp_Object *args;
@@ -4615,10 +4619,13 @@
   /* Look for `:weakness WEAK'.  */
   i = get_key_arg (QCweakness, nargs, args, used);
   weak = i < 0 ? Qnil : args[i];
+  if (EQ (weak, Qt))
+    weak = Qkey_and_value;
   if (!NILP (weak)
-      && !EQ (weak, Qt)
       && !EQ (weak, Qkey)
-      && !EQ (weak, Qvalue))
+      && !EQ (weak, Qvalue)
+      && !EQ (weak, Qkey_or_value)
+      && !EQ (weak, Qkey_and_value))
     Fsignal (Qerror, list2 (build_string ("Illegal hash table weakness"), 
 			    weak));
   
@@ -4852,6 +4859,10 @@
   staticpro (&Qvalue);
   Qhash_table_test = intern ("hash-table-test");
   staticpro (&Qhash_table_test);
+  Qkey_or_value = intern ("key-or-value");
+  staticpro (&Qkey_or_value);
+  Qkey_and_value = intern ("key-and-value");
+  staticpro (&Qkey_and_value);
 
   defsubr (&Ssxhash);
   defsubr (&Smake_hash_table);