Expand description
Inlean.Map: a hash map for Lean code, kept in a Rust HashMap.
In Lean the map is defined by a model: a list of entries in insertion order, searched
with the key type’s ==. This module is the implementation the compiled code runs
instead, and it must agree with the model on every operation. Two things make that
possible. Entries are kept in insertion order, so listing the map has one defined
result. And the index is keyed by Lean’s hash of a key and searched with Lean’s ==,
both called through the instances the Lean code passes in, so “the same key” means here
what it means in the model. A lawful hash (a == b → hash a = hash b, which the Lean
side requires) guarantees that a key is always found in its own bucket.
Functions§
- empty
- The empty map.
- entries⚠
- The entries of a map, for a caller that owns nothing: each key and value is borrowed.
- erase⚠
mwithout the entries whose key equalskey. Consumesm; borrows the rest.- filter⚠
mwith only the entries for whichkeep key valueis true. Consumesm; borrows the function.- get_opt⚠
- The value bound to a key equal to
key, as anOption. Borrows everything. - insert⚠
mwithkeybound tovalue. An entry whose key equalskeyis replaced where it is, key included; otherwise the entry is added at the end. Consumesm,keyandvalue; borrows the instances.- map_
values ⚠ - A map with the keys of
m, in the same order, each bound tof key value. Borrows both arguments. - size⚠
- The number of entries, as a
Nat. - to_list⚠
- The entries in insertion order, as a
List (κ × α). Borrowsm.