M5: the top structure after a drain starts — derived views #
SDCtx bundles the situation; S' is the state after startDrain v, N = v1, N + 1 = v2.
structure
OrderMaintenance.Proof.Top.SDCtx
(s : Model.Core)
(cl : List ℕ)
(ord : ℕ → List ℕ)
(dr n0 : ℕ → ℕ)
(j : Model.Job)
(v : ℕ)
(side : List (ℕ × Model.Side))
:
The situation when a drain of v starts, with the sides startDrain computes.
- look (x : ℕ) : Model.lookup side x = if 2 ≤ Top.ht (ts s) v ∧ x ∈ sEntries (wiC s v) v ∧ (nd (ts s) x).draining = true then Model.lookup (Model.sidesOf (Top.order (ts s) v) ((nd (ts s) v).children.getD (sK (wiC s v) v) 0)) (nd (ts s) x).t1 else Model.lookup (Model.sidesOf (Top.order (ts s) v) ((nd (ts s) v).children.getD (sK (wiC s v) v) 0)) x
Instances For
theorem
OrderMaintenance.Proof.Top.SDCtx.livePar
{s : Model.Core}
{cl : List ℕ}
{ord : ℕ → List ℕ}
{dr n0 : ℕ → ℕ}
{j : Model.Job}
{v : ℕ}
{side : List (ℕ × Model.Side)}
(C : SDCtx s cl ord dr n0 j v side)
(u : ℕ)
:
(nd (ts (sdS (wiC s v) v side)) u).livePar = if u = v then Model.NIL
else if u = s.nodes.size ∨ u = s.nodes.size + 1 then (nd (ts s) v).livePar
else if Top.ht (ts s) v ≠ 1 ∧ u ∈ List.drop (sK (wiC s v) v) (nd (ts s) v).children then s.nodes.size + 1
else if Top.ht (ts s) v ≠ 1 ∧ u ∈ List.take (sK (wiC s v) v) (nd (ts s) v).children then s.nodes.size
else (nd (ts s) u).livePar
theorem
OrderMaintenance.Proof.Top.SDCtx.children
{s : Model.Core}
{cl : List ℕ}
{ord : ℕ → List ℕ}
{dr n0 : ℕ → ℕ}
{j : Model.Job}
{v : ℕ}
{side : List (ℕ × Model.Side)}
(C : SDCtx s cl ord dr n0 j v side)
(u : ℕ)
:
(nd (ts (sdS (wiC s v) v side)) u).children = if u = v then []
else if u = s.nodes.size then List.take (sK (wiC s v) v) (nd (ts s) v).children
else if u = s.nodes.size + 1 then List.drop (sK (wiC s v) v) (nd (ts s) v).children
else if u = (nd (ts s) v).livePar then
(nd (ts s) (nd (ts s) v).livePar).children.replace1 v [s.nodes.size, s.nodes.size + 1]
else (nd (ts s) u).children
theorem
OrderMaintenance.Proof.Top.SDCtx.livePar_old
{s : Model.Core}
{cl : List ℕ}
{ord : ℕ → List ℕ}
{dr n0 : ℕ → ℕ}
{j : Model.Job}
{v : ℕ}
{side : List (ℕ × Model.Side)}
(C : SDCtx s cl ord dr n0 j v side)
{u : ℕ}
(hu : Top.isN (ts s) u)
(huv : u ≠ v)
(hk : Top.ht (ts s) v ≠ 1 → u ∉ (nd (ts s) v).children)
:
A node the drain does not touch keeps its live parent.