lean4-htt/tests/lean/run/treemap.lean
Paul Reichert 0f1133fe69
feat: tree map data structures and operations (#6914)
This PR introduces ordered map data structures, namely `DTreeMap`,
`TreeMap`, `TreeSet` and their `.Raw` variants, into the standard
library. There are still some operations missing that the hash map has.
As of now, the operations are unverified, but the corresponding lemmas
will follow in subsequent PRs. While the tree map has already been
optimized, more micro-optimization will follow as soon as the new code
generator is ready.

---------

Co-authored-by: Paul Reichert <6992158+datokrat@users.noreply.github.com>
2025-02-11 14:47:47 +00:00

31 lines
871 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Reichert
-/
import Std.Data.TreeSet.Basic
open Std
variable {α : Type u} {β : Type v} [Ord α]
def mkDTreeMapSingleton (a : α) (b : β) : DTreeMap α (fun _ => β) := Id.run do
let mut m : DTreeMap α (fun _ => β) := ∅
m := m.insert a b
return m
def mkTreeMapSingleton (a : α) (b : β) : TreeMap α β := Id.run do
let mut m : TreeMap α β := ∅
m := m.insert a b
return m
def mkTreeSetSingleton (a : α) : TreeSet α := Id.run do
let mut m : TreeSet α := ∅
m := m.insert a
return m
example [TransOrd α] [LawfulEqOrd α] (a : α) (b : β) : Option β :=
mkDTreeMapSingleton a b |>.get? a
example [TransOrd α] [LawfulEqOrd α] (a : α) (b : β) : Option β :=
(mkTreeMapSingleton a b)[a]?