A Trie is a key-value store where the keys are of type String
,
and the internal structure is a tree that branches on the bytes of the string.
- leaf {α : Type} : Option α → Lean.Data.Trie α
- node1 {α : Type} : Option α → UInt8 → Lean.Data.Trie α → Lean.Data.Trie α
- node {α : Type} : Option α → ByteArray → Array (Lean.Data.Trie α) → Lean.Data.Trie α
Instances For
Equations
- Lean.Data.Trie.instEmptyCollection = { emptyCollection := Lean.Data.Trie.empty }
Equations
- Lean.Data.Trie.instInhabited = { default := Lean.Data.Trie.empty }
Insert or update the value at a the given key s
.
Equations
- t.upsert s f = Lean.Data.Trie.upsert.loop s f 0 t
Instances For
partial def
Lean.Data.Trie.upsert.insertEmpty
{α : Type}
(s : String)
(f : Option α → α)
(i : Nat)
:
partial def
Lean.Data.Trie.upsert.loop
{α : Type}
(s : String)
(f : Option α → α)
:
Nat → Lean.Data.Trie α → Lean.Data.Trie α
Inserts a value at a the given key s
, overriding an existing value if present.
Instances For
Looks up a value at the given key s
.
Equations
- t.find? s = Lean.Data.Trie.find?.loop s 0 t
Instances For
Returns an Array
of all values in the trie, in no particular order.
Equations
- t.values = (StateT.run (Lean.Data.Trie.values.go t) #[]).snd
Instances For
Returns all values whose key have the given string pre
as a prefix, in no particular order.
Equations
- t.findPrefix pre = Lean.Data.Trie.findPrefix.go pre t 0
Instances For
partial def
Lean.Data.Trie.findPrefix.go
{α : Type}
(pre : String)
(t : Lean.Data.Trie α)
(i : Nat)
:
Array α
def
Lean.Data.Trie.matchPrefix
{α : Type}
(s : String)
(t : Lean.Data.Trie α)
(i : String.Pos)
:
Option α
Find the longest key in the trie that is contained in the given string s
at position i
,
and return the associated value.
Equations
- Lean.Data.Trie.matchPrefix s t i = Lean.Data.Trie.matchPrefix.loop s t i.byteIdx none
Instances For
partial def
Lean.Data.Trie.matchPrefix.loop
{α : Type}
(s : String)
:
Lean.Data.Trie α → Nat → Option α → Option α
Equations
- Lean.Data.Trie.instToString = { toString := fun (t : Lean.Data.Trie α) => (flip Lean.Format.joinSep Lean.Format.line (Lean.Data.Trie.toStringAux✝ t)).pretty }