pub struct StringInterner { /* private fields */ }Expand description
String interner for reducing memory usage of repeated strings.
Domain and predicate names are often repeated throughout the symbol table. This interner ensures each unique string is stored only once in memory.
§Example
use tensorlogic_adapters::StringInterner;
let mut interner = StringInterner::new();
let id1 = interner.intern("Person");
let id2 = interner.intern("Person");
assert_eq!(id1, id2); // Same string gets same ID
assert_eq!(interner.resolve(id1), Some("Person"));Implementations§
Source§impl StringInterner
impl StringInterner
Sourcepub fn intern(&mut self, s: &str) -> usize
pub fn intern(&mut self, s: &str) -> usize
Intern a string and return its unique ID.
If the string already exists, returns the existing ID. Otherwise, allocates a new ID and stores the string.
Sourcepub fn memory_usage(&self) -> MemoryStats
pub fn memory_usage(&self) -> MemoryStats
Get memory usage statistics.
Trait Implementations§
Source§impl Clone for StringInterner
impl Clone for StringInterner
Source§fn clone(&self) -> StringInterner
fn clone(&self) -> StringInterner
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StringInterner
impl Debug for StringInterner
Source§impl Default for StringInterner
impl Default for StringInterner
Source§fn default() -> StringInterner
fn default() -> StringInterner
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StringInterner
impl RefUnwindSafe for StringInterner
impl Send for StringInterner
impl Sync for StringInterner
impl Unpin for StringInterner
impl UnwindSafe for StringInterner
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
Mutably borrows from an owned value. Read more