Staged map for implementing the Environment. The idea is to store imported entries into a hashtable and local entries into a persistent hashtable.
Hypotheses:
- The number of entries (i.e., declarations) coming from imported files is much bigger than the number of entries in the current file.
- HashMap is faster than PersistentHashMap.
- When we are reading imported files, we have exclusive access to the map, and efficient destructive updates are performed.
Remarks:
- We never remove declarations from the Environment. In principle, we could support
deletion by using
(PHashMap α (Option β))
where the valuenone
would indicate that an entry was "removed" from the hashtable. - We do not need additional bookkeeping for extracting the local entries.
- stage₁ : Bool
- map₁ : Lean.HashMap α β
- map₂ : Lean.PHashMap α β
Instances For
@[inline]
def
Lean.SMap.fromHashMap
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
(m : Lean.HashMap α β)
(stage₁ : optParam Bool true)
:
Lean.SMap α β
Equations
- Lean.SMap.fromHashMap m stage₁ = { stage₁ := stage₁, map₁ := m, map₂ := { root := Lean.PersistentHashMap.Node.entries Lean.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }
Instances For
@[inline]
def
Lean.SMap.findD
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
(m : Lean.SMap α β)
(a : α)
(b₀ : β)
:
β
Equations
- Lean.SMap.findD m a b₀ = Option.getD (Lean.SMap.find? m a) b₀
Instances For
def
Lean.SMap.forM
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
{m : Type u_1 → Type u_1}
[Monad m]
(s : Lean.SMap α β)
(f : α → β → m PUnit)
:
m PUnit
Equations
- Lean.SMap.forM s f = do Lean.HashMap.forM f s.map₁ Lean.PersistentHashMap.forM s.map₂ f
Instances For
@[inline]
def
Lean.SMap.foldStage2
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
{σ : Type w}
(f : σ → α → β → σ)
(s : σ)
(m : Lean.SMap α β)
:
σ
Equations
- Lean.SMap.foldStage2 f s m = Lean.PersistentHashMap.foldl m.map₂ f s
Instances For
def
Lean.SMap.fold
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
{σ : Type w}
(f : σ → α → β → σ)
(init : σ)
(m : Lean.SMap α β)
:
σ
Equations
- Lean.SMap.fold f init m = Lean.PersistentHashMap.foldl m.map₂ f (Lean.HashMap.fold f init m.map₁)
Instances For
Equations
- Lean.SMap.size m = Lean.HashMap.size m.map₁ + m.map₂.size
Instances For
Equations
- Lean.SMap.stageSizes m = (Lean.HashMap.size m.map₁, m.map₂.size)
Instances For
Equations
- Lean.SMap.numBuckets m = Lean.HashMap.numBuckets m.map₁
Instances For
Equations
- Lean.SMap.toList m = Lean.SMap.fold (fun (es : List (α × β)) (a : α) (b : β) => (a, b) :: es) [] m
Instances For
Equations
- Lean.instReprSMap = { reprPrec := fun (v : Lean.SMap α β) (prec : Nat) => Repr.addAppParen (reprArg (Lean.SMap.toList v) ++ Std.Format.text ".toSMap") prec }