Skip to content

Commit

Permalink
Fix typos and some wording
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothNET committed Nov 22, 2024
1 parent d14c435 commit f32a1bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ By providing both `Ulid` and `ZeroableUlid` types, it serves different applicati

- **Robust**: Generates ULIDs that are unique and strictly monotonically increasing under all circumstances, including threads, no failing, and no overflowing random part. See below for [Details](#Guarantees).
- **Hassle-Free**: Simple API for easy usage. Customize entropy source when needed.
- **Non-Zero ULIDs**: Provides both non-zero (`Ulid`) and zeroable (`ZeroableUlid`) types to suit different use cases.
- **Non-Zero ULIDs**: Provides non-zero (`Ulid`) and zeroable (`ZeroableUlid`) types.
- **Minimal Dependencies**: Actually no dependencies required, only `rand` enabled by default as Rust lacks a built-in random number generator.
- **Optional Features**: Supports `serde` for serialization and deserialization.

## Guarantees

A notable feature of this crate is the guarantee that a sufficient number of ULIDs can be generated at any time without failing or the random part overflowing.
A notable guarantee of this crate is that a sufficient number of ULIDs can be generated at any time without failing or the random part overflowing.

The 80-bit random component of a ULID is slightly reduced by 10<sup>10</sup> values, resulting in a negligible reduction in entropy of approximately 0.000000000001%. This ensures that at least 10<sup>10</sup> ULIDs can be generated per _millisecond_, equating to 10<sup>13</sup> ULIDs per _second_. Such capacity exceeds the capabilities of current systems by magnitudes.

Expand All @@ -33,8 +33,6 @@ Add `mr-ulid` to your `Cargo.toml`:
mr-ulid = "1"
```

By default, the `rand` feature is enabled.

## Quickstart

```rust
Expand Down
10 changes: 5 additions & 5 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub const fn from_parts(timestamp: u64, randomness: u128) -> Result<u128, Error>
if timestamp > TIMESTAMP_MAX {
Err(Error::TimestampOutOfRange)
} else if randomness > RANDOM_MASK {
Err(Error::RandomnessOutOfRange)
} else {
Err(Error::RandomnessOutOfRange)
} else {
let shifted_timestamp = (timestamp as u128) << RANDOM_BITS;
Ok(shifted_timestamp | randomness)
Ok(shifted_timestamp | randomness)
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ fn timestamp_to_string(millis: u64) -> String {

const DAYS_PER_QUAD_YEAR: u64 = 4 * DAYS_PER_YEAR + 1; // leap year: every 4 years,
const DAYS_PER_CENTURY: u64 = 25 * DAYS_PER_QUAD_YEAR - 1; // but not every 100 years,
const DASS_PER_QUADRICENTENNIAL: u64 = 4 * DAYS_PER_CENTURY + 1; // but again every 400 years.
const DAYS_PER_QUADRICENTENNIAL: u64 = 4 * DAYS_PER_CENTURY + 1; // but again every 400 years.

const BASE: u64 = 1600;
const DAYS_BASE_TO_1970: u64 = 3 * DAYS_PER_CENTURY + 1 + 70 * DAYS_PER_YEAR + 70 / 4;
Expand All @@ -80,7 +80,7 @@ fn timestamp_to_string(millis: u64) -> String {
// days relative to year 1600
let days = days + DAYS_BASE_TO_1970;

let (quadricentennials, days) = (days / DASS_PER_QUADRICENTENNIAL, days % DASS_PER_QUADRICENTENNIAL);
let (quadricentennials, days) = (days / DAYS_PER_QUADRICENTENNIAL, days % DAYS_PER_QUADRICENTENNIAL);
let (centuries, days) = (days / DAYS_PER_CENTURY, days % DAYS_PER_CENTURY);
let (quad_years, days) = (days / DAYS_PER_QUAD_YEAR, days % DAYS_PER_QUAD_YEAR);

Expand Down

0 comments on commit f32a1bc

Please sign in to comment.