trie

Generated by tinox doc

tinox.core.trie, bundled with the compiler and also available as a standalone tinox-central package.

Autocomplete

import tinox.core.trie
class Main
{
    fnc main() -> Int32
    {
        const dict: Trie = Trie::new()
        Trie::insert(dict, "cat")
        Trie::insert(dict, "car")
        Trie::insert(dict, "card")
        Trie::insert(dict, "dog")
        println(Trie::search(dict, "car").toString())       // true
        println(Trie::search(dict, "ca").toString())        // false (not a full word)
        println(Trie::startsWith(dict, "ca").toString())     // true

        const suggestions: List<String> = Trie::autocomplete(dict, "ca")
        var i: Int64 = 0
        while i < suggestions.len()
        {
            println(suggestions[i])
            i = i + 1
        }

        return 0
    }
}

class Trie

Fields

rootTrieNode

Methods

fn new() → Trie
fn insert(trie: Trie, word: String) → Nothing
fn search(trie: Trie, word: String) → Bool
fn startsWith(trie: Trie, prefix: String) → Bool
fn autocomplete(trie: Trie, prefix: String) → List<String>
fn collectWords(node: TrieNode, prefix: String) → List<String>

class TrieNode

Fields

childrenMap<String, TrieNode>
isEndBool

Methods

fn new() → TrieNode