Documentation

LeanPool.OrderMaintenance.Impl.PQ

M6: the priority queue in the core language (Model/PQ.lean) #

Capacities #

The queue's arrays are indexed by chunk (pqNext, pqPrev, pqWhere: capacity κ.arr .pqNext) or by bucket (pqHead, nbNext, nbPrev: capacity κ.arr .pqHead), and hold chunks or buckets. PQCaps says every stored value fits.

@[reducible, inline]

Capacity shared by the priority queue's chunk-indexed arrays.

Equations
Instances For
    @[reducible, inline]

    Capacity shared by the priority queue's bucket-indexed arrays.

    Equations
    Instances For

      Compatible queue-array capacities covering every allocated chunk and bucket.

      Instances For
        theorem OrderMaintenance.Impl.getX_setX_lt {a : Array ℕ} {i v B : ℕ} (ha : ∀ (j : ℕ), a.getX j < B) (hv : v < B) (j : ℕ) :
        (a.setX i v).getX j < B
        theorem OrderMaintenance.Impl.PQCaps.sNext {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Ccap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext.setX i v, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sPrev {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Ccap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev.setX i v, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sHead {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Ccap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead.setX i v, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sWhere {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Bcap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere.setX i v, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sNbN {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Bcap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext.setX i v, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sNbP {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {i v : ℕ} (hv : v < Bcap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev.setX i v, pqHi := σ.pqHi, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sLo {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {v : ℕ} (hv : v < Bcap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := σ.pqHi, pqLo := v, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }
        theorem OrderMaintenance.Impl.PQCaps.sHi {κ : Caps} {σ : Model.Core} (h : PQCaps κ σ) {v : ℕ} (hv : v < Bcap κ) :
        PQCaps κ { P := σ.P, E := σ.E, Gs := σ.Gs, C := σ.C, freeG := σ.freeG, count := σ.count, head := σ.head, tail := σ.tail, firstGroup := σ.firstGroup, firstChunk := σ.firstChunk, ready := σ.ready, prep := σ.prep, resJob := σ.resJob, fallbacks := σ.fallbacks, pqHead := σ.pqHead, pqNext := σ.pqNext, pqPrev := σ.pqPrev, pqWhere := σ.pqWhere, nbNext := σ.nbNext, nbPrev := σ.nbPrev, pqHi := v, pqLo := σ.pqLo, nodes := σ.nodes, path := σ.path, cin := σ.cin, lpar := σ.lpar }

        Prove PQCaps κ σ' for a state obtained from σ (with hq : PQCaps κ σ) by bounded writes.

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

          Procedure linking a newly nonempty bucket after its predecessor.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem OrderMaintenance.Impl.pqLinkAfter_agree (κ : Caps) (σ : Model.Core) (L : Loc) {s p : ℕ} (hs : L "s" = s) (hp : L "p" = p) (hq : PQCaps κ σ) (hsB : s < Bcap κ) (hpB : p < Bcap κ) {σ' : Model.Core} (h : EStateM.run (Model.pqLinkAfter s p) σ = EStateM.Result.ok () σ') :
            (∃ (L' : Loc), ∃ (c : ℕ), evalF κ pqLinkAfterP.body σ L = Res.ok σ' L' c ∧ c ≤ 60) ∧ PQCaps κ σ'

            Procedure inserting a chunk at the head of a size bucket.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem OrderMaintenance.Impl.pqAdd_agree (κ : Caps) (σ : Model.Core) (L : Loc) {c s p : ℕ} (hc : L "c" = c) (hs : L "s" = s) (hp : L "p" = p) (hq : PQCaps κ σ) (hcC : c < Ccap κ) (hsB : s < Bcap κ) (hpB : p < Bcap κ) {σ' : Model.Core} (h : EStateM.run (Model.pqAdd c s p) σ = EStateM.Result.ok () σ') :
              (∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqAddP.body σ L = Res.ok σ' L' n ∧ n ≤ 140) ∧ PQCaps κ σ'

              Procedure removing a chunk and unlinking its bucket when it becomes empty.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem OrderMaintenance.Impl.pqDel_agree (κ : Caps) (σ : Model.Core) (L : Loc) {c : ℕ} (hc : L "c" = c) (hq : PQCaps κ σ) (hcC : c < Ccap κ) {σ' : Model.Core} (h : EStateM.run (Model.pqDel c) σ = EStateM.Result.ok () σ') :
                (∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqDelP.body σ L = Res.ok σ' L' n ∧ n ≤ 200) ∧ PQCaps κ σ'

                Insert c at bucket s. The downward scan for the predecessor bucket (Level F's slow path) runs only if bucket s - 1 is above θ and empty; it is never needed (K2), and costs O(s).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem OrderMaintenance.Impl.pqInsertScan_agree (κ : Caps) (σ : Model.Core) (L : Loc) {c s : ℕ} (hc : L "c" = c) (hs : L "s" = s) (hq : PQCaps κ σ) (hcC : c < Ccap κ) (hsB : s < Bcap κ) (hfast : ¬(σ.P.theta < s - 1 ∧ σ.pqHead.getX (s - 1) = 0)) {σ' : Model.Core} (h : EStateM.run (Model.pqInsertScan c s) σ = EStateM.Result.ok () σ') :
                  (∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqInsertScanP.body σ L = Res.ok σ' L' n ∧ n ≤ 250) ∧ PQCaps κ σ'

                  pqInsertScan when no scan is needed.

                  Procedure transferring a queued chunk after its size changes.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem OrderMaintenance.Impl.pqAdjust_agree (κ : Caps) (σ : Model.Core) (L : Loc) {c old : ℕ} (hc : L "c" = c) (ho : L "old" = old) (hn : L "new" = old + 1) (hq : PQCaps κ σ) (hcC : c < Ccap κ) (hnB : old + 1 < Bcap κ) {σ' : Model.Core} (h : EStateM.run (Model.pqAdjust c old (old + 1)) σ = EStateM.Result.ok () σ') :
                    (∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqAdjustP.body σ L = Res.ok σ' L' n ∧ n ≤ 700) ∧ PQCaps κ σ'

                    pqAdjust for a +1 change of size (the only one the algorithm makes).

                    Procedure queuing a chunk when its size exceeds the quiet threshold.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem OrderMaintenance.Impl.pqEnterIfAbove_agree (κ : Caps) (σ : Model.Core) (L : Loc) {c : ℕ} (hc : L "c" = c) (hcT : c < κ.tbl Tbl.C) (hle : (σ.C.getX c).size ≤ σ.P.theta) {σ' : Model.Core} (h : EStateM.run (Model.pqEnterIfAbove c) σ = EStateM.Result.ok () σ') :
                      ∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqEnterIfAboveP.body σ L = Res.ok σ' L' n ∧ n ≤ 20

                      pqEnterIfAbove for a chunk not above θ (every freshly quiet chunk: c_max ≤ θ).

                      Procedure removing and returning a chunk from the largest nonempty bucket.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem OrderMaintenance.Impl.pqPopMax_agree (κ : Caps) (σ : Model.Core) (L : Loc) (hq : PQCaps κ σ) {c : ℕ} {σ' : Model.Core} (h : EStateM.run Model.pqPopMax σ = EStateM.Result.ok c σ') :
                        (∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqPopMaxP.body σ L = Res.ok σ' L' n ∧ L' "c" = c ∧ n ≤ 240) ∧ PQCaps κ σ'

                        Procedure reporting whether every priority-queue bucket is empty.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem OrderMaintenance.Impl.pqEmpty_agree (κ : Caps) (σ : Model.Core) (L : Loc) {b : Bool} {σ' : Model.Core} (h : EStateM.run Model.pqEmpty σ = EStateM.Result.ok b σ') :
                          ∃ (L' : Loc), ∃ (n : ℕ), evalF κ pqEmptyP.body σ L = Res.ok σ' L' n ∧ L' "r" = b2n b ∧ n ≤ 10