Date: Sun Apr 14 23:41:04 CEST 2002
User: Sterling Hughes
Directory: srm/main/src
Log Message:
[0.30]
- Speed up key comparison for strings and improve string hashing
algorithm as well.
Modified files:
srm/main/src/srm_hash.c (version: 1.33)
[FILE: /srm/main/src/srm_hash.c]
--- srm/main/src/srm_hash.c:1.32 Sun Feb 10 18:54:27 2002 GMT
+++ srm/main/src/srm_hash.c Sun Apr 14 19:41:03 2002 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.32 2002/02/10 19:54:27 sterling Exp $ */
+/* $Id: cvstemp,v 1.33 2002/04/14 21:41:03 sterling Exp $ */
/* The contents of this file are subject to the Vulcan Logic Public
* License Version 1.1 (the "License"); you may not use this file
@@ -43,18 +43,17 @@
return tmp;
}
-static srm_ui32 srm_hash_str(char *key, unsigned int key_length)
+static srm_ui32 srm_hash_str(const char *key, unsigned int key_length)
{
- srm_ui32 h = 0, g;
- char *end = key + key_length;
-
- while (key < end) {
- h = (h << 4) + *key++;
- if ((g = (h & 0xF0000000))) {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
+ char *p = (char *) key;
+ char *end = (char *) key + key_length;
+ unsigned long h = 5381;
+
+ while (p < end) {
+ h += h << 5;
+ h ^= (unsigned long) *p++;
}
+
return h;
}
@@ -120,8 +119,6 @@
(__k)->type = SRM_HASH_KEY_IS_NUM; \
}
-#define MIN(a, b) (a > b ? b : a)
-
static int srm_hash_key_compare(srm_hash_key *key1, srm_hash_key *key2)
{
if (key1->type == SRM_HASH_KEY_IS_NUM) {
@@ -134,8 +131,11 @@
if (key2->type == SRM_HASH_KEY_IS_NUM)
return 0;
- if (memcmp(key1->value.str.val, key2->value.str.val, MIN(key1->value.str.len, key2->value.str.len)) == 0)
+ if (key1->value.str.len == key2->value.str.len &&
+ *key1->value.str.val == *key2->value.str.val &&
+ memcmp(key1->value.str.val, key2->value.str.val, key1->value.str.len) == 0) {
return 1;
+ }
}
return 0;
Received on Mon Apr 15 00:38:06 2002
This archive was generated by hypermail 2.1.8 : Tue Jan 06 2009 - 06:00:02 CET