Skip to main content

DictionaryBuilder

Struct DictionaryBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new empty builder.

Source

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)
Source

pub fn add_property(&mut self, id: Id, data_type: DataType) -> usize

Adds or gets the index for a property.

Source

pub fn add_relation_type(&mut self, id: Id) -> usize

Adds or gets the index for a relation type.

Source

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.

Source

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.

Source

pub fn add_object(&mut self, id: Id) -> usize

Adds or gets the index for an object.

Source

pub fn add_context_id(&mut self, id: Id) -> usize

Adds or gets the index for a context ID.

Source

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.
Source

pub fn get_context_index(&self, context: &Context) -> Option<usize>

Gets the index for an existing context (for encoding).

Source

pub fn build(self) -> WireDictionaries

Builds the final wire dictionaries (consumes the builder).

Source

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.

Source

pub fn get_property_index(&self, id: &Id) -> Option<usize>

Gets the index for an existing property (for encoding).

Source

pub fn get_relation_type_index(&self, id: &Id) -> Option<usize>

Gets the index for an existing relation type (for encoding).

Source

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.

Source

pub fn get_object_index(&self, id: &Id) -> Option<usize>

Gets the index for an existing object (for encoding).

Source

pub fn get_context_id_index(&self, id: &Id) -> Option<usize>

Gets the index for an existing context ID (for encoding).

Source

pub fn write_dictionaries(&self, writer: &mut Writer)

Writes the dictionaries directly to a writer (avoids cloning).

Source

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)
Source

pub fn validate_limits(&self) -> Result<(), EncodeError>

Validates dictionary and context sizes against codec limits.

Source

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

Source§

fn clone(&self) -> DictionaryBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DictionaryBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DictionaryBuilder

Source§

fn default() -> DictionaryBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.