6 releases

new 0.3.0 Nov 25, 2024
0.2.2 Jul 2, 2024
0.2.1 Oct 24, 2023
0.2.0 Jul 5, 2021
0.1.1 Oct 21, 2020

#245 in Database implementations

Download history 926/week @ 2024-08-07 789/week @ 2024-08-14 948/week @ 2024-08-21 945/week @ 2024-08-28 1012/week @ 2024-09-04 944/week @ 2024-09-11 994/week @ 2024-09-18 1015/week @ 2024-09-25 1015/week @ 2024-10-02 1272/week @ 2024-10-09 1183/week @ 2024-10-16 1226/week @ 2024-10-23 1244/week @ 2024-10-30 1223/week @ 2024-11-06 1208/week @ 2024-11-13 1112/week @ 2024-11-20

4,966 downloads per month

MIT license

18KB
318 lines

obkv

A micro key-value store where the key is always one byte. It is highly inspired by the KVDS crate.

Usage

let mut writer = KvWriter::memory();
writer.insert(0, b"hello").unwrap();
writer.insert(1, b"blue").unwrap();
writer.insert(255, b"world").unwrap();
let obkv = writer.into_inner().unwrap();

let reader = KvReader::new(&obkv);
assert_eq!(reader.get(0), Some(&b"hello"[..]));
assert_eq!(reader.get(1), Some(&b"blue"[..]));
assert_eq!(reader.get(10), None);
assert_eq!(reader.get(255), Some(&b"world"[..]));

lib.rs:

obkv stands for optimized-bytes key and a value store.

The main purpose of this library is to be able to store key value entries where the key can be represented by an optimized amount of bytes, this allows a lot of optimizations.

Example: Creating an obkv and iterating over the entries

use obkv::{KvWriterU16, KvReaderU16};

let mut writer = KvWriterU16::memory();
writer.insert(0, b"hello").unwrap();
writer.insert(1, b"blue").unwrap();
writer.insert(255, b"world").unwrap();
let obkv = writer.into_inner().unwrap();

let reader: &KvReaderU16 = obkv[..].into();
let mut iter = reader.iter();
assert_eq!(iter.next(), Some((0, &b"hello"[..])));
assert_eq!(iter.next(), Some((1, &b"blue"[..])));
assert_eq!(iter.next(), Some((255, &b"world"[..])));
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None); // is it fused?

No runtime deps