huxi / rusty_ulid Goto Github PK
View Code? Open in Web Editor NEWRust ULID (Universally Unique Lexicographically Sortable Identifier) generation and processing
Home Page: https://crates.io/crates/rusty_ulid
License: Apache License 2.0
Rust ULID (Universally Unique Lexicographically Sortable Identifier) generation and processing
Home Page: https://crates.io/crates/rusty_ulid
License: Apache License 2.0
Can I ask you what's the difference between this and https://github.com/dylanhart/ulid-rs?
Thanks for creating such a great utility. I love how well organized and especially well documented it is.
Would there be interest in an API for this which provides a next_monotonic but does so using a thread-safe context and the value is updated atomically? I understand that this might be a major departure from the scope of this crate, which is why I'm asking. I'm happy to make the enhancements, but only if you are interested in such a scope change/increase.
If so, here's my thoughts:
fn threadsafe_next_monotonic(ctx: Arc<UlidContext>) -> Option<Ulid> {
let mut next = unix_epoch_ms() << 12;
let mut current = ctx.0.load(Ordering::Acquire);
let mut counter = current >> 48;
while next != ctx.0.compare_and_swap(current, next, Ordering::Acquire) {
current = ctx.0.load(Ordering::Acquire);
next = current + 1;
}
return ulid_with_context_and_rng(ctx, &mut rand::thread_rng());
}
This isn't correct code, and I'm sure the algo could be made to be safer and more efficient.
That's the basic idea, though.
It would be a bit slower than the non-threaded version, but, that is usually the case.
Edit : Man I really typo'd the crap out of this post. I need to get more sleep
Thank you for your work on this library.
Would you have any feedback on the performance difference in Postgres DB for primary key on a table with 1 million records for read, write sorting between:
BIGINT
UUID v7
ULID
Particularly on multiple table join queries with either of above as PK and FK
Ulid should implement Serde's Serialize and Deserialize as an optional feature.
This will enhance the library's interoperability per Rust API Guidelines: Data structures implement Serde's Serialize and Deserialize
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.