Giter VIP home page Giter VIP logo

Comments (8)

gkkachi avatar gkkachi commented on July 17, 2024 2

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.

gkkachi avatar gkkachi commented on July 17, 2024 1

@frikishaan

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.

alizain avatar alizain commented on July 17, 2024

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.

thdxr avatar thdxr commented on July 17, 2024

Reversing the lexicographic sort does solve the problem. I basically needed a way to create "descending" ulids

from javascript.

tuupola avatar tuupola commented on July 17, 2024

What is the problem you are trying to solve by using negative timestamps?

from javascript.

alizain avatar alizain commented on July 17, 2024

@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.

frikishaan avatar frikishaan commented on July 17, 2024

@thdxr Were you able to solve the problem? Would you mind sharing the solution here?

from javascript.

frikishaan avatar frikishaan commented on July 17, 2024

Hi @gkkachi,
Thanks, have you tested it in production, is it collision free?

from javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.