cvs: php4 /ext/session mod_mm.c

From: Date: Wed, 18 Jul 2001 21:39:02 +0000
Subject: cvs: php4 /ext/session mod_mm.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6257@lists.php.net to get a copy of this message
sas Wed Jul 18 17:39:02 2001 EDT Modified files: /php4/ext/session mod_mm.c Log: Retire old hash algorithm and use the FNV-1 algorithm. Index: php4/ext/session/mod_mm.c diff -u php4/ext/session/mod_mm.c:1.19 php4/ext/session/mod_mm.c:1.20 --- php4/ext/session/mod_mm.c:1.19 Sun Jun 24 18:18:51 2001 +++ php4/ext/session/mod_mm.c Wed Jul 18 17:39:02 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mod_mm.c,v 1.19 2001/06/24 22:18:51 sniper Exp $ */ +/* $Id: mod_mm.c,v 1.20 2001/07/18 21:39:02 sas Exp $ */ #include "php.h" @@ -61,33 +61,26 @@ #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;

« previous php.cvs (#6257) next »