Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

TrieSwift

Swift 5.1 SPM

Trie tree implementation in Swift.

Installation

https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app

Example

  1. 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: "🍎")
  2. 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.

plantuml

License

MIT

About

Trie tree implementation in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages