Skip to main content

HashTableBucket

Trait HashTableBucket 

Source
pub trait HashTableBucket<P: PtrTraits>: Sealed + Sized {
    type Iter<'a>: Iterator<Item = &'a P::Target>
       where Self: 'a,
             P: 'a;

    // Required methods
    fn try_new_buckets(count: usize) -> Result<Pin<Array<Self>>, AllocError>;
    fn is_empty(&self) -> bool;
    unsafe fn push_front_raw(self: Pin<&mut Self>, ptr: P);
    fn find_if<F>(&self, f: F) -> Option<&P::Target>
       where F: FnMut(&P::Target) -> bool;
    fn erase_if<F>(self: Pin<&mut Self>, f: F) -> Option<P>
       where F: FnMut(&P::Target) -> bool;
    unsafe fn erase(self: Pin<&mut Self>, obj: &P::Target) -> Option<P>;
    unsafe fn replace_raw(
        self: Pin<&mut Self>,
        obj: &P::Target,
        replacement: P,
    ) -> Option<P>;
    fn clear(self: Pin<&mut Self>);
    fn iter<'a>(&'a self) -> Self::Iter<'a>
       where P: 'a;
}
Expand description

A list type which can be used as the bucket type of a HashTable of pointers of type P.

This trait is sealed. It is implemented for:

  • SinglyLinkedList<P, Tag>: Erasing a specific element (e.g. with HashTable::erase_element) searches its bucket, so it runs in time proportional to the length of the bucket.
  • DoublyLinkedList<P, Tag>: Erasing a specific element runs in constant time. The buckets must not move once initialized; the hash table keeps them pinned in its bucket storage.

Required Associated Types§

Source

type Iter<'a>: Iterator<Item = &'a P::Target> where Self: 'a, P: 'a

An iterator over the elements of a bucket.

Required Methods§

Source

fn try_new_buckets(count: usize) -> Result<Pin<Array<Self>>, AllocError>

Allocates the storage for count empty buckets.

Source

fn is_empty(&self) -> bool

Returns true if the bucket is empty.

Source

unsafe fn push_front_raw(self: Pin<&mut Self>, ptr: P)

Pushes an element to the front of the bucket.

§Safety

The caller must ensure that ptr is a valid pointer to an object that is not currently in any container, and that the object outlives the reference from the bucket.

Source

fn find_if<F>(&self, f: F) -> Option<&P::Target>
where F: FnMut(&P::Target) -> bool,

Finds the first element of the bucket which satisfies the predicate.

Source

fn erase_if<F>(self: Pin<&mut Self>, f: F) -> Option<P>
where F: FnMut(&P::Target) -> bool,

Finds the first element of the bucket which satisfies the predicate, erases it from the bucket, and returns it.

Source

unsafe fn erase(self: Pin<&mut Self>, obj: &P::Target) -> Option<P>

Erases obj from the bucket, returning it. Returns None if obj is not in any container.

§Safety

The caller must ensure that obj is either not in any container, or is currently in this bucket.

Source

unsafe fn replace_raw( self: Pin<&mut Self>, obj: &P::Target, replacement: P, ) -> Option<P>

Replaces obj with replacement in the bucket, returning the replaced element.

§Safety

The caller must ensure that obj is currently in this bucket, and that replacement is a valid pointer to an object that is not currently in any container and that outlives the reference from the bucket.

Source

fn clear(self: Pin<&mut Self>)

Removes all elements from the bucket.

Source

fn iter<'a>(&'a self) -> Self::Iter<'a>
where P: 'a,

Returns an iterator over the elements of the bucket.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<P, Tag, S> HashTableBucket<P> for DoublyLinkedList<P, Tag, S>

Source§

type Iter<'a> = ForwardIterator<'a, P, Tag> where Self: 'a, P: 'a

Source§

impl<P, Tag, S> HashTableBucket<P> for SinglyLinkedList<P, Tag, S>

Source§

type Iter<'a> = Iterator<'a, P, Tag> where Self: 'a, P: 'a