TrieSwift
Trie tree implementation in Swift.
Installation
https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app
Example
-
Make tree
let tree = TrieTree<Character, String>() tree.insertValue(for: "sea", value: "π") tree.insertValue(for: "seat", value: "πΊ") tree.insertValue(for: "sheep", value: "π") tree.insertValue(for: "she", value: "π©") tree.insertValue(for: "tea", value: "π΅") tree.insertValue(for: "triangle", value: "πΊ") tree.insertValue(for: "tree", value: "π³") tree.insertValue(for: "apple", value: "π")
-
Tree traversal
print(tree.nextState(key: "a")).value // => nil print(tree.nextState(key: "p")).value // => nil print(tree.nextState(key: "p")).value // => nil print(tree.nextState(key: "l")).value // => nil print(tree.nextState(key: "e")).value // => "π"
Visualize
TrieTree
can generate PlantUML format text for debugging.
print(tree.generatePlantUMLString()) // => "@startuml ... @enduml"
The generated text can be rendered like the figure below.
License
MIT