Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn stack-hash
- "Creates a hash of in which fits in size with minimal rehashing given various sizes. Optional n argument can be specified if it has been precomputed"
- [in size]
- (let [n (Math/ceil (/ (Math/log size) (Math/log 2)))
- Hv (loop [i 0
- h 0]
- (if (> (count in) i)
- (recur (+ i 1)
- (mod (+ (* h 31) (int (.charAt in i))) Integer/MAX_VALUE))
- h))
- mask (int (- (Math/pow 2 n) 1))
- first-four (bit-and Hv mask)]
- (if (<= first-four size)
- first-four
- (stack-hash (str first-four)))
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement