Struct HashInterner

Source
pub struct HashInterner<T: ?Sized + Eq + Hash> { /* private fields */ }
Expand description

Interner for hashable values

The interner is cheaply cloneable by virtue of keeping the underlying storage in an Arc. Once the last reference to this interner is dropped, it will clear its backing storage and release all references to the interned values it has created that are still live. Those values remain fully operational until dropped. Memory for the values themselves is freed for each value individually once its last reference is dropped. The interner’s ArcInner memory will only be deallocated once the last interned value has been dropped (this is less than hundred bytes).

Implementations§

Source§

impl<T: ?Sized + Eq + Hash> HashInterner<T>

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Returns the number of objects currently kept in this interner.

Source

pub fn is_empty(&self) -> bool

Returns true when this interner doesn’t hold any values.

Source

pub fn intern_ref(&self, value: &T) -> InternedHash<T>
where T: ToOwned, T::Owned: Into<Box<T>>,

Intern a value from a shared reference by allocating new memory for it.

use intern_arc::{HashInterner, InternedHash};

let strings = HashInterner::<str>::new();
let i: InternedHash<str> = strings.intern_ref("hello world!");
Source

pub fn intern_box(&self, value: Box<T>) -> InternedHash<T>

Intern a value from an owned reference without allocating new memory for it.

use intern_arc::{HashInterner, InternedHash};

let strings = HashInterner::<str>::new();
let hello: Box<str> = "hello world!".into();
let i: InternedHash<str> = strings.intern_box(hello);

(This also works nicely with a String that can be turned .into() a Box.)

Source

pub fn intern_sized(&self, value: T) -> InternedHash<T>
where T: Sized,

Intern a sized value, allocating heap memory for it.

use intern_arc::{HashInterner, InternedHash};

let arrays = HashInterner::<[u8; 1000]>::new();
let i: InternedHash<[u8; 1000]> = arrays.intern_sized([0; 1000]);

Trait Implementations§

Source§

impl<T: ?Sized + Eq + Hash> Clone for HashInterner<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized + Eq + Hash> Default for HashInterner<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for HashInterner<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for HashInterner<T>

§

impl<T> Send for HashInterner<T>
where T: Sync + Send + ?Sized,

§

impl<T> Sync for HashInterner<T>
where T: Sync + Send + ?Sized,

§

impl<T> Unpin for HashInterner<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for HashInterner<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.