Documentation

Algolean.Models.ListDataStructs

A stateful query type for Singly Linked Lists #

The query type SinglyLinkedList α models the abstract interface for a singly linked list. Its basic interface is identical to that of it's functional programming cousin, a recursively defined list.

A state type with a single list that is used to internally represent linear data structures like linked lists, stacks, and queues.

  • internalList : List α

    The internal list

Instances For

    Insertion strategy. This can be either last-in-first-out (lifo) or first-in-first-out (fifo)

    Instances For
      inductive Algolean.Algorithms.ListADT (s : Strategy) (α : Type u) :
      Type u → Type u

      An ADT query type for a stack. Note this is essentially identical to the List query type, but with renamed queries to match the typical names of a stack interface.

      Instances For

        A model for the stack query using the ListState to store the stack internally in the state type.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[simp]
          theorem Algolean.Algorithms.listModel_cost {α : Type} (s : Strategy) {α✝ : Type} (x✝ : ListADT s α α✝) :
          (listModel s).cost x✝ = 1
          @[simp]
          theorem Algolean.Algorithms.listModel_evalQuery {α : Type} (s : Strategy) {α✝ : Type} (x✝ : ListADT s α α✝) :
          (listModel s).evalQuery x✝ = match α✝, x✝ with | .(Option α), ListADT.peek => do let iL ← get pure iL.internalList.head? | .(PUnit.{1}), ListADT.drop => do let iL ← get set { internalList := iL.internalList.tail } pure () | .(PUnit.{1}), ListADT.insert x => match s with | Strategy.lifo => modify fun (iL : ListState α) => { internalList := x :: iL.internalList } | Strategy.fifo => modify fun (iL : ListState α) => { internalList := iL.internalList ++ [x] }
          @[reducible, inline]

          Interpretation of ListADT as the ADT of a stack

          Equations
          Instances For
            @[reducible, inline]

            Interpretation of ListADT as the ADT of a queue

            Equations
            Instances For