Skip to content

Instantly share code, notes, and snippets.

@ekmartin
Created March 17, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekmartin/e96275f09874a13a578faf0fbd2d0f6d to your computer and use it in GitHub Desktop.
Save ekmartin/e96275f09874a13a578faf0fbd2d0f6d to your computer and use it in GitHub Desktop.
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