pub struct DictionaryBuilder { /* private fields */ }Expand description
Builder for constructing wire dictionaries during encoding.
Uses FxHashMap for faster hashing of 16-byte IDs.
Implementations§
Source§impl DictionaryBuilder
impl DictionaryBuilder
Sourcepub fn with_capacity(estimated_ops: usize) -> Self
pub fn with_capacity(estimated_ops: usize) -> Self
Creates a new builder with pre-allocated capacity.
estimated_ops is used to estimate dictionary sizes:
- properties: ~estimated_ops / 4 (entities average ~4 properties)
- relation_types: ~estimated_ops / 20 (fewer unique relation types)
- languages: 4 (typically few languages per edit)
- units: 4 (typically few units per edit)
- objects: ~estimated_ops / 2 (many ops reference existing objects)
- context_ids: 8 (typically few context IDs per edit)
- contexts: 4 (typically few unique contexts per edit)
Sourcepub fn add_property(&mut self, id: Id, data_type: DataType) -> usize
pub fn add_property(&mut self, id: Id, data_type: DataType) -> usize
Adds or gets the index for a property.
Sourcepub fn add_relation_type(&mut self, id: Id) -> usize
pub fn add_relation_type(&mut self, id: Id) -> usize
Adds or gets the index for a relation type.
Sourcepub fn add_language(&mut self, id: Option<Id>) -> usize
pub fn add_language(&mut self, id: Option<Id>) -> usize
Adds or gets the index for a language.
Returns 0 for default (no language), 1+ for actual languages.
Sourcepub fn add_unit(&mut self, id: Option<Id>) -> usize
pub fn add_unit(&mut self, id: Option<Id>) -> usize
Adds or gets the index for a unit.
Returns 0 for no unit, 1+ for actual units.
Sourcepub fn add_object(&mut self, id: Id) -> usize
pub fn add_object(&mut self, id: Id) -> usize
Adds or gets the index for an object.
Sourcepub fn add_context_id(&mut self, id: Id) -> usize
pub fn add_context_id(&mut self, id: Id) -> usize
Adds or gets the index for a context ID.
Sourcepub fn add_context(&mut self, context: &Context) -> usize
pub fn add_context(&mut self, context: &Context) -> usize
Adds or gets the index for a context.
If the context is new, registers all its IDs to the appropriate dictionaries:
- root_id and edge.to_entity_id go to context_ids dictionary
- edge.type_id goes to relation_types dictionary (it’s a RelationTypeRef) Returns the index into the contexts array.
Sourcepub fn get_context_index(&self, context: &Context) -> Option<usize>
pub fn get_context_index(&self, context: &Context) -> Option<usize>
Gets the index for an existing context (for encoding).
Sourcepub fn build(self) -> WireDictionaries
pub fn build(self) -> WireDictionaries
Builds the final wire dictionaries (consumes the builder).
Sourcepub fn as_wire_dicts(&self) -> WireDictionaries
pub fn as_wire_dicts(&self) -> WireDictionaries
Returns a reference to wire dictionaries without consuming the builder. This allows continued use of the builder for encoding while having the dictionaries.
Sourcepub fn get_property_index(&self, id: &Id) -> Option<usize>
pub fn get_property_index(&self, id: &Id) -> Option<usize>
Gets the index for an existing property (for encoding).
Sourcepub fn get_relation_type_index(&self, id: &Id) -> Option<usize>
pub fn get_relation_type_index(&self, id: &Id) -> Option<usize>
Gets the index for an existing relation type (for encoding).
Sourcepub fn get_language_index(&self, id: Option<&Id>) -> Option<usize>
pub fn get_language_index(&self, id: Option<&Id>) -> Option<usize>
Gets the index for an existing language (for encoding). Returns 0 for None, 1+ for existing languages.
Sourcepub fn get_object_index(&self, id: &Id) -> Option<usize>
pub fn get_object_index(&self, id: &Id) -> Option<usize>
Gets the index for an existing object (for encoding).
Sourcepub fn get_context_id_index(&self, id: &Id) -> Option<usize>
pub fn get_context_id_index(&self, id: &Id) -> Option<usize>
Gets the index for an existing context ID (for encoding).
Sourcepub fn write_dictionaries(&self, writer: &mut Writer)
pub fn write_dictionaries(&self, writer: &mut Writer)
Writes the dictionaries directly to a writer (avoids cloning).
Sourcepub fn write_contexts(&self, writer: &mut Writer)
pub fn write_contexts(&self, writer: &mut Writer)
Writes the contexts array to the writer.
Each context is encoded as:
- root_id: varint (index into context_ids)
- edge_count: varint
- edges: for each edge: type_id (RelationTypeRef), to_entity_id (ContextRef)
Sourcepub fn validate_limits(&self) -> Result<(), EncodeError>
pub fn validate_limits(&self) -> Result<(), EncodeError>
Validates dictionary and context sizes against codec limits.
Sourcepub fn into_sorted(self) -> Self
pub fn into_sorted(self) -> Self
Converts this builder into a sorted canonical form.
All dictionaries are sorted by ID bytes (lexicographic order), and the index maps are rebuilt to reflect the new ordering.
This is used for canonical encoding to ensure deterministic output.
Trait Implementations§
Source§impl Clone for DictionaryBuilder
impl Clone for DictionaryBuilder
Source§fn clone(&self) -> DictionaryBuilder
fn clone(&self) -> DictionaryBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more