https://github.com/jmcomets/panoradix
A generic map and a set, both backed by a Radix tree.
https://github.com/jmcomets/panoradix
data-structure radix-tree
Last synced: 9 months ago
JSON representation
A generic map and a set, both backed by a Radix tree.
- Host: GitHub
- URL: https://github.com/jmcomets/panoradix
- Owner: jmcomets
- Created: 2017-04-10T10:17:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-31T13:49:17.000Z (over 6 years ago)
- Last Synced: 2025-08-30T02:30:36.738Z (10 months ago)
- Topics: data-structure, radix-tree
- Language: Rust
- Homepage:
- Size: 464 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
panoradix
=========
My take on implementing a [Radix tree][], for usage when large data mappings
with slices as indices.
[](https://travis-ci.org/jmcomets/panoradix)
[](https://crates.io/crates/panoradix)
[Documentation][]
## What's in this repo?
- [RadixMap][], a key-value map.
- [RadixSet][], a set of keys.
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` 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
```rust
let mut map: RadixMap = 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
```rust
let v = vec!["foo", "bar", "baz"];
let mut set: RadixSet = RadixSet::from_iter(v);
set.remove("bar");
assert!(!set.contains("bar"));
assert!(set.contains("baz"));
```
### Completion
```rust
let v = vec!["foo", "bar", "baz"];
let set: RadixSet = RadixSet::from_iter(v);
assert_eq!(set.find("ba").collect::>(), vec!["bar", "baz"]);
```
[Radix tree]: https://en.wikipedia.org/wiki/Radix_tree
[Documentation]: https://docs.rs/panoradix
[RadixMap]: https://github.com/jmcomets/panoradix/blob/master/src/map.rs
[RadixSet]: https://github.com/jmcomets/panoradix/blob/master/src/set.rs
## Contributing
I try to maintain a list of things that need to be worked on [over
here](https://github.com/jmcomets/panoradix/blob/master/TODO.md). Issues / PRs
are always welcome!