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>
31 lines
871 B
Text
31 lines
871 B
Text
/-
|
||
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]?
|