summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorMark Fisher <fisherm@tce.com>2001-02-08 05:44:00 -0500
committerNick Ing-Simmons <nik@tiuk.ti.com>2001-02-09 19:25:16 +0000
commita6fe520e69b81614f687efd2cdbfdcd1bb40e201 (patch)
treea2a37a5d596be27d5093af180a50d3555f9c5be6 /hv.h
parent682a4d6ff488c90b285372b88adbfe46b909f779 (diff)
downloadperl-a6fe520e69b81614f687efd2cdbfdcd1bb40e201.tar.gz
RE: Biannual Competition to Improve Hashing Function
Date: Thu, 8 Feb 2001 10:44:00 -0500 Message-Id: <A5E22933E3D5D4118FFE00508BF373C706A52F@indyexch28.indy.tce. Date: Thu, 8 Feb 2001 15:02:47 -0500 Message-Id: <A5E22933E3D5D4118FFE00508BF373C706A52B@indyexch28.indy.tce. p4raw-id: //depot/perl@8750
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/hv.h b/hv.h
index 5def051d72..a1652d8c58 100644
--- a/hv.h
+++ b/hv.h
@@ -43,14 +43,22 @@ struct xpvhv {
};
/* hash a key */
+/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
+/* from requirements by Colin Plumb. */
+/* (http://burtleburtle.net/bob/hash/doobs.html) */
#define PERL_HASH(hash,str,len) \
STMT_START { \
register const char *s_PeRlHaSh = str; \
register I32 i_PeRlHaSh = len; \
register U32 hash_PeRlHaSh = 0; \
- while (i_PeRlHaSh--) \
- hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \
- (hash) = hash_PeRlHaSh + (hash_PeRlHaSh>>5); \
+ while (i_PeRlHaSh--) { \
+ hash_PeRlHaSh += *s_PeRlHaSh++; \
+ hash_PeRlHaSh += (hash_PeRlHaSh << 10); \
+ hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \
+ } \
+ hash_PeRlHaSh += (hash_PeRlHaSh << 3); \
+ hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \
+ (hash) = (hash_PeRlHaSh += (hash_PeRlHaSh << 15)); \
} STMT_END
/*