armdb 0.1.13

sharded bitcask key-value storage optimized for NVMe
Documentation
use armdb::{Config, ConstTree};
use tempfile::tempdir;

#[test]
fn test_compaction_const_tree() {
    let dir = tempdir().unwrap();
    let mut config = Config::test();
    config.max_file_size = 4096; // very small file size to force rotation
    config.compaction_threshold = 0.1; // low threshold to force compaction

    let tree = ConstTree::<[u8; 8], 8>::open(dir.path(), config).unwrap();

    // Write some entries
    for i in 0..1000u64 {
        let key = i.to_be_bytes();
        tree.put(&key, &key).unwrap();
    }

    // Overwrite half of them
    for i in 0..500u64 {
        let key = i.to_be_bytes();
        let val = (i + 1).to_be_bytes();
        tree.put(&key, &val).unwrap();
    }

    println!("Tree len before compaction: {}", tree.len());

    // Trigger compaction
    let _compacted = tree.compact().unwrap();

    println!("Tree len after compaction: {}", tree.len());

    // Check data integrity
    for i in 0..1000u64 {
        let key = i.to_be_bytes();
        let expected = if i < 500 {
            (i + 1).to_be_bytes()
        } else {
            i.to_be_bytes()
        };
        let val = tree.get(&key).unwrap_or_else(|| {
            panic!("Key not found: i={}", i);
        });
        assert_eq!(val, expected);
    }
}