Comments (8)
Hi @frikishaan !
This is my solution:
const enc = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
function rev(ulid) { return [...ulid].map(x => enc[31 - enc.indexOf(x)]).join(''); }
// Test!
const ulid1 = '01ARZ3NDEKTSV4RRFFQ69G5FAV';
const ulid2 = '01ARYZ6S41TSV4RRFFQ69G5FAV';
console.log(ulid1 > ulid2); // => true
console.log(rev(ulid1) < rev(ulid2)); // => true
from javascript.
have you tested it in production?
No.
is it collision free?
Yes, the probability of collision for "descending ULIDs" is the same as that of the original ULIDs because rev
function is bijective.
You can convert a "descending ULID" back to the original ULID by applying the rev
function once more.
from javascript.
Would reversing the lexicographical sort (with positive timestamps) work for you? If not, then I don't exactly understand your problem. Before making changes to handle negative timestamps, I'd like to understand what you're trying to do.
from javascript.
Reversing the lexicographic sort does solve the problem. I basically needed a way to create "descending" ulids
from javascript.
What is the problem you are trying to solve by using negative timestamps?
from javascript.
@thdxr, I'm assuming your problem has been solved, and closing this issue. Feel free to open it up again if things don't work for you!
from javascript.
@thdxr Were you able to solve the problem? Would you mind sharing the solution here?
from javascript.
Hi @gkkachi,
Thanks, have you tested it in production, is it collision free?
from javascript.
Related Issues (20)
- isUlid
- dist _index.js#L59
- License violation HOT 20
- Where is ulid.js HOT 3
- Support for RFC 4648 base32? HOT 2
- First and Last IDs for Timestamp HOT 4
- Is there a way to get the timestamp from a given ULID? HOT 3
- PRNG inconsistency HOT 1
- Crypto API isn't detected on alternative platforms HOT 5
- Monotonically Increasing Guarantee
- is_ulid(x) HOT 3
- Generate time from shortened ulid?
- Random bias?
- Not available in web workers
- Maintainers HOT 4
- Please Upgrade Your Package HOT 1
- Error in worker HOT 2
- issue 1
- issue2
- Decoding ULID string into bytes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javascript.