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. withHashTable::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§
Required Methods§
Sourcefn try_new_buckets(count: usize) -> Result<Pin<Array<Self>>, AllocError>
fn try_new_buckets(count: usize) -> Result<Pin<Array<Self>>, AllocError>
Allocates the storage for count empty buckets.
Sourceunsafe fn push_front_raw(self: Pin<&mut Self>, ptr: P)
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.
Sourcefn find_if<F>(&self, f: F) -> Option<&P::Target>where
F: FnMut(&P::Target) -> bool,
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.
Sourcefn erase_if<F>(self: Pin<&mut Self>, f: F) -> Option<P>where
F: FnMut(&P::Target) -> bool,
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.
Sourceunsafe fn erase(self: Pin<&mut Self>, obj: &P::Target) -> Option<P>
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.
Sourceunsafe fn replace_raw(
self: Pin<&mut Self>,
obj: &P::Target,
replacement: P,
) -> Option<P>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".