Giter VIP home page Giter VIP logo

Comments (2)

michaelsproul avatar michaelsproul commented on May 30, 2024

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.

leshow avatar leshow commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.