Skip to content

Commit

Permalink
examples: update integration example
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdroychan committed Aug 8, 2024
1 parent 932a154 commit 367804e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions examples/your-kv-store/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ use std::collections::HashMap;
use std::sync::{Arc, RwLock};

#[derive(Clone)]
pub struct SimpleKVMap(Arc<RwLock<HashMap<Box<[u8]>, Box<[u8]>>>>);
pub struct YourKVMap(Arc<RwLock<HashMap<Box<[u8]>, Box<[u8]>>>>);

impl SimpleKVMap {
impl YourKVMap {
pub fn new() -> Self {
Self(Arc::new(
RwLock::new(HashMap::<Box<[u8]>, Box<[u8]>>::new()),
))
}

pub fn new_benchkvmap(_opt: &toml::Table) -> BenchKVMap {
BenchKVMap::Regular(Box::new(Self::new()))
BenchKVMap::Regular(Arc::new(Box::new(Self::new())))
}
}

impl KVMap for SimpleKVMap {
impl KVMap for YourKVMap {
fn handle(&self) -> Box<dyn KVMapHandle> {
Box::new(self.clone())
}
}

impl KVMapHandle for SimpleKVMap {
impl KVMapHandle for YourKVMap {
fn set(&mut self, key: &[u8], value: &[u8]) {
self.0.write().unwrap().insert(key.into(), value.into());
}
Expand All @@ -46,10 +46,14 @@ impl KVMapHandle for SimpleKVMap {
fn delete(&mut self, key: &[u8]) {
self.0.write().unwrap().remove(key);
}

fn scan(&mut self, _key: &[u8], _n: usize) -> Vec<(Box<[u8]>, Box<[u8]>)> {
unimplemented!();
}
}

inventory::submit! {
Registry::new("simplekvmap", SimpleKVMap::new_benchkvmap)
Registry::new("your_kv_store", YourKVMap::new_benchkvmap)
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/your-kv-store/your-kv-store.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[map]
name = "simplekvmap"
name = "your_kv_store"

0 comments on commit 367804e

Please sign in to comment.