Created
March 17, 2019 01:31
-
-
Save ekmartin/e96275f09874a13a578faf0fbd2d0f6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rocksdb; | |
use rocksdb::{DB, Options, SliceTransform}; | |
use std::alloc::System; | |
#[global_allocator] | |
static A: System = System; | |
fn main() { | |
let mut opts = Options::default(); | |
opts.create_if_missing(true); | |
let slice_transform = SliceTransform::create("slice", transform, Some(in_domain)); | |
opts.set_prefix_extractor(slice_transform); | |
let db = DB::open(&opts, "rocksdb.db").unwrap(); | |
for i in 0..100000 { | |
let key = format!("{}this is a long key", i); | |
db.put(&key, b"this is a value").unwrap(); | |
let iter = db.prefix_iterator(key); | |
if i % 1000 == 0 { | |
println!("items: {:?}", iter.collect::<Vec<_>>().len()); | |
} | |
} | |
} | |
fn in_domain(_: &[u8]) -> bool { | |
true | |
} | |
fn transform<'a>(key: &'a [u8]) -> &'a [u8] { | |
key | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment