DequeInt
struct · Source line 31
pub struct DequeInt { items: List[int], head: int, }The queue: elements items[head .. items.len], front first.
wolf-std d58f9e1
· toolchain pin verified against wolf 0.2.41 (0261597).
Source signatures and documentation; execution support is stated in each module.
All modules · Plain text · Stability tier: x
std.x.deque_int — the running prototype behind std.deque's reviewed contract: a double-ended queue at ONE concrete element type, because struct Deque[T] does not parse until s16 delivers generic data types. Stability tier: x (nursery, D31 clock — this module graduates into std.deque with int replaced by T, or it is deleted, at the stdc01 closeout).
What it proves, executing under BOTH implementations: the representation (one List[int] plus a head index — no second buffer), the amortization story, the front-to-back order to_list promises, and that every one of std.deque's ten operations is expressible over the language's List surface alone.
What it deliberately does not do: reclaim the space in front of head. A pop_front advances the head; the storage before it is released the next time the queue is rebuilt (push_front, pop_back, clear), or wholesale when the region dies (D10). A generic version would want a compaction rule; that is a decision for the graduating sprint, recorded here rather than guessed.
Absence is spelled none, the convention's own spelling as of sc06 (F-0003 is dead; "pending" was stale prose for six sprints). Every length read goes through count because std.list's single-read rule required it when these bodies were written; that rule died at the sc11 pin (s72's D40, F-0005 and F-0014 closed) and the shape is kept because it is correct, not because it is required.
struct · Source line 31
pub struct DequeInt { items: List[int], head: int, }The queue: elements items[head .. items.len], front first.
fn · Source line 53
pub fn new() -> DequeIntA fresh empty queue. Total: no error row, no traps.
let d = deque_int.new()
deque_int.len(d) == 0fn · Source line 64
pub fn len(d: DequeInt) -> intThe number of elements. Total: no error row, no traps.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.len(d) == 1fn · Source line 76
pub fn is_empty(d: DequeInt) -> boolWhether the queue holds no elements. Total: no error row, no traps.
var d = deque_int.new()
deque_int.is_empty(d) == true
deque_int.push_front(mut d, 1)
deque_int.is_empty(d) == falsefn · Source line 89
pub fn push_back(mut d: DequeInt, v: int)Appends v at the back. Amortized constant time. Total: no error row, no traps beyond allocation.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.push_back(mut d, 2)
(deque_int.back(d) else 0) == 2fn · Source line 103
pub fn push_front(mut d: DequeInt, v: int)Prepends v at the front. Rebuilds the buffer (this representation pays for push_front, which is the trade the prototype records). Total: no error row, no traps beyond allocation.
var d = deque_int.new()
deque_int.push_back(mut d, 2)
deque_int.push_front(mut d, 1)
(deque_int.front(d) else 0) == 1fn · Source line 123
pub fn front(d: DequeInt) -> int ! {none}The front element, left in place; none when empty. No traps.
var d = deque_int.new()
deque_int.push_back(mut d, 5)
(deque_int.front(d) else 0) == 5fn · Source line 138
pub fn back(d: DequeInt) -> int ! {none}The back element, left in place; none when empty. No traps.
var d = deque_int.new()
deque_int.push_back(mut d, 5)
deque_int.push_back(mut d, 6)
(deque_int.back(d) else 0) == 6fn · Source line 156
pub fn pop_front(mut d: DequeInt) -> int ! {none}Removes and returns the front element; none when empty. Constant time: the head advances and no element moves. No traps.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.push_back(mut d, 2)
(deque_int.pop_front(mut d) else 0) == 1
(deque_int.pop_front(mut d) else 0) == 2
(deque_int.pop_front(mut d) else 0 - 1) == 0 - 1fn · Source line 175
pub fn pop_back(mut d: DequeInt) -> int ! {none}Removes and returns the back element; none when empty. Rebuilds the buffer (see the module header on compaction). No traps.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.push_back(mut d, 2)
(deque_int.pop_back(mut d) else 0) == 2
deque_int.len(d) == 1fn · Source line 201
pub fn clear(mut d: DequeInt)Empties the queue, keeping it usable, and releases the buffer. Total: no error row, no traps.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.clear(mut d)
deque_int.is_empty(d) == truefn · Source line 217
pub fn to_list(d: DequeInt) -> List[int]A fresh list of the elements, FRONT to BACK — the one order this type promises. Total: no error row, no traps beyond allocation.
var d = deque_int.new()
deque_int.push_back(mut d, 1)
deque_int.push_front(mut d, 0)
var first = 0 - 1
for x in deque_int.to_list(d) { first = first + 1 }
first == 1No public declarations in this section.
Tags named by public signatures: none. Their conditions are documented on the functions that return them.
No public declarations in this section.