art-tree

Crates.ioart-tree
lib.rsart-tree
version0.2.0
sourcesrc
created_at2021-09-27 07:55:26.891245
updated_at2021-12-27 12:30:12.370811
descriptionThe Adaptive Radix Tree
homepage
repositoryhttps://github.com/Lagrang/art-rs
max_upload_size
id456844
size98,450
Igor Skokov (Lagrang)

documentation

https://docs.rs/art-tree

README

Crate API

The Adaptive Radix Tree

The radix tree based on The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases paper.

use art_tree::ByteString;
use art_tree::KeyBuilder;
use art_tree::Art;

pub fn art_example() {
    let mut art = Art::<u16, u16>::new();
    for i in 0..u8::MAX as u16 {
        assert!(art.insert(i, i), "{}", i);
        assert!(matches!(art.get(&i), Some(val) if val == &i));
    }
    for i in 0..u8::MAX as u16 {
        assert!(matches!(art.remove(&i), Some(val) if val == i));
    }
    let mut art = Art::<ByteString, u16>::new();
    for i in 0..u8::MAX as u16 {
        let key = KeyBuilder::new().append(i).append(ByteString::new("abc".to_string().as_bytes())).build();
        art.upsert(key.clone(), i + 1);
        assert!(matches!(art.get(&key), Some(val) if val == &(i + 1)));
    }
    let from_key = KeyBuilder::new().append(16u16).append(ByteString::new("abc".to_string().as_bytes())).build();
    let until_key = KeyBuilder::new().append(20u16).append(ByteString::new("abc".to_string().as_bytes())).build();
    assert_eq!(art.range(from_key..=until_key).count(), 5);
    assert_eq!(art.iter().count(), u8::MAX as usize);   
}
Commit count: 41

cargo fmt