Skip to main content

HashConsArena

Struct HashConsArena 

Source
pub struct HashConsArena<T> { /* private fields */ }
Expand description

A hash consing arena that allows for efficient interning of values.

§Caveat(s)

The arena is backed by a bumpalo, therefore, objects allocated via the arena, will not have their Drop implementation called, without manual intervention. Thus, it is relatively easy to leak resources. If you need Drop to be called, use BoxedHashConsArena instead.

Implementations§

Source§

impl<T> HashConsArena<T>
where T: Eq + Hash,

Source

pub fn new() -> Self

Create a new HashConsArena.

Source

pub fn intern<'a>(&'a self, value: T) -> HRef<'a, T>
where T: Debug,

Intern a value, returning a reference that’s guaranteed to be the same for structurally equal values.

§Arguments
  • value - The value to intern. It must implement Eq and Hash.
§Returns

A HRef<T> that points to the interned value. If the value is already interned, it returns the existing reference.

§Example
use hashcons_arena::HashConsArena;

let arena = HashConsArena::new();

let a = arena.intern("hello");
let b = arena.intern("hello");

assert!(a == b); // a and b are the same reference
Source

pub fn reset(&mut self)

Reset the arena, clearing all interned values.

Auto Trait Implementations§

§

impl<T> !Freeze for HashConsArena<T>

§

impl<T> !RefUnwindSafe for HashConsArena<T>

§

impl<T> !Send for HashConsArena<T>

§

impl<T> !Sync for HashConsArena<T>

§

impl<T> !UnwindSafe for HashConsArena<T>

§

impl<T> Unpin for HashConsArena<T>

§

impl<T> UnsafeUnpin for HashConsArena<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> 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, 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.