]> mj.ucw.cz Git - libucw.git/blobdiff - lib/hashfunc.c
libucw: removed utf8_check routine... it did not check correct UTF-8
[libucw.git] / lib / hashfunc.c
index 10c29abd67c3cdb7be34a294adfbb20d7820ce93..8fca5f4139254cd211bd71eb9a4edb04fe4d90aa 100644 (file)
@@ -45,7 +45,7 @@ str_len_uns(uns x)
        uns a, i;
        byte *bytes;
        a = ~x & (x - sub) & and;
        uns a, i;
        byte *bytes;
        a = ~x & (x - sub) & and;
-       /* 
+       /*
         * x_2 = x - 0x01010101;
         * x_3 = ~x & x_2;
         * a = x_3 & 0x80808080;
         * x_2 = x - 0x01010101;
         * x_3 = ~x & x_2;
         * a = x_3 & 0x80808080;
@@ -64,7 +64,7 @@ str_len_uns(uns x)
 }
 
 inline uns
 }
 
 inline uns
-str_len_aligned(const byte *str)
+str_len_aligned(const char *str)
 {
        const uns *u = (const uns *) str;
        uns len = 0;
 {
        const uns *u = (const uns *) str;
        uns len = 0;
@@ -78,7 +78,7 @@ str_len_aligned(const byte *str)
 }
 
 inline uns
 }
 
 inline uns
-hash_string_aligned(const byte *str)
+hash_string_aligned(const char *str)
 {
        const uns *u = (const uns *) str;
        uns hash = 0;
 {
        const uns *u = (const uns *) str;
        uns hash = 0;
@@ -112,7 +112,7 @@ hash_block_aligned(const byte *str, uns len)
 
 #ifndef        CPU_ALLOW_UNALIGNED
 uns
 
 #ifndef        CPU_ALLOW_UNALIGNED
 uns
-str_len(const byte *str)
+str_len(const char *str)
 {
        uns shift = UNALIGNED_PART(str, uns);
        if (!shift)
 {
        uns shift = UNALIGNED_PART(str, uns);
        if (!shift)
@@ -129,11 +129,12 @@ str_len(const byte *str)
 }
 
 uns
 }
 
 uns
-hash_string(const byte *str)
+hash_string(const char *str)
 {
 {
-       uns shift = UNALIGNED_PART(str, uns);
+       const byte *s = str;
+       uns shift = UNALIGNED_PART(s, uns);
        if (!shift)
        if (!shift)
-               return hash_string_aligned(str);
+               return hash_string_aligned(s);
        else
        {
                uns hash = 0;
        else
        {
                uns hash = 0;
@@ -149,9 +150,9 @@ hash_string(const byte *str)
 #endif
                        if (!modulo)
                                hash = ROL(hash, SHIFT_BITS);
 #endif
                        if (!modulo)
                                hash = ROL(hash, SHIFT_BITS);
-                       if (!str[i])
+                       if (!s[i])
                                break;
                                break;
-                       hash ^= str[i] << (shift * 8);
+                       hash ^= s[i] << (shift * 8);
                }
                return hash;
        }
                }
                return hash;
        }
@@ -188,8 +189,9 @@ hash_block(const byte *str, uns len)
 #endif
 
 uns
 #endif
 
 uns
-hash_string_nocase(const byte *str)
+hash_string_nocase(const char *str)
 {
 {
+       const byte *s = str;
        uns hash = 0;
        uns i;
        for (i=0; ; i++)
        uns hash = 0;
        uns i;
        for (i=0; ; i++)
@@ -203,9 +205,9 @@ hash_string_nocase(const byte *str)
 #endif
                if (!modulo)
                        hash = ROL(hash, SHIFT_BITS);
 #endif
                if (!modulo)
                        hash = ROL(hash, SHIFT_BITS);
-               if (!str[i])
+               if (!s[i])
                        break;
                        break;
-               hash ^= Cupcase(str[i]) << (shift * 8);
+               hash ^= Cupcase(s[i]) << (shift * 8);
        }
        return hash;
 }
        }
        return hash;
 }