maxcountryman / flake Goto Github PK
View Code? Open in Web Editor NEWDecentralized, k-ordered unique IDs in Clojure
License: BSD 3-Clause "New" or "Revised" License
Decentralized, k-ordered unique IDs in Clojure
License: BSD 3-Clause "New" or "Revised" License
The alphabet order is incorrect for proper sorting.
Current:
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Should be:
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
When base-encoding the bigint:
Since the "left" 64 bits are using milliseconds since epoch, and are technically allowed to go up to a value of (Long/MAX_VALUE), and also go down to zero, the character count of the final encoded bigint value can be as many as 22, but also much lower (if I've interpreted the source correctly).
Assuming the goal is always ensuring proper sort order, the value needs to left-padded with "0"s to the max character length (22 if I'm not mistaken).
Great library, and I know this is a port, but I'd like to see support for 100-nanosecond precision (where available). I noticed you are utilizing nanoTime now.
I don't know the rationale of having the MAC/machine ID in the middle, but this would seem to provide ordering with more precision: [millis-timestamp:64][100nano+sequence:16][MAC:48]
You could provide up to 100 nano precision with the same bits (consistent with UUID-1)... and where the precision lacks the sequence is used to fill in any remaining bits.
Any thoughts?
While it is very unlikely to happen, if 65,535 flakes are generated in a millisecond, then an exception will be thrown. Would it be better to check this and wait until the start of the next millisecond to generate the next flake?
I'm not 100% sure this is even an issue, if the caller is aware that this may throw an exception then they could prepare for it and catch it to retry.
(PartialFlake. (System/currentTimeMillis) (p/inc (Short/MAX_VALUE)))
IllegalArgumentException Value out of range for short: 32768 clojure.lang.RT.shortCast (RT.java:1040)
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.