Struct ScopeSet

Source
pub struct ScopeSet<T, S: BuildHasher = RandomState> { /* private fields */ }
Expand description

A layered hash set for representing the scopes of variables.

Implementations§

Source§

impl<T> ScopeSet<T, RandomState>

Source

pub fn new() -> Self

Creates an empty ScopeSet with a default hasher and capacity.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty ScopeSet with a default hasher and the specified capacity.

Source§

impl<T, S: BuildHasher> ScopeSet<T, S>

Source

pub fn with_hasher(hash_builder: S) -> Self

Creates an empty ScopeSet with the specified hasher and a default capacity.

Source

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self

Creates an empty ScopeSet with the specified capacity and hasher.

Source§

impl<T, S: BuildHasher> ScopeSet<T, S>

Source

pub fn is_empty(&self) -> bool

Returns true is the set is empty.

Source

pub fn capacity(&self) -> usize

Gets the number of elements the set can hold without reallocating.

Source

pub fn len(&self) -> usize

Gets the number of unique keys in the set.

Source

pub fn depth(&self) -> usize

Gets the number of layers in the set.

Source

pub fn push_layer(&mut self)

Adds a new, empty layer.

Computes in O(1) time.

Source

pub fn pop_layer(&mut self) -> bool

Removes the topmost layer (if it isn’t the bottom layer) and all associated keys. Returns true if the layer was removed.

Computes in O(n) time in relation to the number of keys stored in the removed layer.

Source§

impl<T: Eq + Hash, S: BuildHasher> ScopeSet<T, S>

Source

pub fn clear_all(&mut self)

Removes all entries and additional layers.

Source

pub fn clear_top(&mut self)

Removes all keys in the topmost layer.

Source

pub fn define(&mut self, key: T)

Adds the specified key to the topmost layer.

Source

pub fn define_parent(&mut self, key: T, min_depth: usize)

Adds the specified key to the layer min_depth layers below the top layer. Saturates to base layer.

Source

pub fn remove<Q>(&mut self, key: &Q) -> bool
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Removes the specified key from the topmost layer and returns it.

Source

pub fn contains<Q>(&self, key: &Q) -> bool
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns true if any layer contains the specified key.

Computes in O(1) time.

Source

pub fn contains_at_top<Q>(&self, key: &Q) -> bool
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Returns true if the topmost layer contains the specified key. Computes in O(1) time.

Source

pub fn depth_of<Q>(&self, key: &Q) -> Option<usize>
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets the depth of the specified key (i.e. how many layers down from the top that the key first appears). A depth of 0 refers to the top layer.

Returns None if the key does not exist.

Computes in O(n) time (worst-case) in relation to layer count.

Source

pub fn depth_of_parent<Q>(&self, key: &Q, min_depth: usize) -> Option<usize>
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets the depth of the specified key (i.e. how many layers down from the top that the key first appears), but ignores a maximum number of layers from the top equal to min_depth. Saturates to base layer.

Returns None if the key does not exist.

Computes in O(n) time (worst-case) in relation to layer count.

Source

pub fn height_of<Q>(&self, key: &Q) -> Option<usize>
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets the height of the specified key (i.e. how many layers up from the bottom that the key last appears). A height of 0 refers to the bottom layer.

Returns None if the key does not exist.

Computes in O(n) time (worst-case) in relation to layer count.

Source

pub fn height_of_parent<Q>(&self, key: &Q, min_depth: usize) -> Option<usize>
where T: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets the height of the specified key (i.e. how many layers up from the bottom that the key last appears), but ignores a maximum number of layers from the top equal to min_depth. A height of 0 refers to the bottom layer. Saturates to base layer.

Returns None if the key does not exist.

Computes in O(n) time (worst-case) in relation to layer count.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Iterates over the keys in arbitrary order.

The iterator element type is &'a T.

Source

pub fn iter_top(&self) -> impl Iterator<Item = &T>

Iterates over the top-level keys in arbitrary order.

The iterator element type is &'a T.

Trait Implementations§

Source§

impl<T: Clone, S: Clone + BuildHasher> Clone for ScopeSet<T, S>

Source§

fn clone(&self) -> ScopeSet<T, S>

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, S: Default + BuildHasher> Default for ScopeSet<T, S>

Source§

fn default() -> Self

Creates a new ScopeSet with the default configuration.

Auto Trait Implementations§

§

impl<T, S> Freeze for ScopeSet<T, S>
where S: Freeze,

§

impl<T, S> RefUnwindSafe for ScopeSet<T, S>

§

impl<T, S> Send for ScopeSet<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for ScopeSet<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for ScopeSet<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for ScopeSet<T, S>
where S: UnwindSafe, T: UnwindSafe,

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.