Mercurial > lbo > hg > leveldb-rs
view examples/write-a-lot/src/main.rs @ 450:b98968e1cc7d
chore(version): Bump version -> 0.2.0
Important changes:
. Fix integer overflow in bloom filter hash code.
. Change API and internals to use `Path` instead of `String`/`&str`.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 03 Mar 2018 11:49:17 +0100 |
parents | 8b6ecfd60c85 |
children | 9f01a2fbcda2 |
line wrap: on
line source
extern crate rusty_leveldb; extern crate rand; use rusty_leveldb::CompressionType; use rusty_leveldb::DB; use rusty_leveldb::Options; use rand::Rng; use std::error::Error; use std::iter::FromIterator; const KEY_LEN: usize = 16; const VAL_LEN: usize = 48; fn gen_string(len: usize) -> String { let mut rng = rand::thread_rng(); String::from_iter(rng.gen_ascii_chars().take(len)) } fn fill_db(db: &mut DB, entries: usize) -> Result<(), Box<Error>> { for i in 0..entries { let (k, v) = (gen_string(KEY_LEN), gen_string(VAL_LEN)); db.put(k.as_bytes(), v.as_bytes())?; if i % 100 == 0 { db.flush()?; } } Ok(()) } fn main() { let mut opt = Options::default(); opt.compression_type = CompressionType::CompressionSnappy; let mut db = DB::open("test1", opt).unwrap(); fill_db(&mut db, 32768).unwrap(); }