Extensional dependent tree maps #
This file develops the type Std.ExtDTreeMap
of extensional dependent tree maps.
Lemmas about the operations on Std.ExtDTreeMap
will be available in the
module Std.Data.ExtDTreeMap.Lemmas
.
See the module Std.Data.DTreeMap.Raw.Basic
for a variant of this type which is safe to use in
nested inductive types.
Extensional dependent tree maps.
A tree map stores an assignment of keys to values. It depends on a comparator function that defines an ordering on the keys and provides efficient order-dependent queries, such as retrieval of the minimum or maximum.
To ensure that the operations behave as expected, the comparator function cmp
should satisfy
certain laws that ensure a consistent ordering:
- If
a
is less than (or equal) tob
, thenb
is greater than (or equal) toa
and vice versa (see theOrientedCmp
typeclass). - If
a
is less than or equal tob
andb
is, in turn, less than or equal toc
, thena
is less than or equal toc
(see theTransCmp
typeclass).
Keys for which cmp a b = Ordering.eq
are considered the same, i.e., there can be only one entry
with key either a
or b
in a tree map. Looking up either a
or b
always yields the same entry,
if any is present. The get
operations of the dependent tree map additionally require a
LawfulEqCmp
instance to ensure that cmp a b = .eq
always implies a = b
, so that their
respective value types are equal.
To avoid expensive copies, users should make sure that the tree map is used linearly.
Internally, the tree maps are represented as size-bounded trees, a type of self-balancing binary search tree with efficient order statistic lookups.
In contrast to regular dependent tree maps, Std.ExtDTreeMap
offers several extensionality lemmas
and therefore has more lemmas about equality of tree maps. This doesn't affect the amount of
supported functions though: Std.ExtDTreeMap
supports all operations from Std.DTreeMap
.
In order to use most functions, a TransCmp
instance is required. This is necessary to make sure
that the functions are congruent, i.e. equivalent tree maps as parameters produce equivalent return
values.
These tree maps contain a bundled well-formedness invariant, which means that they cannot
be used in nested inductive types. For these use cases, Std.DTreeMap.Raw
and
Std.DTreeMap.Raw.WF
unbundle the invariant from the tree map. When in doubt, prefer
ExtDTreeMap
over DTreeMap.Raw
.
- mk' :: (
- inner : Quotient (DTreeMap.isSetoid α β cmp)
Implementation detail of the tree map
- )
Instances For
- Std.ExtDTreeMap.instEmptyCollection
- Std.ExtDTreeMap.instForInSigmaOfTransCmpOfLawfulMonad
- Std.ExtDTreeMap.instForMSigmaOfTransCmpOfLawfulMonad
- Std.ExtDTreeMap.instInhabited
- Std.ExtDTreeMap.instInsertSigmaOfTransCmp
- Std.ExtDTreeMap.instLawfulSingletonSigma
- Std.ExtDTreeMap.instMembershipOfTransCmp
- Std.ExtDTreeMap.instReprOfTransCmp
- Std.ExtDTreeMap.instSingletonSigmaOfTransCmp
Implementation detail of the tree map
Equations
- Std.ExtDTreeMap.mk t = { inner := Quotient.mk (Std.DTreeMap.isSetoid α β cmp) t }
Implementation detail of the tree map
Equations
- Std.ExtDTreeMap.lift f h t = Quotient.lift f h t.inner
Implementation detail of the tree map
Implementation detail of the tree map
Equations
- t.pliftOn f h = t.inner.pliftOn (fun (x : Std.DTreeMap α β cmp) (hx : t.inner = Quotient.mk (Std.DTreeMap.isSetoid α β cmp) x) => f x ⋯) ⋯
Creates a new empty tree map. It is also possible and recommended to
use the empty collection notations ∅
and {}
to create an empty tree map. simp
replaces
empty
with ∅
.
Equations
- Std.ExtDTreeMap.instEmptyCollection = { emptyCollection := Std.ExtDTreeMap.empty }
Equations
- Std.ExtDTreeMap.instInhabited = { default := ∅ }
Inserts the given mapping into the map. If there is already a mapping for the given key, then both key and value will be replaced.
Equations
- t.insert a b = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (m.insert a b)) ⋯ t
Equations
- Std.ExtDTreeMap.instInsertSigmaOfTransCmp = { insert := fun (e : (a : α) × β a) (s : Std.ExtDTreeMap α β cmp) => s.insert e.fst e.snd }
If there is no mapping for the given key, inserts the given mapping into the map. Otherwise, returns the map unaltered.
Equations
- t.insertIfNew a b = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (m.insertIfNew a b)) ⋯ t
Checks whether a key is present in a map and unconditionally inserts a value for the key.
Equivalent to (but potentially faster than) calling contains
followed by insert
.
Equations
- t.containsThenInsert a b = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => have m' := m.containsThenInsert a b; (m'.fst, Std.ExtDTreeMap.mk m'.snd)) ⋯ t
Checks whether a key is present in a map and inserts a value for the key if it was not found.
If the returned Bool
is true
, then the returned map is unaltered. If the Bool
is false
,
then the returned map has a new value inserted.
Equivalent to (but potentially faster than) calling contains
followed by insertIfNew
.
Equations
- t.containsThenInsertIfNew a b = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => have m' := m.containsThenInsertIfNew a b; (m'.fst, Std.ExtDTreeMap.mk m'.snd)) ⋯ t
Checks whether a key is present in a map, returning the associated value, and inserts a value for the key if it was not found.
If the returned value is some v
, then the returned map is unaltered. If it is none
, then the
returned map has a new value inserted.
Equivalent to (but potentially faster than) calling get?
followed by insertIfNew
.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- t.getThenInsertIfNew? a b = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => have m' := m.getThenInsertIfNew? a b; (m'.fst, Std.ExtDTreeMap.mk m'.snd)) ⋯ t
Returns true
if there is a mapping for the given key a
or a key that is equal to a
according
to the comparator cmp
. There is also a Prop
-valued version
of this: a ∈ t
is equivalent to t.contains a = true
.
Observe that this is different behavior than for lists: for lists, ∈
uses =
and contains
uses
==
for equality checks, while for tree maps, both use the given comparator cmp
.
Equations
- t.contains a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.contains a) ⋯ t
Equations
- Std.ExtDTreeMap.instMembershipOfTransCmp = { mem := fun (m : Std.ExtDTreeMap α β cmp) (a : α) => m.contains a = true }
Equations
Returns the number of mappings present in the map.
Equations
- t.size = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.size) ⋯ t
Returns true
if the tree map contains no mappings.
Equations
- t.isEmpty = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.isEmpty) ⋯ t
Removes the mapping for the given key if it exists.
Equations
- t.erase a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (m.erase a)) ⋯ t
Tries to retrieve the mapping for the given key, returning none
if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- t.get? a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.get? a) ⋯ t
Given a proof that a mapping for the given key is present, retrieves the mapping for the given key.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- t.get a h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.get a ⋯) ⋯
Tries to retrieve the mapping for the given key, panicking if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- t.get! a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.get! a) ⋯ t
Tries to retrieve the mapping for the given key, returning fallback
if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- t.getD a fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getD a fallback) ⋯ t
Checks if a mapping for the given key exists and returns the key if it does, otherwise none
.
The result in the some
case is guaranteed to be pointer equal to the key in the map.
Equations
- t.getKey? a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKey? a) ⋯ t
Retrieves the key from the mapping that matches a
. Ensures that such a mapping exists by
requiring a proof of a ∈ m
. The result is guaranteed to be pointer equal to the key in the map.
Equations
- t.getKey a h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getKey a ⋯) ⋯
Checks if a mapping for the given key exists and returns the key if it does, otherwise panics. If no panic occurs the result is guaranteed to be pointer equal to the key in the map.
Equations
- t.getKey! a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKey! a) ⋯ t
Checks if a mapping for the given key exists and returns the key if it does, otherwise fallback
.
If a mapping exists the result is guaranteed to be pointer equal to the key in the map.
Equations
- t.getKeyD a fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyD a fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key in the tree map, returning none
if the
map is empty.
Equations
- t.minEntry? = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minEntry?) ⋯ t
Given a proof that the tree map is not empty, retrieves the key-value pair with the smallest key.
Equations
- t.minEntry h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.minEntry ⋯) ⋯
Tries to retrieve the key-value pair with the smallest key in the tree map, panicking if the map is empty.
Equations
- t.minEntry! = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minEntry!) ⋯ t
Tries to retrieve the key-value pair with the smallest key in the tree map, returning fallback
if
the tree map is empty.
Equations
- t.minEntryD fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minEntryD fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key in the tree map, returning none
if the
map is empty.
Equations
- t.maxEntry? = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxEntry?) ⋯ t
Given a proof that the tree map is not empty, retrieves the key-value pair with the largest key.
Equations
- t.maxEntry h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.maxEntry ⋯) ⋯
Tries to retrieve the key-value pair with the largest key in the tree map, panicking if the map is empty.
Equations
- t.maxEntry! = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxEntry!) ⋯ t
Tries to retrieve the key-value pair with the largest key in the tree map, returning fallback
if
the tree map is empty.
Equations
- t.maxEntryD fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxEntryD fallback) ⋯ t
Tries to retrieve the smallest key in the tree map, returning none
if the map is empty.
Equations
- t.minKey? = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minKey?) ⋯ t
Given a proof that the tree map is not empty, retrieves the smallest key.
Equations
- t.minKey h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.minKey ⋯) ⋯
Tries to retrieve the smallest key in the tree map, panicking if the map is empty.
Equations
- t.minKey! = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minKey!) ⋯ t
Tries to retrieve the smallest key in the tree map, returning fallback
if the tree map is empty.
Equations
- t.minKeyD fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.minKeyD fallback) ⋯ t
Tries to retrieve the largest key in the tree map, returning none
if the map is empty.
Equations
- t.maxKey? = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxKey?) ⋯ t
Given a proof that the tree map is not empty, retrieves the largest key.
Equations
- t.maxKey h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.maxKey ⋯) ⋯
Tries to retrieve the largest key in the tree map, panicking if the map is empty.
Equations
- t.maxKey! = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxKey!) ⋯ t
Tries to retrieve the largest key in the tree map, returning fallback
if the tree map is empty.
Equations
- t.maxKeyD fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.maxKeyD fallback) ⋯ t
Returns the key-value pair with the n
-th smallest key, or none
if n
is at least t.size
.
Equations
- t.entryAtIdx? n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.entryAtIdx? n) ⋯ t
Returns the key-value pair with the n
-th smallest key.
Equations
- t.entryAtIdx n h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.entryAtIdx n ⋯) ⋯
Returns the key-value pair with the n
-th smallest key, or panics if n
is at least t.size
.
Equations
- t.entryAtIdx! n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.entryAtIdx! n) ⋯ t
Returns the key-value pair with the n
-th smallest key, or fallback
if n
is at least t.size
.
Equations
- t.entryAtIdxD n fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.entryAtIdxD n fallback) ⋯ t
Returns the n
-th smallest key, or none
if n
is at least t.size
.
Equations
- t.keyAtIdx? n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.keyAtIdx? n) ⋯ t
Returns the n
-th smallest key.
Equations
- t.keyAtIdx n h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.keyAtIdx n ⋯) ⋯
Returns the n
-th smallest key, or panics if n
is at least t.size
.
Equations
- t.keyAtIdx! n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.keyAtIdx! n) ⋯ t
Returns the n
-th smallest key, or fallback
if n
is at least t.size
.
Equations
- t.keyAtIdxD n fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.keyAtIdxD n fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the
given key, returning none
if no such pair exists.
Equations
- t.getEntryGE? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGE? k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key,
returning none
if no such pair exists.
Equations
- t.getEntryGT? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGT? k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the
given key, returning none
if no such pair exists.
Equations
- t.getEntryLE? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLE? k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key,
returning none
if no such pair exists.
Equations
- t.getEntryLT? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLT? k) ⋯ t
Given a proof that such a mapping exists, retrieves the key-value pair with the smallest key that is greater than or equal to the given key.
Equations
- t.getEntryGE k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getEntryGE k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the smallest key that is greater than the given key.
Equations
- t.getEntryGT k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getEntryGT k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the largest key that is less than or equal to the given key.
Equations
- t.getEntryLE k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getEntryLE k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the largest key that is less than the given key.
Equations
- t.getEntryLT k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getEntryLT k ⋯) ⋯
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the given key, panicking if no such pair exists.
Equations
- t.getEntryGE! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGE! k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key, panicking if no such pair exists.
Equations
- t.getEntryGT! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGT! k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the given key, panicking if no such pair exists.
Equations
- t.getEntryLE! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLE! k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key, panicking if no such pair exists.
Equations
- t.getEntryLT! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLT! k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the
given key, returning fallback
if no such pair exists.
Equations
- t.getEntryGED k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGED k fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key,
returning fallback
if no such pair exists.
Equations
- t.getEntryGTD k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryGTD k fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the
given key, returning fallback
if no such pair exists.
Equations
- t.getEntryLED k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLED k fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key,
returning fallback
if no such pair exists.
Equations
- t.getEntryLTD k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getEntryLTD k fallback) ⋯ t
Tries to retrieve the smallest key that is greater than or equal to the
given key, returning none
if no such key exists.
Equations
- t.getKeyGE? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGE? k) ⋯ t
Tries to retrieve the smallest key that is greater than the given key,
returning none
if no such key exists.
Equations
- t.getKeyGT? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGT? k) ⋯ t
Tries to retrieve the largest key that is less than or equal to the
given key, returning none
if no such key exists.
Equations
- t.getKeyLE? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLE? k) ⋯ t
Tries to retrieve the largest key that is less than the given key,
returning none
if no such key exists.
Equations
- t.getKeyLT? k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLT? k) ⋯ t
Given a proof that such a mapping exists, retrieves the smallest key that is greater than or equal to the given key.
Equations
- t.getKeyGE k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getKeyGE k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the smallest key that is greater than the given key.
Equations
- t.getKeyGT k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getKeyGT k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the largest key that is less than or equal to the given key.
Equations
- t.getKeyLE k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getKeyLE k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the largest key that is less than the given key.
Equations
- t.getKeyLT k h = t.pliftOn (fun (m : Std.DTreeMap α β cmp) (h' : t = Std.ExtDTreeMap.mk m) => m.getKeyLT k ⋯) ⋯
Tries to retrieve the smallest key that is greater than or equal to the given key, panicking if no such key exists.
Equations
- t.getKeyGE! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGE! k) ⋯ t
Tries to retrieve the smallest key that is greater than the given key, panicking if no such key exists.
Equations
- t.getKeyGT! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGT! k) ⋯ t
Tries to retrieve the largest key that is less than or equal to the given key, panicking if no such key exists.
Equations
- t.getKeyLE! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLE! k) ⋯ t
Tries to retrieve the largest key that is less than the given key, panicking if no such key exists.
Equations
- t.getKeyLT! k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLT! k) ⋯ t
Tries to retrieve the smallest key that is greater than or equal to the
given key, returning fallback
if no such key exists.
Equations
- t.getKeyGED k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGED k fallback) ⋯ t
Tries to retrieve the smallest key that is greater than the given key,
returning fallback
if no such key exists.
Equations
- t.getKeyGTD k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyGTD k fallback) ⋯ t
Tries to retrieve the largest key that is less than or equal to the
given key, returning fallback
if no such key exists.
Equations
- t.getKeyLED k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLED k fallback) ⋯ t
Tries to retrieve the largest key that is less than the given key,
returning fallback
if no such key exists.
Equations
- t.getKeyLTD k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.getKeyLTD k fallback) ⋯ t
Checks whether a key is present in a map, returning the associated value, and inserts a value for the key if it was not found.
If the returned value is some v
, then the returned map is unaltered. If it is none
, then the
returned map has a new value inserted.
Equivalent to (but potentially faster than) calling get?
followed by insertIfNew
.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- One or more equations did not get rendered due to their size.
Tries to retrieve the mapping for the given key, returning none
if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- Std.ExtDTreeMap.Const.get? t a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.get? m a) ⋯ t
Given a proof that a mapping for the given key is present, retrieves the mapping for the given key.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- Std.ExtDTreeMap.Const.get t a h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.get m a ⋯) ⋯
Tries to retrieve the mapping for the given key, panicking if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- Std.ExtDTreeMap.Const.get! t a = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.get! m a) ⋯ t
Tries to retrieve the mapping for the given key, returning fallback
if no such mapping is present.
Uses the LawfulEqCmp
instance to cast the retrieved value to the correct type.
Equations
- Std.ExtDTreeMap.Const.getD t a fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getD m a fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key in the tree map, returning none
if the
map is empty.
Equations
- Std.ExtDTreeMap.Const.minEntry? t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.minEntry? m) ⋯ t
Given a proof that the tree map is not empty, retrieves the key-value pair with the smallest key.
Equations
- Std.ExtDTreeMap.Const.minEntry t h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.minEntry m ⋯) ⋯
Tries to retrieve the key-value pair with the smallest key in the tree map, panicking if the map is empty.
Equations
- Std.ExtDTreeMap.Const.minEntry! t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.minEntry! m) ⋯ t
Tries to retrieve the key-value pair with the smallest key in the tree map, returning fallback
if
the tree map is empty.
Equations
- Std.ExtDTreeMap.Const.minEntryD t fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.minEntryD m fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key in the tree map, returning none
if the
map is empty.
Equations
- Std.ExtDTreeMap.Const.maxEntry? t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.maxEntry? m) ⋯ t
Given a proof that the tree map is not empty, retrieves the key-value pair with the largest key.
Equations
- Std.ExtDTreeMap.Const.maxEntry t h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.maxEntry m ⋯) ⋯
Tries to retrieve the key-value pair with the largest key in the tree map, panicking if the map is empty.
Equations
- Std.ExtDTreeMap.Const.maxEntry! t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.maxEntry! m) ⋯ t
Tries to retrieve the key-value pair with the largest key in the tree map, returning fallback
if
the tree map is empty.
Equations
- Std.ExtDTreeMap.Const.maxEntryD t fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.maxEntryD m fallback) ⋯ t
Returns the key-value pair with the n
-th smallest key, or none
if n
is at least t.size
.
Equations
- Std.ExtDTreeMap.Const.entryAtIdx? t n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.entryAtIdx? m n) ⋯ t
Returns the key-value pair with the n
-th smallest key.
Equations
- Std.ExtDTreeMap.Const.entryAtIdx t n h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.entryAtIdx m n ⋯) ⋯
Returns the key-value pair with the n
-th smallest key, or panics if n
is at least t.size
.
Equations
- Std.ExtDTreeMap.Const.entryAtIdx! t n = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.entryAtIdx! m n) ⋯ t
Returns the key-value pair with the n
-th smallest key, or fallback
if n
is at least t.size
.
Equations
- Std.ExtDTreeMap.Const.entryAtIdxD t n fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.entryAtIdxD m n fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the
given key, returning none
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGE? t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGE? m k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key,
returning none
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGT? t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGT? m k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the
given key, returning none
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLE? t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLE? m k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key,
returning none
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLT? t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLT? m k) ⋯ t
Given a proof that such a mapping exists, retrieves the key-value pair with the smallest key that is greater than or equal to the given key.
Equations
- Std.ExtDTreeMap.Const.getEntryGE t k h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.getEntryGE m k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the smallest key that is greater than the given key.
Equations
- Std.ExtDTreeMap.Const.getEntryGT t k h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.getEntryGT m k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the largest key that is less than or equal to the given key.
Equations
- Std.ExtDTreeMap.Const.getEntryLE t k h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.getEntryLE m k ⋯) ⋯
Given a proof that such a mapping exists, retrieves the key-value pair with the largest key that is less than the given key.
Equations
- Std.ExtDTreeMap.Const.getEntryLT t k h = t.pliftOn (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) (h' : t = Std.ExtDTreeMap.mk m) => Std.DTreeMap.Const.getEntryLT m k ⋯) ⋯
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the given key, panicking if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGE! t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGE! m k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key, panicking if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGT! t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGT! m k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the given key, panicking if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLE! t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLE! m k) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key, panicking if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLT! t k = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLT! m k) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the
given key, returning fallback
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGED t k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGED m k fallback) ⋯ t
Tries to retrieve the key-value pair with the smallest key that is greater than the given key,
returning fallback
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryGTD t k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryGTD m k fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than or equal to the
given key, returning fallback
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLED t k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLED m k fallback) ⋯ t
Tries to retrieve the key-value pair with the largest key that is less than the given key,
returning fallback
if no such pair exists.
Equations
- Std.ExtDTreeMap.Const.getEntryLTD t k fallback = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.getEntryLTD m k fallback) ⋯ t
Removes all mappings of the map for which the given function returns false
.
Equations
- Std.ExtDTreeMap.filter f t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.filter f m)) ⋯ t
Updates the values of the map by applying the given function to all mappings, keeping
only those mappings where the function returns some
value.
Equations
- Std.ExtDTreeMap.filterMap f t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.filterMap f m)) ⋯ t
Updates the values of the map by applying the given function to all mappings.
Equations
- Std.ExtDTreeMap.map f t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.map f m)) ⋯ t
Folds the given monadic function over the mappings in the map in ascending order.
Equations
- Std.ExtDTreeMap.foldlM f init t = Std.ExtDTreeMap.lift (fun (m_1 : Std.DTreeMap α β cmp) => Std.DTreeMap.foldlM f init m_1) ⋯ t
Folds the given function over the mappings in the map in ascending order.
Equations
- Std.ExtDTreeMap.foldl f init t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.DTreeMap.foldl f init m) ⋯ t
Folds the given monadic function over the mappings in the map in descending order.
Equations
- Std.ExtDTreeMap.foldrM f init t = Std.ExtDTreeMap.lift (fun (m_1 : Std.DTreeMap α β cmp) => Std.DTreeMap.foldrM f init m_1) ⋯ t
Folds the given function over the mappings in the map in descending order.
Equations
- Std.ExtDTreeMap.foldr f init t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.DTreeMap.foldr f init m) ⋯ t
Partitions a tree map into two tree maps based on a predicate.
Equations
- One or more equations did not get rendered due to their size.
Carries out a monadic action on each mapping in the tree map in ascending order.
Equations
- Std.ExtDTreeMap.forM f t = Std.ExtDTreeMap.lift (fun (m_1 : Std.DTreeMap α β cmp) => Std.DTreeMap.forM f m_1) ⋯ t
Support for the for
loop construct in do
blocks. Iteration happens in ascending order.
Equations
- Std.ExtDTreeMap.forIn f init t = Std.ExtDTreeMap.lift (fun (m_1 : Std.DTreeMap α β cmp) => Std.DTreeMap.forIn f init m_1) ⋯ t
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
We do not define ForM
and ForIn
instances that are specialized to constant β
. Instead, we
define uncurried versions of forM
and forIn
that will be used in the Const
lemmas and to
define the ForM
and ForIn
instances for ExtDTreeMap
.
Carries out a monadic action on each mapping in the tree map in ascending order.
Equations
- Std.ExtDTreeMap.Const.forMUncurried f t = Std.ExtDTreeMap.forM (fun (a : α) (b : β) => f (a, b)) t
Support for the for
loop construct in do
blocks. Iteration happens in ascending order.
Equations
- Std.ExtDTreeMap.Const.forInUncurried f init t = Std.ExtDTreeMap.forIn (fun (a : α) (b : β) (acc : δ) => f (a, b) acc) init t
Check if any element satisfes the predicate, short-circuiting if a predicate fails.
Equations
- t.any p = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.any p) ⋯ t
Check if all elements satisfy the predicate, short-circuiting if a predicate fails.
Equations
- t.all p = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.all p) ⋯ t
Returns a list of all keys present in the tree map in ascending order.
Equations
- t.keys = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.keys) ⋯ t
Returns an array of all keys present in the tree map in ascending order.
Equations
- t.keysArray = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.keysArray) ⋯ t
Returns a list of all values present in the tree map in ascending order.
Equations
- t.values = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => m.values) ⋯ t
Returns an array of all values present in the tree map in ascending order.
Equations
- t.valuesArray = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => m.valuesArray) ⋯ t
Transforms the tree map into a list of mappings in ascending order.
Equations
- t.toList = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.toList) ⋯ t
Transforms a list of mappings into a tree map.
Equations
- Std.ExtDTreeMap.ofList l cmp = Std.ExtDTreeMap.mk (Std.DTreeMap.ofList l cmp)
Transforms the tree map into a list of mappings in ascending order.
Equations
- t.toArray = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => m.toArray) ⋯ t
Transforms an array of mappings into a tree map.
Equations
- Std.ExtDTreeMap.ofArray a cmp = Std.ExtDTreeMap.mk (Std.DTreeMap.ofArray a cmp)
Modifies in place the value associated with a given key.
This function ensures that the value is used linearly.
Equations
- t.modify a f = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (m.modify a f)) ⋯ t
Modifies in place the value associated with a given key,
allowing creating new values and deleting values via an Option
valued replacement function.
This function ensures that the value is used linearly.
Equations
- t.alter a f = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (m.alter a f)) ⋯ t
Returns a map that contains all mappings of t₁
and t₂
. In case that both maps contain the
same key k
with respect to cmp
, the provided function is used to determine the new value from
the respective values in t₁
and t₂
.
This function ensures that t₁
is used linearly. It also uses the individual values in t₁
linearly if the merge function uses the second argument (i.e. the first of type β a
) linearly.
Hence, as long as t₁
is unshared, the performance characteristics follow the following imperative
description: Iterate over all mappings in t₂
, inserting them into t₁
if t₁
does not contain a
conflicting mapping yet. If t₁
does contain a conflicting mapping, use the given merge function to
merge the mapping in t₂
into the mapping in t₁
. Then return t₁
.
Hence, the runtime of this method scales logarithmically in the size of t₁
and linearly in the size of
t₂
as long as t₁
is unshared.
Equations
- Std.ExtDTreeMap.mergeWith mergeFn t₁ t₂ = t₁.liftOn₂ t₂ (fun (m₁ m₂ : Std.DTreeMap α β cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.mergeWith mergeFn m₁ m₂)) ⋯
Transforms the tree map into a list of mappings in ascending order.
Equations
- Std.ExtDTreeMap.Const.toList t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.toList m) ⋯ t
Transforms a list of mappings into a tree map.
Equations
Transforms the tree map into a list of mappings in ascending order.
Equations
- Std.ExtDTreeMap.Const.toArray t = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.DTreeMap.Const.toArray m) ⋯ t
Transforms a list of mappings into a tree map.
Equations
Transforms a list of keys into a tree map.
Equations
Transforms an array of keys into a tree map.
Equations
Modifies in place the value associated with a given key.
This function ensures that the value is used linearly.
Equations
- Std.ExtDTreeMap.Const.modify t a f = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.Const.modify m a f)) ⋯ t
Modifies in place the value associated with a given key,
allowing creating new values and deleting values via an Option
valued replacement function.
This function ensures that the value is used linearly.
Equations
- Std.ExtDTreeMap.Const.alter t a f = Std.ExtDTreeMap.lift (fun (m : Std.DTreeMap α (fun (x : α) => β) cmp) => Std.ExtDTreeMap.mk (Std.DTreeMap.Const.alter m a f)) ⋯ t
Returns a map that contains all mappings of t₁
and t₂
. In case that both maps contain the
same key k
with respect to cmp
, the provided function is used to determine the new value from
the respective values in t₁
and t₂
.
This function ensures that t₁
is used linearly. It also uses the individual values in t₁
linearly if the merge function uses the second argument (i.e. the first of type β a
) linearly.
Hence, as long as t₁
is unshared, the performance characteristics follow the following imperative
description: Iterate over all mappings in t₂
, inserting them into t₁
if t₁
does not contain a
conflicting mapping yet. If t₁
does contain a conflicting mapping, use the given merge function to
merge the mapping in t₂
into the mapping in t₁
. Then return t₁
.
Hence, the runtime of this method scales logarithmically in the size of t₁
and linearly in the size of
t₂
as long as t₁
is unshared.
Equations
- One or more equations did not get rendered due to their size.
Inserts multiple mappings into the tree map by iterating over the given collection and calling
insert
. If the same key appears multiple times, the last occurrence takes precedence.
Note: this precedence behavior is true for TreeMap
, DTreeMap
, TreeMap.Raw
and DTreeMap.Raw
.
The insertMany
function on TreeSet
and TreeSet.Raw
behaves differently: it will prefer the first
appearance.
Equations
- One or more equations did not get rendered due to their size.
Erases multiple mappings from the tree map by iterating over the given collection and calling
erase
.
Equations
- One or more equations did not get rendered due to their size.
Inserts multiple mappings into the tree map by iterating over the given collection and calling
insert
. If the same key appears multiple times, the last occurrence takes precedence.
Note: this precedence behavior is true for TreeMap
, DTreeMap
, TreeMap.Raw
and DTreeMap.Raw
.
The insertMany
function on TreeSet
and TreeSet.Raw
behaves differently: it will prefer the first
appearance.
Equations
- One or more equations did not get rendered due to their size.
Inserts multiple elements into the tree map by iterating over the given collection and calling
insertIfNew
. If the same key appears multiple times, the first occurrence takes precedence.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Std.ExtDTreeMap.instReprOfTransCmp = { reprPrec := fun (m : Std.ExtDTreeMap α β cmp) (prec : Nat) => Repr.addAppParen (Std.Format.text "Std.ExtDTreeMap.ofList " ++ repr m.toList) prec }