Skip to content

Commit 8dd6805

Browse files
committed
comment and tweak the strashCode
This is the result of experiments where we instrumented C to keep track of the number of collisions. See comments in diff for the results/rational.
1 parent 3a1a4d9 commit 8dd6805

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

logic/c.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ func (p *C) grow() {
375375
p.strash = strash
376376
}
377377

378+
// this is sortof fnv-1a, but we do not do it byte wise
379+
// instead lit-wise (which is 4x wider) and there is no offset.
380+
// It gives the fewest collisions of the hashes we tried.
381+
//
382+
// A close 2nd was b * ^(a<<13), as a is smaller than b
383+
// we have fewer/cheaper operations and only marginally
384+
// more collisions. It was actually faster than the above,
385+
// the increase of collisions was compensated for by
386+
// faster computation (less multiplies).
378387
func strashCode(a, b z.Lit) uint32 {
379-
return uint32(^(a << 13) * b)
388+
return 16777619 * ^uint32(b) * 16777619 * ^uint32(a)
380389
}

0 commit comments

Comments
 (0)