Advertisement
Guest User

Untitled

a guest
Nov 6th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn stack-hash
  2.     "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"
  3.     [in size]
  4.     (let [n (Math/ceil (/ (Math/log size) (Math/log 2)))
  5.           Hv (loop [i 0
  6.                 h 0]
  7.                 (if (> (count in) i)
  8.                     (recur  (+ i 1)
  9.                         (mod (+ (* h 31) (int (.charAt in i))) Integer/MAX_VALUE))
  10.                 h))
  11.           mask (int (- (Math/pow 2 n) 1))
  12.           first-four (bit-and Hv mask)]
  13.         (if (<= first-four size)
  14.             first-four
  15.             (stack-hash (str first-four)))
  16.     ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement