pub struct UnboundedQueue<T> { /* private fields */ }Expand description
An unbounded lock-free queue. This is the LCSQ from the ACM paper, “A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue” by Ruslan Nikolaev.
Internally, it manages a linked list of bounded queue types and this allows it to grow in an unbounded manner. Since with a reasonable order new queue creation and deletion should be sparse, the operation cost is largely dominated by the internal queues and thus is still extremely fast.
§Example
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<usize>::new();
queue.enqueue(4);
queue.enqueue(5);
assert_eq!(queue.dequeue(), Some(4));
assert_eq!(queue.dequeue(), Some(5));Implementations§
Source§impl<T> UnboundedQueue<T>
impl<T> UnboundedQueue<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new UnboundedQueue with a default segment size of 32.
§Examples
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<()>::new();
assert_eq!(queue.base_segment_capacity(), 32);Sourcepub fn with_segment_size(size: usize) -> Self
pub fn with_segment_size(size: usize) -> Self
Creates a new UnboundedQueue with a particular segment size. The segment size determines the size of each of the internal bounded queues. This method exists to allow developers to customize the internal sizes of the queues.
§Examples
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<()>::with_segment_size(4);
assert_eq!(queue.base_segment_capacity(), 4);Sourcepub fn base_segment_capacity(&self) -> usize
pub fn base_segment_capacity(&self) -> usize
Returns the base segment size of the unbounded queue.
§Examples
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<()>::with_segment_size(4);
assert_eq!(queue.base_segment_capacity(), 4);Sourcepub fn enqueue_handle(&self) -> UnboundedEnqueueHandle<'_, T>
pub fn enqueue_handle(&self) -> UnboundedEnqueueHandle<'_, T>
Creates an UnboundedEnqueueHandle that allows for the execution of many
§Example
use lfqueue::{UnboundedEnqueueHandle, UnboundedQueue};
let queue = UnboundedQueue::<usize>::new();
let mut handle = queue.enqueue_handle();
handle.enqueue(3);
handle.enqueue(4);pub fn full_handle(&self) -> UnboundedFullHandle<'_, T>
Sourcepub fn enqueue(&self, item: T)
pub fn enqueue(&self, item: T)
Enqueues a single entry. Internally, this just creates an UnboundedEnqueueHandle and performs a single enqueue operation. If you intend to do several enqueues in a row, please see UnboundedQueue::enqueue_handle.
§Example
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<usize>::new();
queue.enqueue(4);Sourcepub fn dequeue(&self) -> Option<T>
pub fn dequeue(&self) -> Option<T>
Dequeues a single entry. Internally, this just creates an UnboundedFullHandle and performs a single dequeue operation. If you intend to do several dequeues in a row, please see UnboundedQueue::full_handle.
§Example
use lfqueue::UnboundedQueue;
let queue = UnboundedQueue::<usize>::new();
queue.enqueue(2);
assert_eq!(queue.dequeue(), Some(2));