pub struct Arena<T: ?Sized, Storage = T, H = DefaultBuildHasher, I = u32> { /* private fields */ }Expand description
Implementations§
Source§impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
I: Index,
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
I: Index,
Sourcepub fn identity(&self) -> Mapping<I>
pub fn identity(&self) -> Mapping<I>
Returns the identity mapping of the items in this arena.
This can be useful to rehash the arena.
Sourcepub fn retain(
&self,
filter: impl Fn(Interned<T, Storage, H, I>) -> bool,
) -> Mapping<I>
pub fn retain( &self, filter: impl Fn(Interned<T, Storage, 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 = Interned<T, Storage, H, I>>,
) -> Mapping<I>
Available on crate feature retain only.
pub fn retain_values( &self, values: impl Iterator<Item = Interned<T, Storage, 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) -> RetainBuilder<T, Storage, H, I>
Available on crate feature retain only.
pub fn retain_builder(&self) -> RetainBuilder<T, Storage, H, I>
retain only.Returns a builder allowing to select items to retain, and create an arena containing only these.
Source§impl<T, Storage, H, I> Arena<T, Storage, H, I>
impl<T, Storage, H, I> Arena<T, Storage, H, I>
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>,
) -> Arena<T, Storage, HH, I>where
HH: Default + BuildHasher,
pub fn map_rehash<HH>(
&self,
mapping: &ReverseMapping<I>,
) -> Arena<T, Storage, 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.
Sourcepub fn map2(
&self,
mapping: &ReverseMapping<I>,
f: impl Fn(&T) -> Storage,
) -> Selfwhere
H: Default + BuildHasher,
pub fn map2(
&self,
mapping: &ReverseMapping<I>,
f: impl Fn(&T) -> Storage,
) -> Selfwhere
H: Default + BuildHasher,
Returns a re-ordered version of this arena based on the given mapping,
where each item is additionally transformed according to the given
function f.
The transformation function should be injective, i.e. different inputs should map to different outputs. Otherwise a value may appear twice in the resulting arena.
See also map2_rehash() to use a different hash
function in the resulting arena.
Sourcepub fn map2_rehash<HH>(
&self,
mapping: &ReverseMapping<I>,
f: impl Fn(&T) -> Storage,
) -> Arena<T, Storage, HH, I>where
HH: Default + BuildHasher,
pub fn map2_rehash<HH>(
&self,
mapping: &ReverseMapping<I>,
f: impl Fn(&T) -> Storage,
) -> Arena<T, Storage, HH, I>where
HH: Default + BuildHasher,
Returns a re-ordered version of this arena based on the given mapping,
where each item is additionally transformed according to the given
function f.
The transformation function should be injective, i.e. different inputs should map to different outputs. Otherwise a value may appear twice in the resulting arena.
See also map2() if the resulting arena uses the same
hash function.
Source§impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
H: Default,
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
H: Default,
Sourcepub fn with_capacity(len: usize) -> Self
pub fn with_capacity(len: usize) -> Self
Creates a new arena with pre-allocated space to store at least len
values of type T.
Source§impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of values in this arena.
Note that because Arena 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 Arena 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) -> Snapshot<'_, T, Storage, H, I>
pub fn snapshot(&self) -> Snapshot<'_, T, Storage, H, I>
Returns a snapshot of this arena.
Note that because Arena is a concurrent data structure, this is only
a snapshot as viewed by this thread.
Snapshots can be diffed into a SnapshotDiff, which is useful to
serialize an arena incrementally as values are added to it.
Source§impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = &T>
Available on crate feature raw only.
pub fn iter(&self) -> impl ExactSizeIterator<Item = &T>
raw only.Returns an iterator over all items in this arena, in indexing order.
Note that because Arena 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<T, Storage, H, I> Arena<T, Storage, H, I>
impl<T, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn find(&self, value: &T) -> Option<Interned<T, Storage, H, I>>
pub fn find(&self, value: &T) -> Option<Interned<T, Storage, H, I>>
Returns the given value’s Interned handle if it is already interned.
Otherwise, this simply returns None without adding the value 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.
Source§impl<T, Storage, H, I> Arena<T, Storage, H, I>
impl<T, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn push_mut(&mut self, value: Storage) -> I
Available on crate feature raw only.
pub fn push_mut(&mut self, value: Storage) -> 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<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
Storage: GetSize,
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>where
Storage: GetSize,
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<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, 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 items in this arena.
The underlying counter is incremented each time a value is interned, whether it was already previously in the arena or not.
Source§impl<T, Storage, H, I> Arena<T, Storage, H, I>
impl<T, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn intern(
&self,
value: impl Borrow<T> + Into<Storage>,
) -> Interned<T, Storage, H, I>
Available on crate feature sync only.
pub fn intern( &self, value: impl Borrow<T> + Into<Storage>, ) -> Interned<T, Storage, H, I>
sync only.Interns the given value in this arena.
If the value was already interned in this arena, it will simply be borrowed to retrieve its interning index. Otherwise it will then be converted to store it 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: impl Borrow<T> + Into<Storage>,
) -> Interned<T, Storage, H, I>
pub fn intern_mut( &mut self, value: impl Borrow<T> + Into<Storage>, ) -> Interned<T, Storage, H, I>
Interns the given value in this arena.
If the value was already interned in this arena, it will simply be borrowed to retrieve its interning index. Otherwise it will then be converted to store it 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<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn lookup(&self, interned: Interned<T, Storage, H, I>) -> Storage
pub fn lookup(&self, interned: Interned<T, Storage, H, I>) -> Storage
Retrieves the given Interned 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.
See also lookup_ref() if you only need a
reference.
Source§impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
impl<T: ?Sized, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn lookup_ref(&self, interned: Interned<T, Storage, H, I>) -> &T
pub fn lookup_ref(&self, interned: Interned<T, Storage, H, I>) -> &T
Source§impl<T, Storage, H, I> Arena<T, Storage, H, I>
impl<T, Storage, H, I> Arena<T, Storage, H, I>
Sourcepub fn truncate(&mut self, snapshot: SnapshotMark<T, Storage, H, I>)
pub fn truncate(&mut self, snapshot: SnapshotMark<T, Storage, H, I>)
Truncates this interner back to the given snapshot mark.
This is a no-op if the snapshot mark is larger than this interner (for example because the interner was already truncated to a smaller snapshot in the meantime).
Trait Implementations§
Source§impl<'de, T, Storage, H, I> Deserialize<'de> for Arena<T, Storage, H, I>where
T: Eq + Hash + ?Sized,
Storage: Borrow<T> + Deserialize<'de>,
H: Default + BuildHasher,
I: Index,
Available on crate feature serde only.
impl<'de, T, Storage, H, I> Deserialize<'de> for Arena<T, Storage, H, I>where
T: Eq + Hash + ?Sized,
Storage: Borrow<T> + Deserialize<'de>,
H: Default + BuildHasher,
I: Index,
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<T, Storage, H, I> Eq for Arena<T, Storage, H, I>
Source§impl<T: ?Sized, Storage, H, I> GetSize for Arena<T, Storage, H, I>
Available on crate feature get-size2 only.
impl<T: ?Sized, Storage, H, I> GetSize for Arena<T, Storage, H, I>
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 moreSource§impl<T, Storage, H, I> Schema for Arena<T, Storage, H, I>
Available on crate feature postcard-schema only.
impl<T, Storage, H, I> Schema for Arena<T, Storage, H, I>
postcard-schema only.Auto Trait Implementations§
impl<T, Storage = T, H = RandomState, I = u32> !Freeze for Arena<T, Storage, H, I>
impl<T, Storage = T, H = RandomState, I = u32> !RefUnwindSafe for Arena<T, Storage, H, I>
impl<T, Storage, H, I> Send for Arena<T, Storage, H, I>
impl<T, Storage, H, I> Sync for Arena<T, Storage, H, I>
impl<T, Storage, H, I> Unpin for Arena<T, Storage, H, I>
impl<T, Storage, H, I> UnsafeUnpin for Arena<T, Storage, H, I>where
AppendVec<Storage>: UnsafeUnpin,
DashTable<I>: UnsafeUnpin,
H: UnsafeUnpin,
PhantomData<fn() -> *const T>: UnsafeUnpin,
T: ?Sized,
impl<T, Storage, H, I> UnwindSafe for Arena<T, Storage, H, I>where
AppendVec<Storage>: UnwindSafe,
DashTable<I>: UnwindSafe,
H: UnwindSafe,
PhantomData<fn() -> *const T>: UnwindSafe,
T: ?Sized,
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