pub struct IdGenerator { /* private fields */ }Expand description
A monotonic ID generator.
Generates unique, monotonically increasing IDs. The generator is thread-safe and can be shared across threads. IDs start from 1 (0 is reserved for “no ID”).
§Persistence
The generator can be initialized with the highest existing ID to resume
after a restart. Use IdGenerator::with_start to set the starting value.
§Example
use manifoldb_graph::store::IdGenerator;
let gen = IdGenerator::new();
let id1 = gen.next_entity_id();
let id2 = gen.next_entity_id();
assert!(id1.as_u64() < id2.as_u64());Implementations§
Source§impl IdGenerator
impl IdGenerator
Sourcepub const fn with_start(entity_start: u64, edge_start: u64) -> Self
pub const fn with_start(entity_start: u64, edge_start: u64) -> Self
Create an ID generator starting from specific values.
Use this to resume ID generation after loading existing data. The provided values should be one greater than the highest existing IDs.
§Arguments
entity_start- The first entity ID to generateedge_start- The first edge ID to generate
Sourcepub fn next_entity_id(&self) -> EntityId
pub fn next_entity_id(&self) -> EntityId
Generate the next entity ID.
This operation is atomic and thread-safe.
Sourcepub fn next_edge_id(&self) -> EdgeId
pub fn next_edge_id(&self) -> EdgeId
Generate the next edge ID.
This operation is atomic and thread-safe.
Sourcepub fn current_entity_counter(&self) -> u64
pub fn current_entity_counter(&self) -> u64
Get the current entity ID counter value (next ID to be assigned).
Sourcepub fn current_edge_counter(&self) -> u64
pub fn current_edge_counter(&self) -> u64
Get the current edge ID counter value (next ID to be assigned).
Sourcepub fn reset_entity_counter(&self, value: u64)
pub fn reset_entity_counter(&self, value: u64)
Reset the entity ID counter to a new value.
This is primarily used for testing or when rebuilding indexes.
Sourcepub fn reset_edge_counter(&self, value: u64)
pub fn reset_edge_counter(&self, value: u64)
Reset the edge ID counter to a new value.
This is primarily used for testing or when rebuilding indexes.