Skip to content

std.deque

ring-buffer deque in an arena; O(1) push/pop at both ends; grows 2x

pub Deque :: struct($T: type) {
region: *Arena,
data: []T,
head: usize,
count: usize,
}
  • region: where it grows (borrowed)
  • data: the ring; capacity == data.len
  • head: where the front element is
pub len :: fn(self: *Self) -> usize
pub is_empty :: fn(self: *Self) -> bool
pub push_back :: fn(self: *Self, item: T)
pub push_front :: fn(self: *Self, item: T)
pub pop_front :: fn(self: *Self) -> ?T

take the front; null if empty

pub pop_back :: fn(self: *Self) -> ?T

take the back; null if empty

pub front :: fn(self: *Self) -> ?T
pub back :: fn(self: *Self) -> ?T
pub get :: fn(self: *Self, i: usize) -> T

element i from the front; i < len()

pub set :: fn(self: *Self, i: usize, v: T)
pub each :: fn(self: *Self) -> Each(T)

front to back, left in place

pub clear :: fn(self: *Self)
pub Each :: struct($T: type) {
d: *Deque(T),
i: usize,
}

iterator from Deque.each

pub next :: fn(self: *Self) -> ?T
pub make :: fn($T: type, a: *Arena) -> Deque(T)
pub with_cap :: fn($T: type, a: *Arena, cap: usize) -> Deque(T)

deque in a with room for cap before it grows