#double-array #trie #double-array-trie

bin+lib datrie

Double array trie implementation of rust

1 stable release

1.0.0 Sep 3, 2024

#5 in #double-array

GPL-3.0-only

16KB
214 lines

datrie

Double array trie implementation of rust.

use datrie;

fn main() {
    let mut dat = datrie::Dat::new();
    dat.append("", 1);
    dat.append("我喜欢", 2);
    dat.load(vec![("我喜欢你", 3), ("你不配", 4)]);

    assert_eq!(
        dat.search("我喜欢你"),
        vec![
            ("".to_string(), 1),
            ("我喜欢".to_string(), 2),
            ("我喜欢你".to_string(), 3)
        ]
    );
    assert_eq!(dat.search("配!"), vec![]);
    assert_eq!(dat.lookup("我喜欢你"), Some(3));
    assert_eq!(dat.lookup("我喜欢她"), None);
    assert!(dat.contain("你不配"));
    assert!(!dat.contain("你配"));
}

No runtime deps