Code Monkey home page Code Monkey logo

Comments (5)

dylanhart avatar dylanhart commented on May 31, 2024 1

ulids are 128-bit identifiers, so the maximum value of u128 is the same as the maximum value of a Ulid. This library implements the From conversion trait to and from u128.

from ulid-rs.

dylanhart avatar dylanhart commented on May 31, 2024

Those constants don't really look like they would be that helpful since they are just 0 or (1 << N) - 1 where N is the bit-width of the field in question. This library does have those N values but they are not currently public. That being said, the python constants don't really solve much of the problem since you would still need to do your own bit-math for range queries.

I think that we should instead design an API that returns std::ops::Range or something similar. Can you explain your use-case some more so that we can come up with an interface that works well?

from ulid-rs.

rakanalh avatar rakanalh commented on May 31, 2024

Hi @dylanhart,

Sure... basically i am storing records in sqlite where the identifiers are ULIDs. By range queries, i meant that i would like to query a certain table whose identifier is a ULID with identifier BETWEEN X and Y or identifier <= {max_ulid_identifier}.

This is why i think the constants might be useful if you want to get records with identifiers greater or smaller than min/max ULIDs respectively.

Would you say that:

use chrono::{MAX_DATETIME, MIN_DATETIME};
use ulid:: Generator;

let mut generator = Generator::new();
let max_ulid = generator.generate_from_datetime(MAX_DATETIME).unwrap();
let min_ulid = generator.generate_from_datetime(MIN_DATETIME).unwrap();

would properly calculate the min and max values?

from ulid-rs.

dylanhart avatar dylanhart commented on May 31, 2024

In that case you can use u128::MAX for now. The min/max datetime would not work at all, so a new API could be added to get ulid value sub-ranges for date ranges along with ulid-specific min/max datetime.

from ulid-rs.

rakanalh avatar rakanalh commented on May 31, 2024

I see... could you elaborate on using u128::MAX please? Do you mean that i could use u128::MAX to generate a ULID?

from ulid-rs.

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.