Documentation

CslibFrontier.DataStructure.BTree.NodeAccess.Basic

External-memory node-access oracle model for classic B-trees #

Read-only classic B-tree queries in an external-memory / page-read oracle model built on PFunctor.FreeM. A tree is never passed as an inductive BTree α β value to a query program: instead, a reference is Option H over an abstract handle type H, where none represents an empty leaf without issuing a page read and some h can be inspected only by issuing a readNode h query against a stateless Store α β H oracle.

Counting is structural via PFunctor.FreeM.countQueries: no program parametric in H can inspect a node's keys or child handles without paying 1 query per node read. For order-statistic rankR queries, which skip subtrees in O(height) page reads without reading skipped child pages, RankedNodeView augments each child reference in a page with its subtree entry count (RankedStore, DenotesRanked), paired with a forgetful projection RankedStore.toStore to the unaugmented store.

Main definitions #

Main results #

References #

Entry in an unaugmented B-tree node page: separator key, associated val, and following child reference (none for an empty leaf).

  • key : α

    Separator key.

  • val : β

    Associated value.

  • child : Option H

    Handle reference to the child subtree following key.

Instances For
    def Cslib.DataStructure.BTree.NodeAccess.instDecidableEqPageEntry.decEq {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] (x✝ x✝¹ : PageEntry α✝ β✝ H✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    instance Cslib.DataStructure.BTree.NodeAccess.instDecidableEqPageEntry {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] :
    DecidableEq (PageEntry α✝ β✝ H✝)
    def Cslib.DataStructure.BTree.NodeAccess.instReprPageEntry.repr {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
    PageEntry α✝ β✝ H✝ → ℕ → Std.Format
    @[instance_reducible]
    instance Cslib.DataStructure.BTree.NodeAccess.instReprPageEntry {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
    Repr (PageEntry α✝ β✝ H✝)

    Contents of one B-tree node page: the first child reference followed by rest page entries, where none represents an empty leaf.

    • first : Option H

      Handle reference to the subtree preceding all separator keys.

    • rest : List (PageEntry α β H)

      Ordered (key, val, child) entries of the node page.

    Instances For
      @[instance_reducible]
      instance Cslib.DataStructure.BTree.NodeAccess.instDecidableEqNodeView {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] :
      DecidableEq (NodeView α✝ β✝ H✝)
      def Cslib.DataStructure.BTree.NodeAccess.instDecidableEqNodeView.decEq {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] (x✝ x✝¹ : NodeView α✝ β✝ H✝) :
      Decidable (x✝ = x✝¹)
      @[instance_reducible]
      instance Cslib.DataStructure.BTree.NodeAccess.instReprNodeView {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
      Repr (NodeView α✝ β✝ H✝)
      def Cslib.DataStructure.BTree.NodeAccess.instReprNodeView.repr {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
      NodeView α✝ β✝ H✝ → ℕ → Std.Format
      @[reducible, inline]

      Polynomial query signature reading one node page by its handle h : H.

      @[reducible, inline]

      Read-only external-memory computation over nodeQuery α β H.

      @[reducible, inline]

      Stateless page store mapping each handle to its NodeView.

      def Cslib.DataStructure.BTree.NodeAccess.readNode {α β H : Type} (h : H) :
      NodeM α β H (NodeView α β H)

      Issue one page-read query for handle h : H.

      @[simp]
      theorem Cslib.DataStructure.BTree.NodeAccess.eval_readNode {α β H : Type} (s : Store α β H) (h : H) :
      @[irreducible]
      def Cslib.DataStructure.BTree.NodeAccess.Denotes {α β H : Type} (s : Store α β H) :
      Option H → BTree α β → Prop

      Denotes s ref tr holds when optional handle ref in store s represents tr : BTree α β.

      @[irreducible]
      def Cslib.DataStructure.BTree.NodeAccess.DenotesRest {α β H : Type} (s : Store α β H) :
      List (PageEntry α β H) → List (Triple α β) → Prop

      Entry-by-entry denotation of a node page's PageEntry list.

      @[simp]
      theorem Cslib.DataStructure.BTree.NodeAccess.denotes_none_node {α β H : Type} (s : Store α β H) (first : BTree α β) (rest : List (Triple α β)) :
      ¬Denotes s none (first.node rest)
      @[simp]
      theorem Cslib.DataStructure.BTree.NodeAccess.denotes_some_leaf {α β H : Type} (s : Store α β H) (h : H) :
      theorem Cslib.DataStructure.BTree.NodeAccess.denotes_some_node_iff {α β H : Type} (s : Store α β H) (h : H) (first : BTree α β) (rest : List (Triple α β)) :
      Denotes s (some h) (first.node rest) ↔ Denotes s (s h).first first ∧ DenotesRest s (s h).rest rest
      @[simp]
      theorem Cslib.DataStructure.BTree.NodeAccess.denotesRest_nil_cons {α β H : Type} (s : Store α β H) (e : Triple α β) (rest : List (Triple α β)) :
      ¬DenotesRest s [] (e :: rest)
      @[simp]
      theorem Cslib.DataStructure.BTree.NodeAccess.denotesRest_cons_nil {α β H : Type} (s : Store α β H) (e : PageEntry α β H) (rs : List (PageEntry α β H)) :
      theorem Cslib.DataStructure.BTree.NodeAccess.denotesRest_cons_cons_iff {α β H : Type} (s : Store α β H) (k k' : α) (v v' : β) (r : Option H) (c : BTree α β) (rs : List (PageEntry α β H)) (rest : List (Triple α β)) :
      DenotesRest s ({ key := k, val := v, child := r } :: rs) ((k', v', c) :: rest) ↔ k = k' ∧ v = v' ∧ Denotes s r c ∧ DenotesRest s rs rest
      theorem Cslib.DataStructure.BTree.NodeAccess.Denotes.eq_leaf_of_none {α β H : Type} {s : Store α β H} {tr : BTree α β} (hd : Denotes s none tr) :
      tr = leaf
      theorem Cslib.DataStructure.BTree.NodeAccess.DenotesRest.length_eq {α β H : Type} {s : Store α β H} {rs : List (PageEntry α β H)} {rest : List (Triple α β)} (hd : DenotesRest s rs rest) :
      rs.length = rest.length

      Canonical reference for a pure BTree α β when handles are non-leaf subtrees (H := BTree α β).

      Canonical page store mapping each BTree α β handle to its top-level children and keys.

      Every BTree α β is denoted in canonicalStore by toRef tr.

      Child reference in an order-statistic B-tree page: optional child handle ref paired with its subtree entry count subSize (0 at an empty leaf).

      • ref : Option H

        Optional child handle (none for an empty leaf).

      • subSize : ℕ

        Number of entries in the child subtree.

      Instances For
        @[instance_reducible]

        Entry in an order-statistic B-tree node page: separator key, associated val, and following RankedChild slot.

        • key : α

          Separator key.

        • val : β

          Associated value.

        • child : RankedChild H

          Following child reference and its subtree entry count.

        Instances For
          def Cslib.DataStructure.BTree.NodeAccess.instDecidableEqRankedPageEntry.decEq {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] (x✝ x✝¹ : RankedPageEntry α✝ β✝ H✝) :
          Decidable (x✝ = x✝¹)
          @[instance_reducible]
          @[instance_reducible]
          instance Cslib.DataStructure.BTree.NodeAccess.instReprRankedPageEntry {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
          Repr (RankedPageEntry α✝ β✝ H✝)
          def Cslib.DataStructure.BTree.NodeAccess.instReprRankedPageEntry.repr {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
          RankedPageEntry α✝ β✝ H✝ → ℕ → Std.Format

          Contents of one order-statistic B-tree node page: first RankedChild and rest RankedPageEntry records.

          • first : RankedChild H

            First child reference and its subtree entry count.

          • rest : List (RankedPageEntry α β H)

            Ordered (key, val, child) entries of the order-statistic page.

          Instances For
            @[instance_reducible]
            def Cslib.DataStructure.BTree.NodeAccess.instDecidableEqRankedNodeView.decEq {α✝ β✝ H✝ : Type} [DecidableEq α✝] [DecidableEq β✝] [DecidableEq H✝] (x✝ x✝¹ : RankedNodeView α✝ β✝ H✝) :
            Decidable (x✝ = x✝¹)
            @[instance_reducible]
            instance Cslib.DataStructure.BTree.NodeAccess.instReprRankedNodeView {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
            Repr (RankedNodeView α✝ β✝ H✝)
            def Cslib.DataStructure.BTree.NodeAccess.instReprRankedNodeView.repr {α✝ β✝ H✝ : Type} [Repr α✝] [Repr β✝] [Repr H✝] :
            RankedNodeView α✝ β✝ H✝ → ℕ → Std.Format
            @[reducible, inline]

            Polynomial query signature reading one order-statistic B-tree node page by handle h : H.

            @[reducible, inline]

            Read-only external-memory computation over rankedNodeQuery α β H.

            @[reducible, inline]

            Stateless store mapping each handle to an order-statistic RankedNodeView.

            Issue one page-read query for handle h : H in an order-statistic store.

            Forget subtree-size annotations to view a RankedStore as an unaugmented Store.

            @[irreducible]

            DenotesRanked s ref tr holds when optional handle ref in RankedStore s represents tr with exact child subtree sizes recorded at every child slot.

            @[irreducible]

            Entry-by-entry denotation of an order-statistic node page's RankedPageEntry list.

            @[simp]
            theorem Cslib.DataStructure.BTree.NodeAccess.denotesRanked_none_node {α β H : Type} (s : RankedStore α β H) (first : BTree α β) (rest : List (Triple α β)) :
            ¬DenotesRanked s none (first.node rest)
            theorem Cslib.DataStructure.BTree.NodeAccess.denotesRanked_some_node_iff {α β H : Type} (s : RankedStore α β H) (h : H) (first : BTree α β) (rest : List (Triple α β)) :
            DenotesRanked s (some h) (first.node rest) ↔ DenotesRanked s (s h).first.ref first ∧ (s h).first.subSize = first.size ∧ DenotesRankedRest s (s h).rest rest
            @[simp]
            theorem Cslib.DataStructure.BTree.NodeAccess.denotesRankedRest_nil_cons {α β H : Type} (s : RankedStore α β H) (e : Triple α β) (rest : List (Triple α β)) :
            theorem Cslib.DataStructure.BTree.NodeAccess.denotesRankedRest_cons_cons_iff {α β H : Type} (s : RankedStore α β H) (k k' : α) (v v' : β) (rc : RankedChild H) (c : BTree α β) (rs : List (RankedPageEntry α β H)) (rest : List (Triple α β)) :
            DenotesRankedRest s ({ key := k, val := v, child := rc } :: rs) ((k', v', c) :: rest) ↔ k = k' ∧ v = v' ∧ DenotesRanked s rc.ref c ∧ rc.subSize = c.size ∧ DenotesRankedRest s rs rest
            theorem Cslib.DataStructure.BTree.NodeAccess.DenotesRanked.toDenotes {α β H : Type} {s : RankedStore α β H} {ref : Option H} {tr : BTree α β} (hd : DenotesRanked s ref tr) :
            Denotes s.toStore ref tr

            Forgetting subtree-size annotations preserves tree denotation.

            Canonical order-statistic store over H := BTree α β.