trie-alg

Crates.iotrie-alg
lib.rstrie-alg
version0.4.0
created_at2024-12-22 07:10:39.940435+00
updated_at2024-12-26 14:14:29.803023+00
descriptionTrie implementation
homepage
repository
max_upload_size
id1491740
size1,486,034
Aditya Patil (adip1343)

documentation

README

trie-alg

Implement a trie space optimized for character set in use

let mut t = trie!();
t.add("abc");           // true
t.add("abc");           // false
t.contains("abc");      // true
t.contains("a");        // false

let mut t = multi_trie!();
t.add("abc");           // true
t.count("abc")          // 1
t.add("abc");           // false
t.count("abc")          // 2
t.contains("abc")       // true
t.contains("a")         // false
t.count("a")            // 0

struct LowerCaseWithHash();
impl CharSet for LowerCaseWithHash {
    const SIZE: usize = 27;
    fn map(ch: char) -> usize {
        if ch.is_ascii_lowercase() {
           ch as usize - 'a' as usize 
        } else {
            26
        }
    }

    fn unmap(hash: usize) -> char {
        if hash < 26 {
            (b'a'+hash as u8) as char
        }else {
            '#'
        }
    }
}

let mut t = multi_trie!(LowerCaseWithHash);
Commit count: 0

cargo fmt