michaelklishin / chash Goto Github PK
View Code? Open in Web Editor NEWA yet another consistent hashing library for Clojure
A yet another consistent hashing library for Clojure
This code in clojurewerkz.chash.ring:
(def ^{:const true :tag long}
ring-top (dec (Math/pow 2 160)))
(defn ^long ring-increment
[^long n](quot ring-top n))
The first problem is that ^long before the name ring-increment does not make a function return a primitive long. It just puts useless metadata on the var and the function returns Object. That might be a bug in Clojure, I'm not sure.
The way to declare a primitive return type is to put the ^long type hint just before the vector of args. However, if you do that, then the compiler correctly throws an exception that ring-top is a double, not a long. Looking at the code, you try to put a long :tag on ring-top, but that cannot work, because the value is way too big to fit in a long.
I am not sure what the correct code should be, but probably something where ring-top is calculated using BigInteger methods would be better, then converting the result to bigint. Then perhaps move the return type hint for ring-increment, and coerce the bigint return value of quot to long using (long (quot ring-top n))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.