]> sjero.net Git - wget/commitdiff
[svn] Allow NULL/0 as hash table keys.
authorhniksic <devnull@localhost>
Fri, 7 Nov 2003 11:40:08 +0000 (03:40 -0800)
committerhniksic <devnull@localhost>
Fri, 7 Nov 2003 11:40:08 +0000 (03:40 -0800)
src/ChangeLog
src/hash.c

index bf5f6ccb135e16a75901316a40a4e04d675ca1df..7227bdfb9e1a2e814f05573dce018805e2c3288d 100644 (file)
@@ -1,3 +1,12 @@
+2003-11-07  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * hash.c (NON_EMPTY): Use the all-bit-set value as the marker that
+       the field is empty.  This allows NULL pointer and 0 value to be
+       used as keys, which is necessary for the connect.c code to work
+       when fd==0.
+       (hash_table_new): Fill mappings with 0xff.
+       (grow_hash_table): Ditto.
+
 2003-11-07  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * url.c (url_parse): Allow empty ports.
index b72fac7152b037c672d82f69099c9018e540ef09..ed8cac1e3c3f086c1eb09271a11af7e5b3027ca7 100644 (file)
@@ -175,9 +175,10 @@ struct hash_table {
   struct mapping *mappings;    /* the array of mapping pairs. */
 };
 
-/* We use NULL key to mark a mapping as empty.  It is consequently
-   illegal to store NULL keys.  */
-#define NON_EMPTY(mp) (mp->key != NULL)
+/* We use all-bit-set marker to mean that a mapping is empty.  It is
+   (hopefully) illegal as a pointer, and it allows the users to use
+   NULL (as well as any non-negative integer) as key.  */
+#define NON_EMPTY(mp) (mp->key != (void *)~(unsigned long)0)
 
 /* "Next" mapping is the mapping after MP, but wrapping back to
    MAPPINGS when MP would reach MAPPINGS+SIZE.  */
@@ -284,7 +285,11 @@ hash_table_new (int items,
   ht->resize_threshold = size * HASH_MAX_FULLNESS;
   /*assert (ht->resize_threshold >= items);*/
 
-  ht->mappings = xnew0_array (struct mapping, ht->size);
+  ht->mappings = xnew_array (struct mapping, ht->size);
+  /* Mark mappings as empty.  We use 0xff rather than 0 to mark empty
+     keys because it allows us to store NULL keys to the table.  */
+  memset (ht->mappings, 255, size * sizeof (struct mapping));
+
   ht->count = 0;
 
   return ht;
@@ -384,7 +389,10 @@ grow_hash_table (struct hash_table *ht)
 
   ht->size = newsize;
   ht->resize_threshold = newsize * HASH_MAX_FULLNESS;
-  ht->mappings = mappings = xnew0_array (struct mapping, ht->size);
+
+  mappings = xnew_array (struct mapping, newsize);
+  memset (mappings, 255, newsize * sizeof (struct mapping));
+  ht->mappings = mappings;
 
   for (mp = old_mappings; mp < old_end; mp++)
     if (NON_EMPTY (mp))