pub struct ContiguousQueue<T: Contiguous> { /* private fields */ }
Expand description
Utility for queueing and assembling values in a monoidal fashion.
In particular, ContiguousQueue
provides functions for queueing values and
attempting to acquire adjacent values.
Implementations§
Source§impl<T: Contiguous> ContiguousQueue<T>
impl<T: Contiguous> ContiguousQueue<T>
Source§impl<T> ContiguousQueue<T>
impl<T> ContiguousQueue<T>
Sourcepub fn find_contiguous(&self, next_value: &T) -> Option<Position<T>>
pub fn find_contiguous(&self, next_value: &T) -> Option<Position<T>>
Searches for a value that is contiguous to the provided next_value
.
Contiguity is stricter than mere ordering. Two values are considered contiguous if they are immediately next to each other without any gap. For example, in a series of integers, 1 and 2 are contiguous, but 1 and 3 are not.
Returns the position of the contiguous value relative to next_value
if
found, otherwise None
.
Sourcepub fn queue(&self, value: T)
pub fn queue(&self, value: T)
Adds the provided value to the queue.
This method is useful when a value doesn’t have an immediately contiguous counterpart in the queue. It ensures the value is stored and can be paired later when its contiguous counterpart arrives.
Sourcepub fn dequeue(&self, key: &T::Key) -> Option<T>
pub fn dequeue(&self, key: &T::Key) -> Option<T>
Removes the value with the given key from the queue.
Sourcepub fn acquire_contiguous_pair_or_queue(&self, next_value: T) -> Option<(T, T)>
pub fn acquire_contiguous_pair_or_queue(&self, next_value: T) -> Option<(T, T)>
Attempts to find a value contiguous to the provided next_value
and
pair them.
If a contiguous value is found, it returns the pair. If not, the
next_value
is queued for future pairing.