feat: values and valuesArray functions for the tree map (#7114)

This PR implements the methods `values` and `valuesArray` on the tree
map.

Co-authored-by: Paul Reichert <6992158+datokrat@users.noreply.github.com>
This commit is contained in:
Paul Reichert 2025-02-17 16:57:11 +01:00 committed by GitHub
parent 5a8b4459c8
commit 16e9700224
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 0 deletions

View file

@ -786,6 +786,16 @@ def keys (t : DTreeMap α β cmp) : List α :=
def keysArray (t : DTreeMap α β cmp) : Array α :=
t.inner.keysArray
/-- Returns a list of all values present in the tree map in ascending order. -/
@[inline]
def values {β : Type v} (t : DTreeMap α β cmp) : List β :=
t.inner.values
/-- Returns an array of all values present in the tree map in ascending order. -/
@[inline]
def valuesArray {β : Type v} (t : DTreeMap α β cmp) : Array β :=
t.inner.valuesArray
/-- Transforms the tree map into a list of mappings in ascending order. -/
@[inline]
def toList (t : DTreeMap α β cmp) : List ((a : α) × β a) :=

View file

@ -204,6 +204,14 @@ def forIn {m} [Monad m] (f : δ → (a : α) → β a → m (ForInStep δ)) (ini
@[inline] def keysArray (t : Impl α β) : Array α :=
t.foldl (init := #[]) fun l k _ => l.push k
/-- Returns a `List` of the values in order. -/
@[inline] def values {β : Type v} (t : Impl α β) : List β :=
t.foldr (init := []) fun l _ v => v :: l
/-- Returns an `Array` of the values in order. -/
@[inline] def valuesArray {β : Type v} (t : Impl α β) : Array β :=
t.foldl (init := #[]) fun l _ v => l.push v
/-- Returns a `List` of the key/value pairs in order. -/
@[inline] def toList (t : Impl α β) : List ((a : α) × β a) :=
t.foldr (init := []) fun l k v => ⟨k, v⟩ :: l

View file

@ -575,6 +575,14 @@ def keys (t : Raw α β cmp) : List α :=
def keysArray (t : Raw α β cmp) : Array α :=
t.inner.keysArray
@[inline, inherit_doc DTreeMap.values]
def values {β : Type v} (t : Raw α β cmp) : List β :=
t.inner.values
@[inline, inherit_doc DTreeMap.valuesArray]
def valuesArray {β : Type v} (t : Raw α β cmp) : Array β :=
t.inner.valuesArray
@[inline, inherit_doc DTreeMap.toList]
def toList (t : Raw α β cmp) : List ((a : α) × β a) :=
t.inner.toList

View file

@ -424,6 +424,14 @@ def keys (t : TreeMap α β cmp) : List α :=
def keysArray (t : TreeMap α β cmp) : Array α :=
t.inner.keysArray
@[inline, inherit_doc DTreeMap.values]
def values (t : TreeMap α β cmp) : List β :=
t.inner.values
@[inline, inherit_doc DTreeMap.valuesArray]
def valuesArray (t : TreeMap α β cmp) : Array β :=
t.inner.valuesArray
@[inline, inherit_doc DTreeMap.Const.toList]
def toList (t : TreeMap α β cmp) : List (α × β) :=
DTreeMap.Const.toList t.inner

View file

@ -432,6 +432,14 @@ def keys (t : Raw α β cmp) : List α :=
def keysArray (t : Raw α β cmp) : Array α :=
t.inner.keysArray
@[inline, inherit_doc DTreeMap.Raw.values]
def values (t : Raw α β cmp) : List β :=
t.inner.values
@[inline, inherit_doc DTreeMap.Raw.valuesArray]
def valuesArray (t : Raw α β cmp) : Array β :=
t.inner.valuesArray
@[inline, inherit_doc DTreeMap.Raw.Const.toList]
def toList (t : Raw α β cmp) : List (α × β) :=
DTreeMap.Raw.Const.toList t.inner