Skip to content
Trie tree implementation in Swift
Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
Sources/TrieSwift
Tests
.gitignore
LICENSE
Package.swift
README.md

README.md

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

You can’t perform that action at this time.