From 91246c14713eeac170b8ad4db9520b58ee4746d9 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 18 Jul 2014 22:28:32 -0700 Subject: [PATCH] Mildly improved (?) quasi-hash for deterministic treap construction --- minimart/treap.rkt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/minimart/treap.rkt b/minimart/treap.rkt index 687ef7f..388ecfd 100644 --- a/minimart/treap.rkt +++ b/minimart/treap.rkt @@ -64,8 +64,20 @@ (define (treap-empty? t) (zero? (treap-size t))) (define (default-priority key) - (bitwise-xor 609512461 ;; a random number - (equal-hash-code key))) + ;; Loosely based on a restriction of murmur32 v3 + (define c1 #xcc9e2d51) + (define c2 #x1b873593) + (define r1 15) + (define r2 13) + (define m 5) + (define n #xe6546b64) + (define k (* (equal-hash-code key) c1)) + (define hash0 (* c2 (bitwise-ior (arithmetic-shift k r1) (arithmetic-shift k (- 32 r1))))) + (define hash1 + (+ n (* m (bitwise-ior (arithmetic-shift hash0 r2) (arithmetic-shift hash0 (- 32 r2)))))) + (define hash2 (* #x85ebca6b (bitwise-xor hash1 (arithmetic-shift hash1 -16)))) + (define hash3 (* #xc2b2ae35 (bitwise-xor hash2 (arithmetic-shift hash1 -13)))) + (bitwise-xor hash2 (arithmetic-shift hash1 -16))) (define (treap-insert t key value [priority (default-priority key)]) (match-define (treap order root oldsize) t)