cvs: php4 /ext/ircg ircg.c
| From: | Sascha Schumann | Date: | Fri, 20 Jul 2001 02:26:09 +0000 |
| Subject: | cvs: php4 /ext/ircg ircg.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-6275@lists.php.net to get a copy of this message | ||
sas Thu Jul 19 22:26:09 2001 EDT
Modified files:
/php4/ext/ircg ircg.c
Log:
Retire a hash function and use FNV-1
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.84 php4/ext/ircg/ircg.c:1.85
--- php4/ext/ircg/ircg.c:1.84 Tue Jul 17 22:03:02 2001
+++ php4/ext/ircg/ircg.c Thu Jul 19 22:26:09 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: ircg.c,v 1.84 2001/07/18 02:03:02 sas Exp $ */
+/* $Id: ircg.c,v 1.85 2001/07/20 02:26:09 sas Exp $ */
#include <time.h>
@@ -31,10 +31,7 @@
#include "ext/standard/php_smart_str.h"
#include "ext/standard/info.h"
-
-/* If you declare any globals in php_ircg.h uncomment this:
-ZEND_DECLARE_MODULE_GLOBALS(ircg)
-*/
+#include "ext/standard/basic_functions.h"
/* This module is not intended for thread-safe use */
@@ -352,38 +349,17 @@
smart_str result;
} static cache_entries[NR_CACHE_ENTRIES];
-#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))
-
-/*
- * Weinberger's generic hash algorithm, adapted by Holub
- * (published in [Holub 1990])
- */
-
-static inline unsigned int ghash(smart_str *str)
+static inline php_uint32 ghash(smart_str *str)
{
- const char *data = str->c;
- unsigned int val, i;
- int l = str->len;
-#if 1
- for (val = 0; l-- > 0; data++) {
- val = (val << ONE_EIGTH) + *data;
- if ((i = val & HIGH_BITS) != 0)
- val = (val ^ (i >> THREE_QUARTERS)) & ~HIGH_BITS;
- }
-#else
- for (val = 0; l-- > 0; ) {
- val = (val << 4) + *data++;
- if ((i = val & 0xF0000000)) {
- val = val ^ (i >> 24);
- val = val ^ i;
- }
+ php_uint32 h;
+ const char *data = str->c, *e = str->c + str->len;
+
+ for (h = 2166136261U; data < e; ) {
+ h *= 16777619;
+ h ^= *data++;
}
-#endif
- return val;
+ return h;
}
/* {{{ ircg_mirc_color_cache