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₁ : Std.HashMap α β
- map₂ : Lean.PHashMap α β
Instances For
@[inline]
def
Lean.SMap.fromHashMap
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
(m : Std.HashMap α β)
(stage₁ : Bool := true)
:
Lean.SMap α β
Equations
- Lean.SMap.fromHashMap m stage₁ = { stage₁ := stage₁, map₁ := m, map₂ := { root := Lean.PersistentHashMap.Node.entries Lean.PersistentHashMap.mkEmptyEntriesArray } }
Instances For
@[specialize #[]]
Equations
Instances For
@[specialize #[]]
Equations
Instances For
@[specialize #[]]
Equations
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
- s.forM f = do Std.HashMap.forM f s.map₁ Lean.PersistentHashMap.forM s.map₂ f
Instances For
def
Lean.SMap.foldM
{α : Type u}
{β : Type v}
[BEq α]
[Hashable α]
{σ : Type w}
{m : Type w → Type w}
[Monad m]
(f : σ → α → β → m σ)
(init : σ)
(map : Lean.SMap α β)
:
m σ
Monadic fold over a staged map.
Equations
- Lean.SMap.foldM f init map = do let __do_lift ← Std.HashMap.foldM f init map.map₁ Lean.PersistentHashMap.foldlM map.map₂ f __do_lift
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 (Std.HashMap.fold f init m.map₁)
Instances For
Equations
- m.numBuckets = Std.HashMap.Internal.numBuckets m.map₁