Skip to content
volt
GitHub

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 deque

A 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 = 0the slot of the first element
len: usize = 0the elements held
cap: usize = 0the 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!void

room 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) -> void

append value at the back

<T: type, A: std::mem::allocator> attach fn push_front(this: std::deque<T, A>&, value: T) -> void

put 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>&) -> void

delete 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>&) -> void

deletes the elements, then frees the memory

struct std::deque_iter

<T: type, A: std::mem::allocator> struct deque_iter

walks a deque front to back; changing the deque while walking isn't allowed

Field
d: std::deque<T, A>*
i: usize = 0the next element

Methods

<T: type, A: std::mem::allocator> attach fn next(this: std::deque_iter<T, A>&) -> T*

the next element