Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created May 22, 2017 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/c9d80a0801b84febb9b3b3289665eb51 to your computer and use it in GitHub Desktop.
Save kunigami/c9d80a0801b84febb9b3b3289665eb51 to your computer and use it in GitHub Desktop.
let rec insert (s: char list) (trie: trie) : trie =
let Node(children, hasEntry) = trie in match s with
| [] -> Node(children, true)
| first_char :: rest ->
let currentChild = if ChildList.mem first_char children
then (ChildList.find first_char children)
else empty
in
let newChild = insert rest currentChild in
let newChildren = ChildList.add first_char newChild children in
Node(
newChildren,
hasEntry
)
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment