2002-07-20 Han-Wen <hanwen@cs.uu.nl>
[bpt/guile.git] / libguile / hash.c
index 5a72445..b894150 100644 (file)
@@ -39,8 +39,6 @@
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
 
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 
 \f
 
@@ -60,13 +58,13 @@ extern double floor();
 #endif
 
 
-scm_bits_t 
+unsigned long 
 scm_string_hash (const unsigned char *str, size_t len)
 {
   if (len > 5)
     {
       size_t i = 5;
-      scm_bits_t h = 264;
+      unsigned long h = 264;
       while (i--)
        h = (h << 8) + (unsigned) str[h % len];
       return h;
@@ -74,7 +72,7 @@ scm_string_hash (const unsigned char *str, size_t len)
   else
     {
       size_t i = len;
-      scm_bits_t h = 0;
+      unsigned long h = 0;
       while (i)
        h = (h << 8) + (unsigned) str[--i];
       return h;
@@ -86,8 +84,8 @@ scm_string_hash (const unsigned char *str, size_t len)
 /* Dirk:FIXME:: scm_hasher could be made static. */
 
 
-scm_bits_t
-scm_hasher (SCM obj, scm_bits_t n, size_t d)
+unsigned long
+scm_hasher(SCM obj, unsigned long n, size_t d)
 {
   switch (SCM_ITAG3 (obj)) {
   case scm_tc3_int_1: 
@@ -95,20 +93,20 @@ scm_hasher (SCM obj, scm_bits_t n, size_t d)
     return SCM_INUM(obj) % n;   /* SCM_INUMP(obj) */
   case scm_tc3_imm24:
     if (SCM_CHARP(obj))
-      return (scm_ubits_t) (scm_downcase(SCM_CHAR(obj))) % n;
+      return (unsigned)(scm_downcase(SCM_CHAR(obj))) % n;
     switch (SCM_UNPACK (obj)) {
 #ifndef SICP
-    case SCM_EOL: 
+    case SCM_UNPACK(SCM_EOL):
       d = 256; 
       break;
 #endif
-    case SCM_BOOL_T: 
+    case SCM_UNPACK(SCM_BOOL_T):
       d = 257; 
       break;
-    case SCM_BOOL_F: 
+    case SCM_UNPACK(SCM_BOOL_F):
       d = 258; 
       break;
-    case SCM_EOF_VAL: 
+    case SCM_UNPACK(SCM_EOF_VAL):
       d = 259; 
       break;
     default: 
@@ -140,7 +138,6 @@ scm_hasher (SCM obj, scm_bits_t n, size_t d)
        obj = scm_number_to_string (obj, SCM_MAKINUM (10));
       }
     case scm_tc7_string:
-    case scm_tc7_substring:
       return scm_string_hash (SCM_STRING_UCHARS (obj), SCM_STRING_LENGTH (obj)) % n;
     case scm_tc7_symbol:
       return SCM_SYMBOL_HASH (obj) % n;
@@ -148,18 +145,18 @@ scm_hasher (SCM obj, scm_bits_t n, size_t d)
     case scm_tc7_vector:
       {
        size_t len = SCM_VECTOR_LENGTH(obj);
-       SCM *data = SCM_VELTS(obj);
+       SCM const *data = SCM_VELTS(obj);
        if (len > 5)
          {
            size_t i = d/2;
-           scm_bits_t h = 1;
+           unsigned long h = 1;
            while (i--) h = ((h << 8) + (scm_hasher (data[h % len], n, 2))) % n;
            return h;
          }
        else
          {
            size_t i = len;
-           scm_bits_t h = (n)-1;
+           unsigned long h = (n)-1;
            while (i--) h = ((h << 8) + (scm_hasher (data[i], n, d/len))) % n;
            return h;
          }
@@ -182,8 +179,8 @@ scm_hasher (SCM obj, scm_bits_t n, size_t d)
 \f
 
 
-scm_bits_t
-scm_ihashq (SCM obj, scm_bits_t n)
+unsigned long
+scm_ihashq (SCM obj, unsigned long n)
 {
   return (SCM_UNPACK (obj) >> 1) % n;
 }
@@ -212,14 +209,14 @@ SCM_DEFINE (scm_hashq, "hashq", 2, 0, 0,
 \f
 
 
-scm_bits_t
-scm_ihashv (SCM obj, scm_bits_t n)
+unsigned long
+scm_ihashv (SCM obj, unsigned long n)
 {
   if (SCM_CHARP(obj))
-    return ((scm_ubits_t)(scm_downcase(SCM_CHAR(obj)))) % n; /* downcase!?!! */
+    return ((unsigned long) (scm_downcase (SCM_CHAR (obj)))) % n; /* downcase!?!! */
 
   if (SCM_NUMP(obj))
-    return (scm_bits_t) scm_hasher(obj, n, 10);
+    return (unsigned long) scm_hasher(obj, n, 10);
   else
     return SCM_UNPACK (obj) % n;
 }
@@ -248,10 +245,10 @@ SCM_DEFINE (scm_hashv, "hashv", 2, 0, 0,
 \f
 
 
-scm_bits_t
-scm_ihash (SCM obj, scm_bits_t n)
+unsigned long
+scm_ihash (SCM obj, unsigned long n)
 {
-  return (scm_bits_t) scm_hasher (obj, n, 10);
+  return (unsigned long) scm_hasher (obj, n, 10);
 }
 
 SCM_DEFINE (scm_hash, "hash", 2, 0, 0,
@@ -274,9 +271,7 @@ SCM_DEFINE (scm_hash, "hash", 2, 0, 0,
 void
 scm_init_hash ()
 {
-#ifndef SCM_MAGIC_SNARFER
 #include "libguile/hash.x"
-#endif
 }