4 releases

0.1.3 Jul 2, 2024
0.1.2 Sep 5, 2022
0.1.1 Sep 5, 2022
0.1.0 Sep 4, 2022

#453 in Data structures

Download history 188/week @ 2024-06-30 5/week @ 2024-07-07 1/week @ 2024-07-14 15/week @ 2024-09-15 4/week @ 2024-09-22 27/week @ 2024-09-29 11/week @ 2024-10-06

57 downloads per month

MIT license

36KB
907 lines

Check Lints Test Coverage

settrie

Fast subset and superset queries. It implemented Iztok Savnik's proposed data structure set-trie.

One difference from Iztok Savnik's data structure is, this implementation doesn't memorize a set which ends in a non-leaf node of existing set.

use settrie::SetTrie;
fn main(){
    let mut set_trie = SetTrie::new();
    set_trie.insert_set(&[1, 2, 3]);
    set_trie.insert_set(&[1, 2, 3, 5]);
    set_trie.insert_set(&[1, 2, 4]);
    assert_eq!(
        set_trie.get_supersets(&[1, 2]),
        vec![vec![1, 2, 3, 5], vec![1, 2, 4]]
    );
    assert_eq!(set_trie.exist_subset(&vec![1, 2, 3, 5]), true);
    assert_eq!(set_trie.exist_superset(&vec![1, 2]), true);
    assert_eq!(
        set_trie.get_all_supersets(),
        vec![vec![1, 2, 3, 5], vec![1, 2, 4]]
    );
    assert_eq!(set_trie.get_supersets(&[1, 3, 5]), vec![vec![1, 2, 3, 5]]);
    assert_eq!(
        set_trie.get_subsets(&[1, 2, 3, 5, 7]),
        vec![vec![1, 2, 3, 5]]
    );
}

No runtime deps