std::deque
A double-ended queue (a ring buffer): push and pop at both ends in O(1).
Source: std/deque.volt
Types
struct std::deque
<T: type, Allocator: std::mem::allocator = std::mem::default_allocator> struct dequeA double-ended queue that owns its elements. Nothing is allocated until the first push.
| Field | |
|---|---|
ptr: T* = @cast<T*>(@alignof(T)) | cap slots; a non-null placeholder while cap is 0 |
head: usize = 0 | the slot of the first element |
len: usize = 0 | the elements held |
cap: usize = 0 | the slots |
allocator: Allocator = {} | where the slots come from |
Methods
<T: type, A: std::mem::allocator> attach fn new_in(static this: std::deque<T>, allocator: A) -> std::deque<T, A>an empty deque that allocates from allocator
<T: type, A: std::mem::allocator> attach fn reserve(this: std::deque<T, A>&, n: usize) -> std::mem::mem_error!voidroom for at least n elements: when it grows (to double, at least 8), the elements move to the front of the new slots in order
<T: type, A: std::mem::allocator> attach fn at(this: std::deque<T, A>&, i: usize) -> T&element i from the front (panics when i >= len)
<T: type, A: std::mem::allocator> attach fn front(this: std::deque<T, A>&) -> T*the first element, or null when empty
<T: type, A: std::mem::allocator> attach fn back(this: std::deque<T, A>&) -> T*the last element, or null when empty
<T: type, A: std::mem::allocator> attach fn push_back(this: std::deque<T, A>&, value: T) -> voidappend value at the back
<T: type, A: std::mem::allocator> attach fn push_front(this: std::deque<T, A>&, value: T) -> voidput value at the front
<T: type, A: std::mem::allocator> attach fn pop_back(this: std::deque<T, A>&) -> T?the last element, moved out
<T: type, A: std::mem::allocator> attach fn pop_front(this: std::deque<T, A>&) -> T?the first element, moved out
<T: type, A: std::mem::allocator> attach fn clear(this: std::deque<T, A>&) -> voiddelete every element, keep the memory
<T: type, A: std::mem::allocator> attach fn iter(this: std::deque<T, A>&) -> std::deque_iter<T, A>for (x) in d.iter(): each element, as a reference
<T: type, A: std::mem::allocator> attach fn copy(this: std::deque<T, A>&) -> std::deque<T, A>a new deque holding a copy of each element, with a copy of the allocator
<T: type, A: std::mem::allocator> attach fn delete(this: std::deque<T, A>&) -> voiddeletes the elements, then frees the memory
struct std::deque_iter
<T: type, A: std::mem::allocator> struct deque_iterwalks a deque front to back; changing the deque while walking isn't allowed
| Field | |
|---|---|
d: std::deque<T, A>* | |
i: usize = 0 | the next element |
Methods
<T: type, A: std::mem::allocator> attach fn next(this: std::deque_iter<T, A>&) -> T*the next element