improve hash mixing
original commit: d7469cedd67a950931a561ce14388fe7e628770d
This commit is contained in:
parent
77e84faa24
commit
ffc02a9877
15
c/intern.c
15
c/intern.c
|
@ -188,19 +188,18 @@ void S_resize_oblist(void) {
|
||||||
S_G.oblist = new_oblist;
|
S_G.oblist = new_oblist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hash function: multiplier weights each character, h = n factors in the length */
|
#define MIX_HASH(hc) (hc += (hc << 10), hc ^= (hc >> 6))
|
||||||
#define multiplier 3
|
|
||||||
|
|
||||||
static iptr hash(const unsigned char *s, iptr n) {
|
static iptr hash(const unsigned char *s, iptr n) {
|
||||||
iptr h = n + 401887359;
|
uptr h = (uptr)n + 401887359;
|
||||||
while (n--) h = h * multiplier + *s++;
|
while (n--) { h += *s++; MIX_HASH(h); }
|
||||||
return h & most_positive_fixnum;
|
return (iptr)h & most_positive_fixnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static iptr hash_sc(const string_char *s, iptr n) {
|
static iptr hash_sc(const string_char *s, iptr n) {
|
||||||
iptr h = n + 401887359;
|
uptr h = (uptr)n + 401887359;
|
||||||
while (n--) h = h * multiplier + Schar_value(*s++);
|
while (n--) { h += Schar_value(*s++); MIX_HASH(h); }
|
||||||
return h & most_positive_fixnum;
|
return (iptr)h & most_positive_fixnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static iptr hash_uname(const string_char *s, iptr n) {
|
static iptr hash_uname(const string_char *s, iptr n) {
|
||||||
|
|
|
@ -920,7 +920,8 @@ Documentation notes:
|
||||||
(define (hcabs hc) (if (fx< hc 0) (fxnot hc) hc))
|
(define (hcabs hc) (if (fx< hc 0) (fxnot hc) hc))
|
||||||
|
|
||||||
(define (update hc k)
|
(define (update hc k)
|
||||||
(fxlogxor (#3%fx+ (#3%fxsll hc 2) hc) k))
|
(let ([hc2 (#3%fx+ hc (#3%fxsll (#3%fx+ hc k) 10))])
|
||||||
|
(fxlogxor hc2 (fxsrl hc2 6))))
|
||||||
|
|
||||||
(define bytevector-hash
|
(define bytevector-hash
|
||||||
(lambda (bv)
|
(lambda (bv)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user