2011/12/5 Stuart Sierra <the.stuart.sie...@gmail.com>

> >  (side note: what is different between Long/MAX_VALUE and the
> > function call (Long/MAX_VALUE)?
>
> None. Both are syntax sugar for (. Long MAX_VALUE)
>
>
> > It seems like unchecked-multiply doesn't like vars, but thats surprising.
> > What am I doing wrong here?
>
> unchecked-multiply only does unchecked arithmetic when the arguments are
> primitive. Vars cannot have primitive values, they must be boxed as
> java.lang.Long. So it reverts to normal Clojure arithmetic.
>
> The unchecked-* functions are intended as a performance optimization when
> doing operations with primitives.


OK, then the problem seems to be to refer to primitives with symbols with
unchecked-* functions. How do I do that?

The loop where high performance is required is

hash = -3750763034362895579
for each byte b in array-of-bytes-to-be-hashed do :
    hash = hash * 1099511628211 (without caring about overflowing)
    hash = hash ^ byte
return hash

and I really cannot see how to do this without using something that hold
values somehow, but how do I bypass the numeric stack in clojure?

I have tried with the following approach (just for the first step):

fnv> (def hash (Long. -3750763034362895579))
#'fnv/hash
fnv> (def hash2 (Long. (unchecked-multiply hash 1099511628211)))
; Evaluation aborted. (because of integer overflow)

How should I do to get it working correctly? There simply must be a way to
store primitives, but I'm apparently have gotten something wrong here.

(the hash in question is the quite quick FNV-hash, which is in public
domain, nice and everything)

/Linus

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to