pub struct ArenaStr<H = DefaultBuildHasher, I = u32> { /* private fields */ }Expand description
Interning arena for strings.
Implementations§
Source§impl<H, I> ArenaStr<H, I>where
I: Index,
impl<H, I> ArenaStr<H, I>where
I: Index,
Sourcepub fn retain(&self, filter: impl Fn(InternedStr<H, I>) -> bool) -> Mapping<I>
pub fn retain(&self, filter: impl Fn(InternedStr<H, I>) -> bool) -> Mapping<I>
Returns a mapping to build an arena containing only the items of this arena that satisfy the given predicate.
Sourcepub fn retain_values(
&self,
values: impl Iterator<Item = InternedStr<H, I>>,
) -> Mapping<I>
Available on crate feature retain only.
pub fn retain_values( &self, values: impl Iterator<Item = InternedStr<H, I>>, ) -> Mapping<I>
retain only.Returns a mapping to build an arena containing only the given items.
See also retain_builder() if you need a more
flexible way of adding items to retain.
Sourcepub fn retain_builder(&self) -> RetainStrBuilder<H, I>
Available on crate feature retain only.
pub fn retain_builder(&self) -> RetainStrBuilder<H, I>
retain only.Returns a builder allowing to select items to retain, and create an arena containing only these.
Source§impl<H, I> ArenaStr<H, I>where
I: Index,
impl<H, I> ArenaStr<H, I>where
I: Index,
Sourcepub fn map(&self, mapping: &ReverseMapping<I>) -> Selfwhere
H: Default + BuildHasher,
pub fn map(&self, mapping: &ReverseMapping<I>) -> Selfwhere
H: Default + BuildHasher,
Returns a re-ordered version of this arena based on the given mapping.
See also map_rehash() to use a different hash
function in the resulting arena.
Sourcepub fn map_rehash<HH>(&self, mapping: &ReverseMapping<I>) -> ArenaStr<HH, I>where
HH: Default + BuildHasher,
pub fn map_rehash<HH>(&self, mapping: &ReverseMapping<I>) -> ArenaStr<HH, I>where
HH: Default + BuildHasher,
Returns a re-ordered version of this arena based on the given mapping.
See also map() if the resulting arena uses the same hash
function.
Source§impl<H, I> ArenaStr<H, I>where
H: Default,
impl<H, I> ArenaStr<H, I>where
H: Default,
Sourcepub fn with_capacity(strings: usize, bytes: usize) -> Self
pub fn with_capacity(strings: usize, bytes: usize) -> Self
Creates a new arena with pre-allocated space to store at least the given number of strings, totalling the given number of bytes.
Source§impl<H, I> ArenaStr<H, I>
impl<H, I> ArenaStr<H, I>
Sourcepub fn strings(&self) -> usize
pub fn strings(&self) -> usize
Returns the number of strings in this arena.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot as viewed by this thread, and the result may change if
other threads are inserting values.
Sourcepub fn bytes(&self) -> usize
pub fn bytes(&self) -> usize
Returns the total number of bytes in this arena.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot as viewed by this thread, and the result may change if
other threads are inserting values.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if this arena is empty.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot as viewed by this thread, and the result may change if
other threads are inserting values.
Sourcepub fn snapshot(&self) -> SnapshotStr<'_, H, I>
Available on crate feature serde only.
pub fn snapshot(&self) -> SnapshotStr<'_, H, I>
serde only.Returns a snapshot of this arena.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot as viewed by this thread.
Snapshots can be diffed into a SnapshotStrDiff, which is useful to
serialize an arena incrementally as values are added to it.
Source§impl<H, I: Index> ArenaStr<H, I>
impl<H, I: Index> ArenaStr<H, I>
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = &str>
Available on crate feature raw only.
pub fn iter(&self) -> impl ExactSizeIterator<Item = &str>
raw only.Returns an iterator over all strings in this arena, in indexing order.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot. Once this iterator has been created, for performance
reasons it will not iterate over items added afterwards, even on the
same thread.
If you only need to access byte slices,
iter_bytes() may be more efficient.
Sourcepub fn iter_bytes(&self) -> impl ExactSizeIterator<Item = &[u8]>
Available on crate feature raw only.
pub fn iter_bytes(&self) -> impl ExactSizeIterator<Item = &[u8]>
raw only.Returns an iterator over all strings (viewed as byte slices) in this arena, in indexing order.
Note that because ArenaStr is a concurrent data structure, this is
only a snapshot. Once this iterator has been created, for performance
reasons it will not iterate over items added afterwards, even on the
same thread.
Source§impl<H, I> ArenaStr<H, I>where
H: BuildHasher,
I: Index,
impl<H, I> ArenaStr<H, I>where
H: BuildHasher,
I: Index,
Sourcepub fn find(&self, value: &str) -> Option<InternedStr<H, I>>
pub fn find(&self, value: &str) -> Option<InternedStr<H, I>>
Returns the given string’s InternedStr handle if it is already
interned.
Otherwise, this simply returns None without adding the string to
this arena.
See also find_mut(), which is more efficient if you
hold a mutable reference to this arena as it avoids acquiring locks.
Sourcepub fn find_mut(&mut self, value: &str) -> Option<InternedStr<H, I>>
pub fn find_mut(&mut self, value: &str) -> Option<InternedStr<H, I>>
Returns the given string’s InternedStr handle if it is already
interned.
Otherwise, this simply returns None without adding the string to
this arena.
Contrary to find(), no locks are held internally because
this function already takes an exclusive mutable reference to this
arena.
Sourcepub fn push_mut(&mut self, value: &str) -> I
Available on crate feature raw only.
pub fn push_mut(&mut self, value: &str) -> I
raw only.Unconditionally push a value, without validating that it’s already interned.
Calling this function multiple times with the same value doesn’t violate safety, but the value will be stored multiple times in the arena.
Source§impl<H, I> ArenaStr<H, I>
impl<H, I> ArenaStr<H, I>
Sourcepub fn print_summary(&self, prefix: &str, title: &str, total_bytes: usize)
Available on crate features debug and std only.
pub fn print_summary(&self, prefix: &str, title: &str, total_bytes: usize)
debug and std only.Prints a summary of the storage used by this arena to stdout.
Source§impl<H, I> ArenaStr<H, I>
impl<H, I> ArenaStr<H, I>
Sourcepub fn references(&self) -> usize
Available on crate feature debug only.
pub fn references(&self) -> usize
debug only.Returns the total number of references to strings in this arena.
The underlying counter is incremented each time a string is interned, whether it was already previously in the arena or not.
Source§impl<H, I> ArenaStr<H, I>where
H: BuildHasher,
I: Index,
impl<H, I> ArenaStr<H, I>where
H: BuildHasher,
I: Index,
Sourcepub fn intern(&self, value: &str) -> InternedStr<H, I>
Available on crate feature sync only.
pub fn intern(&self, value: &str) -> InternedStr<H, I>
sync only.Interns the given value in this arena.
If the value was already interned in this arena, its interning index will simply be returned. Otherwise it will be stored into the arena.
See also intern_mut(), which is more efficient if
you hold a mutable reference to this arena as it avoids acquiring locks.
Sourcepub fn intern_mut(&mut self, value: &str) -> InternedStr<H, I>
pub fn intern_mut(&mut self, value: &str) -> InternedStr<H, I>
Interns the given value in this arena.
If the value was already interned in this arena, its interning index will simply be returned. Otherwise it will be stored into the arena.
Contrary to intern(), no locks are held internally
because this function already takes an exclusive mutable reference to
this arena.
Source§impl<H, I: Index> ArenaStr<H, I>
impl<H, I: Index> ArenaStr<H, I>
Sourcepub fn lookup(&self, interned: InternedStr<H, I>) -> &str
pub fn lookup(&self, interned: InternedStr<H, I>) -> &str
Retrieves the given InternedStr value from this arena.
The caller is responsible for ensuring that the same arena was used to intern this value, otherwise an arbitrary value will be returned or a panic will happen.
If you only need to access the bytes,
lookup_bytes() may be more efficient.
Sourcepub fn lookup_bytes(&self, interned: InternedStr<H, I>) -> &[u8] ⓘ
pub fn lookup_bytes(&self, interned: InternedStr<H, I>) -> &[u8] ⓘ
Retrieves the bytes for the given InternedStr value from this arena.
The caller is responsible for ensuring that the same arena was used to intern this value, otherwise an arbitrary value will be returned or a panic will happen.
Trait Implementations§
Source§impl<'de, H, I> Deserialize<'de> for ArenaStr<H, I>
Available on crate feature serde only.
impl<'de, H, I> Deserialize<'de> for ArenaStr<H, I>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl<H, I: Index> Eq for ArenaStr<H, I>
Source§impl<H, I> GetSize for ArenaStr<H, I>where
I: GetSize,
Available on crate feature get-size2 only.
impl<H, I> GetSize for ArenaStr<H, I>where
I: GetSize,
get-size2 only.Source§fn get_heap_size_with_tracker<Tr: GetSizeTracker>(
&self,
tracker: Tr,
) -> (usize, Tr)
fn get_heap_size_with_tracker<Tr: GetSizeTracker>( &self, tracker: Tr, ) -> (usize, Tr)
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker. Read moreAuto Trait Implementations§
impl<H = RandomState, I = u32> !Freeze for ArenaStr<H, I>
impl<H = RandomState, I = u32> !RefUnwindSafe for ArenaStr<H, I>
impl<H, I> Send for ArenaStr<H, I>
impl<H, I> Sync for ArenaStr<H, I>
impl<H, I> Unpin for ArenaStr<H, I>
impl<H, I> UnsafeUnpin for ArenaStr<H, I>
impl<H, I> UnwindSafe for ArenaStr<H, I>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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