Documentation

CslibFrontier.DataStructure.Queue.WordRAM.Model

The FIFO meaning of a two-stack representation #

The front stack lists the oldest values first; the rear stack lists the newest values first. Thus the represented FIFO sequence is front ++ rear.reverse. Enqueue pushes onto the rear. Dequeue pops the front when possible; otherwise it reverses the entire rear into the front before popping. Reversal is only a mathematical description here: the machine implementation executes a charged loop, moving one value at a time.

Main definitions #

Main results #

References #

@[reducible, inline]

A queue admits an enqueue exactly when it has spare capacity and the value fits a word.

Logical two-stack state of a FIFO queue: front stores the oldest elements in FIFO order and rear stores newly enqueued elements in reverse FIFO order.

  • front : List ℕ

    Oldest elements in FIFO order, popped first by dequeue.

  • rear : List ℕ

    Newest elements in reverse FIFO order, reversed into front when front is empty.

Instances For

    Front is in FIFO order; rear is in reverse FIFO order.

    Mathematical description of the machine's two-stack transition, including an empty pop.

    Projecting the concrete stack transition gives exactly the specified FIFO step.

    The sum of live stack lengths is the FIFO length, not the size of the reserved regions.

    theorem Cslib.DataStructure.Queue.WordRAM.pairStep_length_le {w capacity : ℕ} {s : Stacks} (hs : s.contents.length ≤ capacity) (o : QueueOp ℕ) (hv : (spec w capacity).valid s.contents o) :
    (pairStep s o).1.contents.length ≤ capacity

    Enqueues require one spare slot; dequeues cannot increase the number of live values.