Giter Site home page Giter Site logo

panoradix's Introduction

panoradix

My take on implementing a Radix tree, for usage when large data mappings with slices as indices.

Travis badge crates.io badge

Documentation

What's in this repo?

Both are backed by a Radix tree.

Any slice of elements that are Ord + Eq + Clone can be used as keys, as well as str that are taken as byte slices. Any lookups are done using a &[T] and iteration will yield an owned Vec<T> each time (for str it will yield String items).

Further extension of keys is possible but not recommended since the keys are arguably always a [T]. If you really want to do this, have a look at the ExtensibleKey trait.

Examples

Insert / Lookup

let mut map: RadixMap<str, i32> = RadixMap::new();
map.insert("a", 0);
map.insert("ac", 1);

assert_eq!(map.get("a"), Some(&0));
assert_eq!(map.get("ac"), Some(&1));
assert_eq!(map.get("ab"), None);

Removal

let v = vec!["foo", "bar", "baz"];
let mut set: RadixSet<str> = RadixSet::from_iter(v);

set.remove("bar");
assert!(!set.contains("bar"));
assert!(set.contains("baz"));

Completion

let v = vec!["foo", "bar", "baz"];
let set: RadixSet<str> = RadixSet::from_iter(v);

assert_eq!(set.find("ba").collect::<Vec<_>>(), vec!["bar", "baz"]);

Contributing

I try to maintain a list of things that need to be worked on over here. Issues / PRs are always welcome!

panoradix's People

Contributors

jmcomets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fdoyon

panoradix's Issues

`len` method for RadixSet and RadixMap

RadixSet and RadixMap have no len methods. The Rust standard library's HashSet and HashMap have len methods, so it is probably a reasonable interface.

It looks like your radix tree implementation uses trees from tree.rs, which don't keep track of their length, so you would have to do a tree traversal (O(n)) to determine the length of a tree. If len would indeed be O(n), it could be called something else, like count_len() to indicate that it is not O(1)

Alternatively, tree could be declared as

pub struct Tree<K, V> {
    node: Node<K, V>,
    len: usize,
}

instead of the current pub type Tree<K, V> = Node<K, V>. Of course, this would require updating len on insert and remove. This would be similar to the standard library's Vec, declared as

pub struct Vec<T> {
    buf: RawVec<T>,
    len: usize,
}

I'm not really sure if these are reasonable solutions, but it struck me as strange that RadixSet doesn't have a len method when I first tried to use it.

just to be clear, this is not a blocking issue, as

let mut set = RadixSet::new();
...
let len = set.iter().count();

works for now

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.