Crates.io | yada_mod |
lib.rs | yada_mod |
version | 0.4.0 |
source | src |
created_at | 2021-03-24 09:40:41.821106 |
updated_at | 2021-03-24 09:40:41.821106 |
description | Yada is a yet another double-array trie library aiming for fast search and compact data representation. This fork added a tokenization function |
homepage | https://github.com/takuyaa/yada |
repository | https://github.com/daibo83/yada_tokenizer |
max_upload_size | |
id | 372873 |
size | 51,936 |
Yada is a yet another double-array trie library aiming for fast search and compact data representation.
Iterator
that is an effective way to find multiple
values without heap allocation.Option
.See also example code for more details.
use yada::builder::DoubleArrayBuilder;
// make a keyset which have key-value pairs
let keyset = &[
("a".as_bytes(), 0),
("ab".as_bytes(), 1),
("abc".as_bytes(), 2),
("b".as_bytes(), 3),
("bc".as_bytes(), 4),
("c".as_bytes(), 5),
];
// build a double-array trie binary
let da_bytes: Option<Vec<u8>> = DoubleArrayBuilder::build(keyset);
use yada::DoubleArray;
// create a double-array trie instance
let da = DoubleArray::new(da_bytes.unwrap());
// exact match search
for (key, value) in keyset {
assert_eq!(da.exact_match_search(key), Some(*value as u32));
}
assert_eq!(da.exact_match_search("abc".as_bytes()), Some(2));
assert_eq!(da.exact_match_search("abcd".as_bytes()), None);
// common prefix search
assert_eq!(
da.common_prefix_search("abcd".as_bytes())
.collect::<Vec<_>>(),
vec![(0, 1), (1, 2), (2, 3)] // match "a", "ab", "abc", value and key length
);
assert_eq!(
da.common_prefix_search("d".as_bytes()).collect::<Vec<_>>(),
vec![] // don't match
);
u32
.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.