Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/Lean/Meta/DiscrTree/Util.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,37 @@ partial def size : Trie α → Nat
children.foldl (init := vs.size) fun n (_, c) => n + size c

/--
Checks that a trie node has no values and no children.
Generate a trie node from values and an array of children.
-/
@[inline]
def mkNode (vs : Array α) (cs : Array (Key × Trie α)) : Trie α :=
.node vs cs

/--
Inspect a trie node as an array of values and an array of children.
-/
@[inline]
def asNode : Trie α → Array α × Array (Key × Trie α)
| .node vs cs => ⟨vs, cs⟩

/--
Returns the values stored at the current trie node.
Equivalent to `t.asNode.1`.
-/
@[inline]
def nodeValues : Trie α → Array α
| .node vs _ => vs

/--
Returns the child nodes of the current trie node.
Equivalent to `t.asNode.2`.
-/
@[inline]
def nodeChildren : Trie α → Array (Key × Trie α)
| .node _ cs => cs

/--
Checks whether a trie node is empty (no values and no children).

This is only a check for actual trie emptiness (`t.size = 0`) if all operations maintain the
invariant that no trie node has an empty child node.
Expand Down
Loading