Comments (2)
In the example the trie contains the keys
z
aba
abb
abc
which represented as bytes (the only thing the trie cares about) is:
z = [0x7a]
aba = [0x61, 0x62, 0x61]
abb = [0x61, 0x62, 0x62]
abc = [0x61, 0x62, 0x63]
The three ab*
keys will be stored under a common prefix, and because the trie uses 16 nodes per level (i.e. half a byte worth of key -- a nibble), it can split that prefix on a half-byte boundary. So there'll be an intermediate node in the trie at key [0x61, 0x62, 0x6_]
, with three children for keys 0x_1
, 0x_2
, 0x_3
. You can fetch this intermediate node using get_raw_ancestor
and any key that starts with [0x61, 0x62, 0x6_]
(like "abd"
) but not with a key like "abz" = [0x61, 0x62, 0x7a]
.
If you had the same data and wanted to iterate over all the ab*
values, you could use get_raw_descendant("ab")
to fetch the common prefix node. Or if you're happy to modify the data slightly, you could insert a dummy value for the key "ab"
and use subtrie("ab")
(that seems cleaner in a lot of ways)
Admittedly, the nibble-oriented approach can be counter-intuitive and I'm not certain that this is the best possible API, but it is what it is. Hope that helps
from rust_radix_trie.
Thanks for commenting, the thing that I'm trying to do is this:
t.insert("z", vec!["z"]);
t.insert("a", vec!["a"]);
t.insert("ab", vec!["b"]);
t.insert("abc", vec!["c"]);
t.insert("abcd", vec!["c"]);
assert!(t.get_all_on_path(&"abce").eq(vec!["a", "b", "c"].iter()));
is something like this possible? If not currently, would you be open to accepting a PR to add it? Any suggestions for implementation?
from rust_radix_trie.
Related Issues (20)
- c ffi support HOT 2
- remove() panics on non-existing element HOT 5
- Missing CI to cover windows build against stable / nightly respectively
- Question: Why is the key stored during insertion? HOT 2
- Optimization store keys HOT 1
- Implement Clone for Trie HOT 1
- Removing nonexistent keys causes prefix matching to fail HOT 4
- How to benchmark HOT 1
- Did get_ancestor match? HOT 4
- Missing TrieKey impls for paths on Windows
- Does this library support multithreading? HOT 3
- nibble_vec 0.0.5 has problem HOT 2
- implement extend trait to allow bulk updates to Trie
- get_raw_ancestor none with multiple children
- Expect a feature to get all prefix match values.
- Extremely poor memory efficiency (many times worse than Vec even with near-ideal conditions) HOT 1
- Question - how to use this to search for common strings based on prefix HOT 2
- Is `get_ancestor_value_mut` a possible method ? HOT 2
- map_with_default encodes key twice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust_radix_trie.