pub struct StringDictionary { /* private fields */ }Expand description
A dictionary-encoded string column.
Implementations§
Source§impl StringDictionary
impl StringDictionary
Sourcepub fn encode(strings: &[Option<&str>]) -> (Self, Vec<u32>)
pub fn encode(strings: &[Option<&str>]) -> (Self, Vec<u32>)
Encode a batch of strings, returning (dictionary, encoded_ids).
The dictionary contains unique strings. encoded_ids is a Vec<u32>
where each entry is the dictionary ID for the corresponding input string.
Unknown/NULL strings get ID u32::MAX.
Sourcepub fn lookup(&self, id: u32) -> Option<&str>
pub fn lookup(&self, id: u32) -> Option<&str>
Look up a string by ID. Returns None if ID is out of range.
Sourcepub fn lookup_id(&self, s: &str) -> Option<u32>
pub fn lookup_id(&self, s: &str) -> Option<u32>
Look up a string value and return its ID. Returns None if not found.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
pub fn serialize(&self) -> Vec<u8> ⓘ
Serialize the dictionary to bytes.
Format: [num_strings: u32][for each string: [len: u32][bytes...]]
Sourcepub fn deserialize(data: &[u8]) -> Result<Self>
pub fn deserialize(data: &[u8]) -> Result<Self>
Deserialize a dictionary from bytes.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Compute the memory usage in bytes.
String bytes are counted once: the Rc<str> in strings and the map key
share a single heap allocation, so the reverse-lookup keys add only the
Rc pointer/refcount overhead, not a second copy of the data.
Trait Implementations§
Source§impl Clone for StringDictionary
impl Clone for StringDictionary
Source§fn clone(&self) -> StringDictionary
fn clone(&self) -> StringDictionary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StringDictionary
impl Debug for StringDictionary
Auto Trait Implementations§
impl !Send for StringDictionary
impl !Sync for StringDictionary
impl Freeze for StringDictionary
impl RefUnwindSafe for StringDictionary
impl Unpin for StringDictionary
impl UnsafeUnpin for StringDictionary
impl UnwindSafe for StringDictionary
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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