Struct simple_interner::Interner
source · pub struct Interner<T: ?Sized, S = RandomState> { /* private fields */ }
Expand description
An interner based on a HashSet
. See the crate-level docs for more.
Implementations§
source§impl<T: Eq + Hash + ?Sized, S: BuildHasher> Interner<T, S>
impl<T: Eq + Hash + ?Sized, S: BuildHasher> Interner<T, S>
sourcepub fn intern<R>(&self, t: R) -> Interned<'_, T>where
R: Borrow<T> + Into<Box<T>>,
pub fn intern<R>(&self, t: R) -> Interned<'_, T>where
R: Borrow<T> + Into<Box<T>>,
Intern an item into the interner.
Takes borrowed or heap-allocated items. If the item has not been
previously interned, it will be Into::into
ed a Box
on the heap and
cached. Notably, if you give this fn a String
or Vec
, the allocation
will be shrunk to fit.
Note that the interner may need to reallocate to make space for the new
reference, just the same as a HashSet
would. This cost is amortized to
O(1)
as it is in other standard library collections.
If you have an owned item (especially if it has a cheap transformation
to Box
) and no longer need the ownership, pass it in directly.
Otherwise, pass in a reference.
See get
for more about the interned symbol.
source§impl<T: ?Sized> Interner<T>
impl<T: ?Sized> Interner<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty interner.
The backing set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create an empty interner with the specified capacity.
The interner will be able to hold at least capacity
items without reallocating.
If capacity
is 0, the interner will not initially allocate.
source§impl<T: ?Sized, H: BuildHasher> Interner<T, H>
impl<T: ?Sized, H: BuildHasher> Interner<T, H>
Constructors to control the backing HashSet
’s hash function
sourcepub fn with_hasher(hasher: H) -> Self
pub fn with_hasher(hasher: H) -> Self
Create an empty interner which will use the given hasher to hash the values.
The interner is also created with the default capacity.
sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: H) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hasher: H) -> Self
Create an empty interner with the specified capacity, using hasher
to hash the values.
The interner will be able to hold at least capacity
items without reallocating.
If capacity
is 0, the interner will not initially allocate.