pub struct SequenceId { /* private fields */ }Expand description
A hierarchical sequence identifier that exists within a shared universe.
SequenceIds form a collision-free universe where each ID is represented as a vector
of indices (e.g., [0, 1, 2]). The API design prevents collisions by only allowing
new IDs to be created through controlled advancement or descent operations.
§Hierarchy and Ordering
IDs are hierarchical and lexicographically ordered:
[0]<[0, 0]<[0, 1]<[1]<[1, 0]- A parent ID like
[0, 1]can spawn children[0, 1, 0],[0, 1, 1], etc. - Sibling IDs are created by advancing:
[0, 0]→[0, 1]→[0, 2]
§Drop Ordering
When a SequenceId is dropped, it may wake futures waiting for ordering guarantees.
The collapse() method leverages this to provide deterministic ordering of
recursively created sequence IDs.
Implementations§
Source§impl SequenceId
impl SequenceId
Sourcepub fn root() -> SequencePointer
pub fn root() -> SequencePointer
Creates a new root sequence universe starting with ID [0].
Each call to root() creates an independent universe with no ordering
guarantees between separate root instances. Within a single universe,
all IDs are strictly ordered.
Sourcepub fn descend(self) -> SequencePointer
pub fn descend(self) -> SequencePointer
Creates a child sequence by descending one level in the hierarchy.
If this SequenceId has ID [1, 2], this method creates the first child
[1, 2, 0] and returns a SequencePointer that can generate siblings
[1, 2, 1], [1, 2, 2], etc.
§Ownership
This method consumes self, as the parent ID is no longer needed once
we’ve descended to work with its children.
Sourcepub async fn collapse(self) -> SegmentId
pub async fn collapse(self) -> SegmentId
Waits until all SequenceIds with IDs lexicographically smaller than this one are dropped.
This async method provides ordering guarantees by ensuring all “prior” sequences in the universe have been dropped before returning. Combined with the collision-free API, this guarantees that for this universe no sequences lexicographically smaller than this one will ever be created again.
§Ordering Guarantee
Once collapse() returns, you can be certain that:
- All sequences with smaller IDs have been dropped
- No new sequences with smaller IDs can ever be created (due to collision prevention)
- The returned
SegmentIdis monotonically increasing within this universe
§Use Cases
This is particularly useful for ordering recursively created work:
- Recursive algorithms that spawn child tasks
- Ensuring deterministic processing order across concurrent operations
- Converting hierarchical sequence identifiers to linear segment identifiers
§Returns
A monotonically increasing SegmentId that can be used for ordered storage
or processing. Each successful collapse within a universe produces a larger
SegmentId than the previous one.
Trait Implementations§
Source§impl Debug for SequenceId
impl Debug for SequenceId
Source§impl Drop for SequenceId
impl Drop for SequenceId
Source§impl Hash for SequenceId
impl Hash for SequenceId
Source§impl Ord for SequenceId
impl Ord for SequenceId
Source§impl PartialEq for SequenceId
impl PartialEq for SequenceId
Source§impl PartialOrd for SequenceId
impl PartialOrd for SequenceId
impl Eq for SequenceId
Auto Trait Implementations§
impl Freeze for SequenceId
impl !RefUnwindSafe for SequenceId
impl Send for SequenceId
impl Sync for SequenceId
impl Unpin for SequenceId
impl !UnwindSafe for SequenceId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more