Debian Codegraph @

examples/build_and_search.rs

raw symbols SCIP
1 extern crate yadarust-analyzer cargo yada 0.5.1 yada/;
2
3 use yadarust-analyzer cargo yada 0.5.1 crate/::builderrust-analyzer cargo yada 0.5.1 builder/::DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#;
4 use yadarust-analyzer cargo yada 0.5.1 crate/::DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#;
5
6 fn mainrust-analyzer cargo yada 0.5.1 main().() {
7 // make a keyset which have key-value pairs
8 let keyset = &[
9 ("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 0),
10 ("ab".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 1),
11 ("abc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 2),
12 ("b".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 3),
13 ("bc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 4),
14 ("c".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), 5),
15 ];
16
17 // build a double-array trie binary
18 let da_bytes = DoubleArrayBuilderrust-analyzer cargo yada 0.5.1 builder/DoubleArrayBuilder#::buildrust-analyzer cargo yada 0.5.1 builder/impl#[DoubleArrayBuilder]build().(keyset);
19 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(da_bytes.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
20
21 // create a double-array trie instance
22 let da = DoubleArrayrust-analyzer cargo yada 0.5.1 DoubleArray#::newrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]new().(da_bytes.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
23
24 // exact match search
25 for (key, value) in keyset {
26 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().(key), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value as u32));
27 }
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("aa".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("aba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("abb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
31 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("abcd".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
32 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("ba".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
33 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("bb".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
34 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("bcd".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
35 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(da.exact_match_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]exact_match_search().("ca".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
36
37 // common prefix search
38 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
39 da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("a".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
40 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)] // match "a"
41 );
42 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
43 da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abc".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
44 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
45 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2), (2, 3)] // match "a", "ab", "abc"
46 );
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
48 da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("abcd".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
49 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
50 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1), (1, 2), (2, 3)] // match "a", "ab", "abc"
51 );
52 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
53 da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("bcd".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
54 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
55 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(3, 1), (4, 2)] // match "b", "bc"
56 );
57 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
58 da.common_prefix_searchrust-analyzer cargo yada 0.5.1 impl#[`DoubleArray<T>`]common_prefix_search().("d".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
59 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] // don't match
60 );
61 }