Documentation

LeanPool.OrderMaintenance.Model.Top

Level F: the top structure (prototype/top_wbbt.py) #

A weight-balanced tree over the chunks with immutable label tables, stored paths and ghost drains. A chunk's tag is the concatenation of the labels along its path p[1..H], with F_j = lab_{p[j]}(p[j-1]) in bits [(j-1)β, jβ).

def OrderMaintenance.Model.assocSet {β : Type} (l : List (Nat × β)) (k : Nat) (v : β) :
List (Nat × β)

(n, l) with l placed after the existing entries, or replacing the entry for n.

Equations
Instances For
    def OrderMaintenance.Model.assocErase {β : Type} (l : List (Nat × β)) (k : Nat) :
    List (Nat × β)

    Remove every entry with the specified key from an association list.

    Equations
    Instances For
      @[irreducible]
      def OrderMaintenance.Model.chunksOf {α : Type} (n : Nat) :
      List α → List (List α)

      Split a list into pieces of length n (the last may be shorter).

      Equations
      Instances For

        Utilities #

        Discard the top tree and all of its chunk paths and table memberships.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Append a fresh node at the specified height and return its index.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Read the array of top-tree ancestors associated with a chunk.

            Equations
            Instances For

              Replace a chunk’s array of top-tree ancestors.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Set one height of a chunk’s top-tree ancestor path.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Read the live parent of a chunk at height zero.

                  Equations
                  Instances For

                    Set the live parent of a chunk at height zero.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Tables containing entry e, which lives at height h (0 = chunk).

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Replace the containing-table list of a chunk or a higher tree entry.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Assemble a chunk tag from the labels along its top-tree path.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Check that a proposed chunk tag lies strictly between its neighbours’ tags.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              A guarded tag write (the safety principle): t must lie strictly between the tags of the chunk-list neighbours of c.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                A label for a new entry right before/after e in the table of node t (averaging).

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def OrderMaintenance.Model.tableInsert (t e new : Nat) (before : Bool) (lab : Nat) :

                                  Insert and label a new table entry adjacent to a specified existing entry.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Construction #

                                    One step of init_steps: build the chain node of height prep.h, or finish. Returns true once the structure is complete.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Construct a fresh top tree for an ordered list of chunks.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        The linked list from x along nxt, at most fuel long.

                                        Equations
                                        Instances For

                                          Number the chunks of l as 1, 2, 3, ….

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            FALLBACK's top part: rebuild the tree, then verify that the tags increase along the chunk list. If they do not (label width too small, docs/PROOF.md §3.4), number the chunks 1, 2, 3, … instead: correctness then needs no condition on β.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Drains #

                                              Are a and b the two targets of one running drain?

                                              Equations
                                              Instances For

                                                Test whether two node indices belong to the same active drain.

                                                Equations
                                                Instances For

                                                  startDrain's greedy cut: the length of the longest prefix of ws with sum at most budget.

                                                  Equations
                                                  Instances For
                                                    def OrderMaintenance.Model.shiftR (pr : Nat → Bool) (n : Nat) :
                                                    Nat → Nat → Nat

                                                    Move the cut k right while children k - 1, k form a pair (pr k), at most f times.

                                                    Equations
                                                    Instances For

                                                      Move the cut k left while children k - 1, k form a pair, at most f times.

                                                      Equations
                                                      Instances For
                                                        def OrderMaintenance.Model.sidesOf (order : List Nat) (boundary : Nat) :

                                                        The side of every entry of order: left before boundary, right from it on.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          A ghost entry takes the side of its first target; none if that target has no side.

                                                          Equations
                                                          Instances For

                                                            A fresh table: the entries part with evenly spaced labels.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Add table t to the tables of entry e (height h).

                                                              Equations
                                                              Instances For

                                                                Insert v1 right before and v2 right after v in table T, with labels a, b.

                                                                Equations
                                                                Instances For

                                                                  Make w the live parent of entry e (height h - 1).

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For
                                                                    def OrderMaintenance.Model.drainCut (ws : List Nat) (pr : Nat → Bool) (hh : Bool) :

                                                                    startDrain's cut of the children with weights ws: the greedy cut k0, then (hh, above height 1) moved so as not to separate a pair (pr k: children k - 1, k are a drain's targets).

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      The weight startDrain gives child e of a node of height h.

                                                                      Equations
                                                                      Instances For

                                                                        Children k - 1, k are the targets of one drain.

                                                                        Equations
                                                                        Instances For

                                                                          The entries of V's table that move to the new nodes: chunks, children, and ghosts with a range.

                                                                          Equations
                                                                          Instances For

                                                                            The side of every entry of V's table: by position from boundary, a ghost then taking the side of its first target.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For

                                                                              Begin a balanced node drain without separating an active drain’s targets.

                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For

                                                                                Remove ghost v from the tables of entry e (height h).

                                                                                Equations
                                                                                Instances For

                                                                                  Remove ghost v from table T.

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    Release target t of ghost v.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For

                                                                                      Finish a node drain and install the replacement nodes and their links.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For

                                                                                        The entry below chunk y in a table of height h.

                                                                                        Equations
                                                                                        Instances For

                                                                                          Move one chunk off ghost v. Returns false when v is fully drained.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For

                                                                                            Insertion jobs #

                                                                                            The guarded, read-only part of insertAround: labels for the new neighbours y, z of x in every table holding x, the tags of y and z, and x's live parent.

                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For

                                                                                              A new chunk c joins the tables tabs and the live parent lp; its path is copied later.

                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              Instances For
                                                                                                def OrderMaintenance.Model.insertAroundFinish (x y z : Nat) (tabs ly lz : List Nat) (lp : Nat) :

                                                                                                The rest of insertAround, in the top structure only: table entries, paths, children.

                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                Instances For

                                                                                                  The O(1) part of a top insertion: y, z are linked before/after x in the chunk list. The tags are written first (the prototype writes them last; only failure states differ, and FALLBACK discards those); y and z are not neighbours, so the second guard is unaffected by the first write. Returns the job that does the rest.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For
                                                                                                    def OrderMaintenance.Model.fundLoop (j : Job) (v up src k : Nat) :

                                                                                                    The sweep funding loop of v, resumed after k sweep steps.

                                                                                                    Equations
                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                    Instances For

                                                                                                      Resume a reservation job after starting a drain, funding its source when needed.

                                                                                                      Equations
                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                      Instances For

                                                                                                        The body of the upward walk at node v, up to its next suspension point.

                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        Instances For

                                                                                                          Resume a job until its next suspension point (some), or to its end (none).

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For