]> sjero.net Git - wget/blobdiff - src/hash.c
[svn] Remove warnings under Borland C.
[wget] / src / hash.c
index af5cf7a2c20338d1483e16fc7b126400d8695d3c..195e23eaeb4e36b22a362882d4cb09e688f2956e 100644 (file)
@@ -27,39 +27,48 @@ modify this file, you may extend this exception to your version of the
 file, but you are not obligated to do so.  If you do not wish to do
 so, delete this exception statement from your version.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+/* With -DSTANDALONE, this file can be compiled outside Wget source
+   tree.  To test, also use -DTEST.  */
 
-#ifdef HAVE_STRING_H
-# include <string.h>
+#ifndef STANDALONE
+# include <config.h>
+# ifdef HAVE_STRING_H
+#  include <string.h>
+# else
+#  include <strings.h>
+# endif
+# ifdef HAVE_LIMITS_H
+#  include <limits.h>
+# endif
 #else
-# include <strings.h>
-#endif
-#ifdef HAVE_LIMITS_H
+/* If running without Autoconf, go ahead and assume presence of
+   standard C89 headers.  */
+# include <string.h>
 # include <limits.h>
 #endif
+
+#include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 
-#include "wget.h"
-#include "utils.h"
-
-#include "hash.h"
-
-#ifdef STANDALONE
-# undef xmalloc
-# undef xrealloc
-# undef xfree
-
-# define xmalloc malloc
-# define xrealloc realloc
+#ifndef STANDALONE
+/* Get Wget's utility headers. */
+# include "wget.h"
+# include "utils.h"
+#else
+/* Make do without them. */
+# define xnew(x) xmalloc (sizeof (x))
+# define xnew_array(type, x) xmalloc (sizeof (type) * (x))
+# define xmalloc malloc                /* or something that exits
+                                  if not enough memory */
 # define xfree free
-
-# undef TOLOWER
+# define countof(x) (sizeof (x) / sizeof ((x)[0]))
 # define TOLOWER(x) ('A' <= (x) && (x) <= 'Z' ? (x) - 32 : (x))
+# define PARAMS(x) x
 #endif
 
+#include "hash.h"
+
 /* INTERFACE:
 
    Hash tables are a technique used to implement mapping between
@@ -106,14 +115,13 @@ so, delete this exception statement from your version.  */
    The hash table is implemented as an open-addressed table with
    linear probing collision resolution.
 
-   In regular language, it means that all the hash entries (pairs of
-   pointers key and value) are stored in a contiguous array.  The
-   position of each mapping is determined by the hash value of its key
-   and the size of the table: location := hash(key) % size.  If two
-   different keys end up on the same position (collide), the one that
-   came second is placed at the next empty position following the
-   occupied place.  This collision resolution technique is called
-   "linear probing".
+   The above means that all the hash entries (pairs of pointers, key
+   and value) are stored in a contiguous array.  The position of each
+   mapping is determined by the hash value of its key and the size of
+   the table: location := hash(key) % size.  If two different keys end
+   up on the same position (collide), the one that came second is
+   placed at the next empty position following the occupied place.
+   This collision resolution technique is called "linear probing".
 
    There are more advanced collision resolution methods (quadratic
    probing, double hashing), but we don't use them because they incur
@@ -287,6 +295,7 @@ hash_table_new (int items,
   /*assert (ht->resize_threshold >= items);*/
 
   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 use NULL/0 as keys.  */
   memset (ht->mappings, INVALID_PTR_BYTE, size * sizeof (struct mapping));
@@ -693,7 +702,7 @@ ptrcmp (const void *ptr1, const void *ptr2)
   return ptr1 == ptr2;
 }
 \f
-#ifdef STANDALONE
+#ifdef TEST
 
 #include <stdio.h>
 #include <string.h>
@@ -747,4 +756,4 @@ main (void)
 #endif
   return 0;
 }
-#endif
+#endif /* TEST */