Skip to content

Commit

Permalink
add new features docs to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Aug 22, 2024
1 parent f82e30b commit e1c553a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ trie.insert("ab".bytes(), "AB");
trie.insert("abc".bytes(), "ABC");
trie.insert("abcde".bytes(), "ABCDE");

// Find all potential prefixes
let prefixes = trie.find_prefixes("abcd".bytes());
assert_eq!(prefixes, vec![&"A", &"AB", &"ABC"]);

// Find the longest prefix
let longest = trie.find_longest_prefix("abcd".bytes());
assert_eq!(longest, Some("ABC").as_ref());

// Find longest with length
if let Some((length, prefix)) = trie.find_longest_prefix_len("abcd".bytes()) {
println!("Longest prefix: {} {}", prefix, length);
}
```

### 🔍 Find postfixes
Expand Down Expand Up @@ -85,14 +92,20 @@ let mut trie = Trie::new();
trie.insert("app".bytes(), "App");
trie.insert("applet".bytes(), "Applet");

// Get a key
assert!(trie.contains_key("app".bytes()));
assert!(!trie.contains_key("not_existing_key".bytes()));
assert_eq!(trie.get("app".bytes()), Some("App").as_ref());
assert_eq!(trie.get("none".bytes()), None.as_ref());

for (k, v) in trie.iter() {
// Iterate the trie
for (k, v) in &trie {
println!("kv: {:?} {}", k, v);
}

// Remove a key
trie.remove("app".bytes());
assert!(!trie.contains_key("app".bytes()));
```

## 🏷️ Features
Expand Down
1 change: 0 additions & 1 deletion tests/trie_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ mod tests {

t.insert(test.clone(), String::from("test"));
t.insert(tes.clone(), String::from("tes"));
// TODO: for (k, v) in &t {
for (k, v) in &t {
assert!(std::str::from_utf8(&k).unwrap().starts_with("tes"));
assert!(v.starts_with("tes"));
Expand Down

0 comments on commit e1c553a

Please sign in to comment.