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 valuenonewould 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 α β
Imported constants.
- map₂ : PHashMap α β
Local constants defined in the current module.
Instances For
@[inline]
def Lean.SMap.fromHashMap {α : Type u} {β : Type v} [BEq α] [Hashable α] (m : Std.HashMap α β) (stage₁ : Bool := true) :
SMap α β
Equations
- Lean.SMap.fromHashMap m stage₁ = { stage₁ := stage₁, map₁ := m }
Instances For
@[specialize #[]]
Equations
Instances For
@[specialize #[]]
Equations
Instances For
@[specialize #[]]
Equations
Instances For
@[specialize #[]]
Equations
Instances For
@[inline]
def Lean.SMap.foldStage2 {α : Type u} {β : Type v} [BEq α] [Hashable α] {σ : Type w} (f : σ → α → β → σ) (s : σ) (m : SMap α β) :
σ
Equations
- Lean.SMap.foldStage2 f s m = Lean.PersistentHashMap.foldl m.map₂ f s
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 : 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 : SMap α β) :
σ
Equations
- Lean.SMap.fold f init m = Lean.PersistentHashMap.foldl m.map₂ f (Std.HashMap.fold f init m.map₁)
Instances For
Equations
Instances For
@[instance_reducible]
instance Lean.instReprSMap {α : Type u_1} {β : Type u_2} {x✝ : BEq α} {x✝¹ : Hashable α} [Repr α] [Repr β] :
Equations
- Lean.instReprSMap = { reprPrec := fun (v : Lean.SMap α β) (prec : Nat) => Repr.addAppParen (reprArg v.toList ++ Std.Format.text ".toSMap") prec }