trie

Generated by tinox doc

A prefix tree (trie) of strings, character by character. Supports insert, exact search, prefix check (startsWith), and prefix-based autocomplete — useful for things like search-as-you-type suggestions or dictionary lookups.

Autocomplete

import tinox.core.trie;

class Main
{
    fnc main() -> Int32
    {
        let 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

        let 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