]> granicus.if.org Git - php/commitdiff
Retire old hash algorithm and use the FNV-1 algorithm.
authorSascha Schumann <sas@php.net>
Wed, 18 Jul 2001 21:39:02 +0000 (21:39 +0000)
committerSascha Schumann <sas@php.net>
Wed, 18 Jul 2001 21:39:02 +0000 (21:39 +0000)
ext/session/mod_mm.c

index f580d785ad14d3ca51dbbe1f9c147293ced16f90..3506a666217bc0159c3d90e9ab0fd5c861054d48 100644 (file)
@@ -61,33 +61,26 @@ static ps_mm *ps_mm_instance = NULL;
 #define ps_mm_debug
 #endif
 
-#define BITS_IN_int (sizeof(int) * CHAR_BIT)
-#define THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4))
-#define ONE_EIGTH ((int) (BITS_IN_int / 8))
-#define HIGH_BITS (~((unsigned int)(~0) >> ONE_EIGTH))
+/* For php_uint32 */
+#include "ext/standard/basic_functions.h"
 
-/*
- * Weinberger's generic hash algorithm, adapted by Holub
- * (published in [Holub 1990])
- */
-
-static unsigned int ps_sd_hash(const char *data)
+static php_uint32 ps_sd_hash(const char *data)
 {
-       unsigned int val, i;
+       php_uint32 h;
+       char c;
        
-       for (val = 0; *data; data++) {
-               val = (val << ONE_EIGTH) + *data;
-               if ((i = val & HIGH_BITS) != 0)
-                       val = (val ^ (i >> THREE_QUARTERS)) & ~HIGH_BITS;
+       for (h = 2166136261; (c = *data++); ) {
+               h *= 16777619;
+               h ^= c;
        }
        
-       return val;
+       return h;
 }
-
+       
 
 static ps_sd *ps_sd_new(ps_mm *data, const char *key, const void *sdata, size_t sdatalen)
 {
-       unsigned int h;
+       php_uint32 h;
        ps_sd *sd;
 
        h = ps_sd_hash(key) % HASH_SIZE;