inductive
Std.PersistentHashMap.Entry
(α : Type u)
(β : Type v)
(σ : Type w)
:
Type (max (max u v) w)
- entry: {α : Type u} → {β : Type v} → {σ : Type w} → α → β → Std.PersistentHashMap.Entry α β σ
- ref: {α : Type u} → {β : Type v} → {σ : Type w} → σ → Std.PersistentHashMap.Entry α β σ
- null: {α : Type u} → {β : Type v} → {σ : Type w} → Std.PersistentHashMap.Entry α β σ
instance
Std.PersistentHashMap.instInhabitedEntry
{α : Type u_1}
{β : Type u_2}
{σ : Type u_3}
:
Inhabited (Std.PersistentHashMap.Entry α β σ)
Equations
- Std.PersistentHashMap.instInhabitedEntry = { default := Std.PersistentHashMap.Entry.null }
- entries: {α : Type u} → {β : Type v} → Array (Std.PersistentHashMap.Entry α β (Std.PersistentHashMap.Node α β)) → Std.PersistentHashMap.Node α β
- collision: {α : Type u} → {β : Type v} → (ks : Array α) → (vs : Array β) → Array.size ks = Array.size vs → Std.PersistentHashMap.Node α β
Equations
- Std.PersistentHashMap.instInhabitedNode = { default := Std.PersistentHashMap.Node.entries #[] }
@[inline]
Equations
@[inline]
@[inline]
Equations
@[inline]
Equations
Equations
- Std.PersistentHashMap.mkEmptyEntriesArray = mkArray (USize.toNat Std.PersistentHashMap.branching) Std.PersistentHashMap.Entry.null
structure
Std.PersistentHashMap
(α : Type u)
(β : Type v)
[inst : BEq α]
[inst : Hashable α]
:
Type (max u v)
- root : Std.PersistentHashMap.Node α β
- size : Nat
@[inline]
Equations
- Std.PHashMap α β = Std.PersistentHashMap α β
Equations
- Std.PersistentHashMap.empty = { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }
def
Std.PersistentHashMap.isEmpty
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
[inst : Hashable α]
(m : Std.PersistentHashMap α β)
:
Equations
- Std.PersistentHashMap.isEmpty m = (m.size == 0)
instance
Std.PersistentHashMap.instInhabitedPersistentHashMap
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
[inst : Hashable α]
:
Equations
- Std.PersistentHashMap.instInhabitedPersistentHashMap = { default := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }
Equations
- Std.PersistentHashMap.mkEmptyEntries = Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray
@[inline]
Equations
- Std.PersistentHashMap.mul2Shift i shift = USize.shiftLeft i shift
@[inline]
Equations
- Std.PersistentHashMap.div2Shift i shift = USize.shiftRight i shift
@[inline]
Equations
- Std.PersistentHashMap.mod2Shift i shift = USize.land i (USize.shiftLeft 1 shift - 1)
inductive
Std.PersistentHashMap.IsCollisionNode
{α : Type u_1}
{β : Type u_2}
:
Std.PersistentHashMap.Node α β → Prop
- mk: ∀ {α : Type u_1} {β : Type u_2} (keys : Array α) (vals : Array β) (h : Array.size keys = Array.size vals), Std.PersistentHashMap.IsCollisionNode (Std.PersistentHashMap.Node.collision keys vals h)
@[inline]
Equations
inductive
Std.PersistentHashMap.IsEntriesNode
{α : Type u_1}
{β : Type u_2}
:
Std.PersistentHashMap.Node α β → Prop
- mk: ∀ {α : Type u_1} {β : Type u_2} (entries : Array (Std.PersistentHashMap.Entry α β (Std.PersistentHashMap.Node α β))), Std.PersistentHashMap.IsEntriesNode (Std.PersistentHashMap.Node.entries entries)
@[inline]
Equations
partial def
Std.PersistentHashMap.insertAtCollisionNodeAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.CollisionNode α β → Nat → α → β → Std.PersistentHashMap.CollisionNode α β
def
Std.PersistentHashMap.insertAtCollisionNode
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.CollisionNode α β → α → β → Std.PersistentHashMap.CollisionNode α β
Equations
Equations
- Std.PersistentHashMap.getCollisionNodeSize x = match x with | { val := Std.PersistentHashMap.Node.collision keys x x_1, property := x_2 } => Array.size keys | { val := Std.PersistentHashMap.Node.entries x, property := h } => False.elim (_ : False)
def
Std.PersistentHashMap.mkCollisionNode
{α : Type u_1}
{β : Type u_2}
(k₁ : α)
(v₁ : β)
(k₂ : α)
(v₂ : β)
:
Equations
- Std.PersistentHashMap.mkCollisionNode k₁ v₁ k₂ v₂ = let ks := Array.mkEmpty Std.PersistentHashMap.maxCollisions; let ks := Array.push (Array.push ks k₁) k₂; let vs := Array.mkEmpty Std.PersistentHashMap.maxCollisions; let vs := Array.push (Array.push vs v₁) v₂; Std.PersistentHashMap.Node.collision ks vs (_ : Array.size (Array.push (Array.push (Array.mkEmpty Std.PersistentHashMap.maxCollisions) k₁) k₂) = Array.size (Array.push (Array.push (Array.mkEmpty Std.PersistentHashMap.maxCollisions) k₁) k₂))
partial def
Std.PersistentHashMap.insertAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
[inst : Hashable α]
:
Std.PersistentHashMap.Node α β → USize → USize → α → β → Std.PersistentHashMap.Node α β
partial def
Std.PersistentHashMap.insertAux.traverse
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
[inst : Hashable α]
(depth : USize)
(keys : Array α)
(vals : Array β)
(heq : Array.size keys = Array.size vals)
(i : Nat)
(entries : Std.PersistentHashMap.Node α β)
:
def
Std.PersistentHashMap.insert
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → β → Std.PersistentHashMap α β
Equations
- Std.PersistentHashMap.insert x x x = match x, x, x with | { root := n, size := sz }, k, v => { root := Std.PersistentHashMap.insertAux n (UInt64.toUSize (hash k)) 1 k v, size := sz + 1 }
partial def
Std.PersistentHashMap.findAtAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
(keys : Array α)
(vals : Array β)
(heq : Array.size keys = Array.size vals)
(i : Nat)
(k : α)
:
Option β
partial def
Std.PersistentHashMap.findAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.Node α β → USize → α → Option β
def
Std.PersistentHashMap.find?
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → Option β
Equations
- Std.PersistentHashMap.find? x x = match x, x with | { root := n, size := x }, k => Std.PersistentHashMap.findAux n (UInt64.toUSize (hash k)) k
@[inline]
def
Std.PersistentHashMap.getOp
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → Option β
Equations
- Std.PersistentHashMap.getOp self idx = Std.PersistentHashMap.find? self idx
@[inline]
def
Std.PersistentHashMap.findD
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → β → β
Equations
- Std.PersistentHashMap.findD m a b₀ = Option.getD (Std.PersistentHashMap.find? m a) b₀
@[inline]
def
Std.PersistentHashMap.find!
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → [inst : Inhabited β] → Std.PersistentHashMap α β → α → β
Equations
- Std.PersistentHashMap.find! m a = match Std.PersistentHashMap.find? m a with | some b => b | none => panicWithPosWithDecl "Std.Data.PersistentHashMap" "Std.PersistentHashMap.find!" 158 14 "key is not in the map"
partial def
Std.PersistentHashMap.findEntryAtAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
(keys : Array α)
(vals : Array β)
(heq : Array.size keys = Array.size vals)
(i : Nat)
(k : α)
:
partial def
Std.PersistentHashMap.findEntryAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.Node α β → USize → α → Option (α × β)
def
Std.PersistentHashMap.findEntry?
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → Option (α × β)
Equations
- Std.PersistentHashMap.findEntry? x x = match x, x with | { root := n, size := x }, k => Std.PersistentHashMap.findEntryAux n (UInt64.toUSize (hash k)) k
partial def
Std.PersistentHashMap.containsAtAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
(keys : Array α)
(vals : Array β)
(heq : Array.size keys = Array.size vals)
(i : Nat)
(k : α)
:
partial def
Std.PersistentHashMap.containsAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.Node α β → USize → α → Bool
def
Std.PersistentHashMap.contains
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
[inst : Hashable α]
:
Std.PersistentHashMap α β → α → Bool
Equations
- Std.PersistentHashMap.contains x x = match x, x with | { root := n, size := x }, k => Std.PersistentHashMap.containsAux n (UInt64.toUSize (hash k)) k
partial def
Std.PersistentHashMap.isUnaryEntries
{α : Type u_1}
{β : Type u_2}
(a : Array (Std.PersistentHashMap.Entry α β (Std.PersistentHashMap.Node α β)))
(i : Nat)
(acc : Option (α × β))
:
def
Std.PersistentHashMap.isUnaryNode
{α : Type u_1}
{β : Type u_2}
:
Std.PersistentHashMap.Node α β → Option (α × β)
Equations
- Std.PersistentHashMap.isUnaryNode x = match x with | Std.PersistentHashMap.Node.entries entries => Std.PersistentHashMap.isUnaryEntries entries 0 none | Std.PersistentHashMap.Node.collision keys vals heq => if h : 1 = Array.size keys then let_fun this := (_ : 0 < Array.size keys); some (Array.get keys { val := 0, isLt := this }, Array.get vals { val := 0, isLt := (_ : 0 < Array.size vals) }) else none
partial def
Std.PersistentHashMap.eraseAux
{α : Type u_1}
{β : Type u_2}
[inst : BEq α]
:
Std.PersistentHashMap.Node α β → USize → α → Std.PersistentHashMap.Node α β × Bool
def
Std.PersistentHashMap.erase
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → α → Std.PersistentHashMap α β
Equations
- Std.PersistentHashMap.erase x x = match x, x with | { root := n, size := sz }, k => let h := UInt64.toUSize (hash k); let x := Std.PersistentHashMap.eraseAux n h k; match x with | (n, del) => { root := n, size := if del = true then sz - 1 else sz }
@[specialize]
partial def
Std.PersistentHashMap.foldlMAux
{m : Type w → Type w'}
[inst : Monad m]
{σ : Type w}
{α : Type u_1}
{β : Type u_2}
(f : σ → α → β → m σ)
:
Std.PersistentHashMap.Node α β → σ → m σ
partial def
Std.PersistentHashMap.foldlMAux.traverse
{m : Type w → Type w'}
[inst : Monad m]
{σ : Type w}
{α : Type u_1}
{β : Type u_2}
(f : σ → α → β → m σ)
(keys : Array α)
(vals : Array β)
(heq : Array.size keys = Array.size vals)
(i : Nat)
(acc : σ)
:
m σ
@[specialize]
def
Std.PersistentHashMap.foldlM
{m : Type w → Type w'}
[inst : Monad m]
{σ : Type w}
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → (σ → α → β → m σ) → σ → m σ
Equations
- Std.PersistentHashMap.foldlM map f init = Std.PersistentHashMap.foldlMAux f map.root init
@[specialize]
def
Std.PersistentHashMap.forM
{m : Type w → Type w'}
[inst : Monad m]
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → (α → β → m PUnit) → m PUnit
Equations
- Std.PersistentHashMap.forM map f = Std.PersistentHashMap.foldlM map (fun x => f) PUnit.unit
@[specialize]
def
Std.PersistentHashMap.foldl
{σ : Type w}
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → (σ → α → β → σ) → σ → σ
Equations
- Std.PersistentHashMap.foldl map f init = Id.run (Std.PersistentHashMap.foldlM map f init)
def
Std.PersistentHashMap.toList
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → List (α × β)
Equations
- Std.PersistentHashMap.toList m = Std.PersistentHashMap.foldl m (fun ps k v => (k, v) :: ps) []
def
Std.PersistentHashMap.stats
{α : Type u_1}
{β : Type u_2}
:
{x : BEq α} → {x_1 : Hashable α} → Std.PersistentHashMap α β → Std.PersistentHashMap.Stats
Equations
- Std.PersistentHashMap.stats m = Std.PersistentHashMap.collectStats m.root { numNodes := 0, numNull := 0, numCollisions := 0, maxDepth := 0 } 1