From 3f60a113c8926962773b2b8a5f33d167e804999f Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:14:20 +0200 Subject: [PATCH 01/28] Create kermit-dv project --- Cargo.toml | 3 ++- kermit-dv/Cargo.toml | 12 ++++++++++++ kermit-dv/src/main.rs | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 kermit-dv/Cargo.toml create mode 100644 kermit-dv/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index e342cfc..254fd9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["kermit", "kermit-algos", "kermit-ds", "kermit-iters"] +members = ["kermit", "kermit-algos", "kermit-ds", "kermit-dv", "kermit-iters"] [workspace.package] authors = ["Aidan Bailey"] @@ -12,6 +12,7 @@ repository = "https://github.com/aidan-bailey/kermit" [patch.crates-io] kermit = { path = "kermit" } +# kermit-dv = { path = "kermit-algos" } kermit-ds = { path = "kermit-ds" } kermit-iters = { path = "kermit-iters" } kermit-algos = { path = "kermit-algos" } diff --git a/kermit-dv/Cargo.toml b/kermit-dv/Cargo.toml new file mode 100644 index 0000000..e565297 --- /dev/null +++ b/kermit-dv/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "kermit-dv" +description = "Data value stores used in Kermit" +version = "0.0.1-dev" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true + +[dependencies] diff --git a/kermit-dv/src/main.rs b/kermit-dv/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/kermit-dv/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From a3119f434caa1da10bc5c3b59d559397ff613a7e Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:16:23 +0200 Subject: [PATCH 02/28] Rename kermit-dv to kermit-kvs --- Cargo.toml | 4 ++-- {kermit-dv => kermit-kvs}/Cargo.toml | 4 ++-- {kermit-dv => kermit-kvs}/src/main.rs | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename {kermit-dv => kermit-kvs}/Cargo.toml (74%) rename {kermit-dv => kermit-kvs}/src/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 254fd9e..7c493df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["kermit", "kermit-algos", "kermit-ds", "kermit-dv", "kermit-iters"] +members = ["kermit", "kermit-algos", "kermit-ds", "kermit-kvs", "kermit-iters"] [workspace.package] authors = ["Aidan Bailey"] @@ -12,7 +12,7 @@ repository = "https://github.com/aidan-bailey/kermit" [patch.crates-io] kermit = { path = "kermit" } -# kermit-dv = { path = "kermit-algos" } +# kermit-kvs = { path = "kermit-kvs" } kermit-ds = { path = "kermit-ds" } kermit-iters = { path = "kermit-iters" } kermit-algos = { path = "kermit-algos" } diff --git a/kermit-dv/Cargo.toml b/kermit-kvs/Cargo.toml similarity index 74% rename from kermit-dv/Cargo.toml rename to kermit-kvs/Cargo.toml index e565297..3285974 100644 --- a/kermit-dv/Cargo.toml +++ b/kermit-kvs/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "kermit-dv" -description = "Data value stores used in Kermit" +name = "kermit-kvs" +description = "Key-value stores used in Kermit" version = "0.0.1-dev" authors.workspace = true edition.workspace = true diff --git a/kermit-dv/src/main.rs b/kermit-kvs/src/main.rs similarity index 100% rename from kermit-dv/src/main.rs rename to kermit-kvs/src/main.rs From 7cedd630cc28b29bfa5faa157c3d135f2070b3b5 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:24:07 +0200 Subject: [PATCH 03/28] Change kermit-kvs to be a lib --- kermit-kvs/Cargo.toml | 2 +- kermit-kvs/src/lib.rs | 0 kermit-kvs/src/main.rs | 3 --- 3 files changed, 1 insertion(+), 4 deletions(-) create mode 100644 kermit-kvs/src/lib.rs delete mode 100644 kermit-kvs/src/main.rs diff --git a/kermit-kvs/Cargo.toml b/kermit-kvs/Cargo.toml index 3285974..a4f9cba 100644 --- a/kermit-kvs/Cargo.toml +++ b/kermit-kvs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kermit-kvs" description = "Key-value stores used in Kermit" -version = "0.0.1-dev" +version = "0.0.2-dev" authors.workspace = true edition.workspace = true homepage.workspace = true diff --git a/kermit-kvs/src/lib.rs b/kermit-kvs/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/kermit-kvs/src/main.rs b/kermit-kvs/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/kermit-kvs/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} From 09d595f5a05684e19944583df813fd06ebb500c4 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:24:20 +0200 Subject: [PATCH 04/28] Add kermit-kvs patch --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7c493df..2514161 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/aidan-bailey/kermit" [patch.crates-io] kermit = { path = "kermit" } -# kermit-kvs = { path = "kermit-kvs" } +kermit-kvs = { path = "kermit-kvs" } kermit-ds = { path = "kermit-ds" } kermit-iters = { path = "kermit-iters" } kermit-algos = { path = "kermit-algos" } From f49610e8b8f3141c99b7f582a06fbd525b58a242 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:25:21 +0200 Subject: [PATCH 05/28] Add kermit-kvs dep --- kermit/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kermit/Cargo.toml b/kermit/Cargo.toml index ded2b92..06eebb3 100644 --- a/kermit/Cargo.toml +++ b/kermit/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kermit" description = "Relational data structures, iterators and algorithms" -version = "0.0.4-dev" +version = "0.0.5-dev" authors.workspace = true edition.workspace = true homepage.workspace = true @@ -10,6 +10,7 @@ readme.workspace = true repository.workspace = true [dependencies] +kermit-kvs = { version = "0.0.2-dev", path = "../kermit-kvs" } kermit-ds = { version = "0.0.4-dev", path = "../kermit-ds" } kermit-iters = { version = "0.0.4-dev", path = "../kermit-iters" } kermit-algos = { version = "0.0.4-dev", path = "../kermit-algos" } From 5f29ac40b46877ece2d9cc748d6ad041350dfeb4 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:26:00 +0200 Subject: [PATCH 06/28] Add kermit_kvs export --- kermit/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kermit/src/lib.rs b/kermit/src/lib.rs index e2a29ad..695f2cd 100644 --- a/kermit/src/lib.rs +++ b/kermit/src/lib.rs @@ -9,3 +9,7 @@ pub mod ds { pub mod iters { pub use kermit_iters::*; } + +pub mod kvs { + pub use kermit_kvs::*; +} From a381eca908fec9abf6169979f535be26b579561b Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Thu, 15 Aug 2024 14:39:09 +0200 Subject: [PATCH 07/28] Create keyvalstore.rs --- kermit-kvs/src/keyvalstore.rs | 12 ++++++++++++ kermit-kvs/src/lib.rs | 1 + 2 files changed, 13 insertions(+) create mode 100644 kermit-kvs/src/keyvalstore.rs diff --git a/kermit-kvs/src/keyvalstore.rs b/kermit-kvs/src/keyvalstore.rs new file mode 100644 index 0000000..5029a8d --- /dev/null +++ b/kermit-kvs/src/keyvalstore.rs @@ -0,0 +1,12 @@ +use std::hash::Hash; + +trait KeyValStore +where + KT: PartialEq + PartialOrd + Clone, + VT: Hash, +{ + fn add(&mut self, val: VT) -> KT; + fn add_all(&mut self, val: Vec) -> Vec; + fn get(&self, key: KT) -> Option; + fn get_all(&self, key: Vec) -> Vec; +} diff --git a/kermit-kvs/src/lib.rs b/kermit-kvs/src/lib.rs index e69de29..f90c804 100644 --- a/kermit-kvs/src/lib.rs +++ b/kermit-kvs/src/lib.rs @@ -0,0 +1 @@ +pub mod keyvalstore; From 89a4be895f6c954090e72dfea6ece37f16766835 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 10:06:25 +0200 Subject: [PATCH 08/28] Refactor --- kermit-kvs/src/keyvalstore.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kermit-kvs/src/keyvalstore.rs b/kermit-kvs/src/keyvalstore.rs index 5029a8d..1fcb127 100644 --- a/kermit-kvs/src/keyvalstore.rs +++ b/kermit-kvs/src/keyvalstore.rs @@ -1,12 +1,12 @@ use std::hash::Hash; -trait KeyValStore +pub trait KeyValStore where - KT: PartialEq + PartialOrd + Clone, + KT: Eq + Hash + Clone + PartialOrd, VT: Hash, { fn add(&mut self, val: VT) -> KT; fn add_all(&mut self, val: Vec) -> Vec; - fn get(&self, key: KT) -> Option; - fn get_all(&self, key: Vec) -> Vec; + fn get(&self, key: &KT) -> Option<&VT>; + fn get_all(&self, key: Vec<&KT>) -> Vec>; } From aef02b72100a283da58d0da759f6124d007397e5 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 10:06:39 +0200 Subject: [PATCH 09/28] Create naivestore.rs --- kermit-kvs/src/lib.rs | 1 + kermit-kvs/src/naivestore.rs | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 kermit-kvs/src/naivestore.rs diff --git a/kermit-kvs/src/lib.rs b/kermit-kvs/src/lib.rs index f90c804..a6577f5 100644 --- a/kermit-kvs/src/lib.rs +++ b/kermit-kvs/src/lib.rs @@ -1 +1,2 @@ pub mod keyvalstore; +pub mod naivestore; diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs new file mode 100644 index 0000000..4e3608a --- /dev/null +++ b/kermit-kvs/src/naivestore.rs @@ -0,0 +1,67 @@ +use { + crate::keyvalstore::KeyValStore, + nohash_hasher::BuildNoHashHasher, + std::{ + collections::HashMap, + hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash}, + }, +}; + +pub struct NaiveStore +where + VT: Hash + Clone, + HB: BuildHasher, +{ + map: HashMap>, + hash_builder: HB, +} + +impl KeyValStore for NaiveStore +where + VT: Hash + Clone, + HB: BuildHasher, +{ + fn add(&mut self, val: VT) -> u64 { + let hash = self.hash_builder.hash_one(&val); + self.map.insert(hash, val); + hash + } + + fn add_all(&mut self, val: Vec) -> Vec { + val.into_iter().map(|v| self.add(v)).collect() + } + + fn get(&self, key: &u64) -> Option<&VT> { + let hash = self.hash_builder.hash_one(&key); + self.map.get(&hash) + } + + fn get_all(&self, key: Vec<&u64>) -> Vec> { + key.into_iter().map(|k| self.get(&k)).collect() + } +} + +impl NaiveStore +where + VT: Hash + Clone, + HB: BuildHasher, +{ + pub fn with_hasher(hasher: HB) -> Self { + Self { + map: HashMap::with_hasher(BuildNoHashHasher::::default()), + hash_builder: hasher, + } + } +} + +impl NaiveStore> +where + VT: Hash + Clone, +{ + pub fn new() -> Self { + Self { + map: HashMap::with_hasher(BuildNoHashHasher::::default()), + hash_builder: BuildHasherDefault::::default(), + } + } +} From fed9e9c10351ca49c43f618b30f65f1a3d829cac Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 10:06:46 +0200 Subject: [PATCH 10/28] Fix missing dependency --- kermit-kvs/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/kermit-kvs/Cargo.toml b/kermit-kvs/Cargo.toml index a4f9cba..fd87fd7 100644 --- a/kermit-kvs/Cargo.toml +++ b/kermit-kvs/Cargo.toml @@ -10,3 +10,4 @@ readme.workspace = true repository.workspace = true [dependencies] +nohash-hasher = "0.2.0" From 4374cfba3dfe90c2ed46301a9c3f305d58a7bbe2 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 10:08:20 +0200 Subject: [PATCH 11/28] Refactor --- kermit-kvs/src/naivestore.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 4e3608a..706aa9f 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -54,11 +54,11 @@ where } } -impl NaiveStore> +impl Default for NaiveStore> where VT: Hash + Clone, { - pub fn new() -> Self { + fn default() -> Self { Self { map: HashMap::with_hasher(BuildNoHashHasher::::default()), hash_builder: BuildHasherDefault::::default(), From 6e6fb3fa022e2a646d2d86fd9f9d8ba5ea045b43 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 10:14:13 +0200 Subject: [PATCH 12/28] Add test --- kermit-kvs/src/naivestore.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 706aa9f..6bdb8c1 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -32,12 +32,11 @@ where } fn get(&self, key: &u64) -> Option<&VT> { - let hash = self.hash_builder.hash_one(&key); - self.map.get(&hash) + self.map.get(key) } fn get_all(&self, key: Vec<&u64>) -> Vec> { - key.into_iter().map(|k| self.get(&k)).collect() + key.into_iter().map(|k| self.get(k)).collect() } } @@ -65,3 +64,20 @@ where } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_default() { + let mut store = NaiveStore::::default(); + let key1 = store.add("hello".to_string()); + let key2 = store.add("world".to_string()); + assert_eq!(store.get(&key1), Some(&"hello".to_string())); + assert_eq!(store.get(&key2), Some(&"world".to_string())); + assert_eq!(store.get(&0), None); + assert_eq!(store.get_all(vec![&key1, &key2, &0]), vec![Some(&"hello".to_string()), Some(&"world".to_string()), None]); + } + +} From aabfe7a5a275a94f4a655e5d0efadb0956802f9e Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 13:27:52 +0200 Subject: [PATCH 13/28] Add AnyValType --- kermit-kvs/src/naivestore.rs | 53 ++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 6bdb8c1..b60ba73 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -3,7 +3,7 @@ use { nohash_hasher::BuildNoHashHasher, std::{ collections::HashMap, - hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash}, + hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, }, }; @@ -22,7 +22,9 @@ where HB: BuildHasher, { fn add(&mut self, val: VT) -> u64 { - let hash = self.hash_builder.hash_one(&val); + let mut hasher = self.hash_builder.build_hasher(); + val.hash(&mut hasher); + let hash = hasher.finish(); self.map.insert(hash, val); hash } @@ -31,9 +33,7 @@ where val.into_iter().map(|v| self.add(v)).collect() } - fn get(&self, key: &u64) -> Option<&VT> { - self.map.get(key) - } + fn get(&self, key: &u64) -> Option<&VT> { self.map.get(key) } fn get_all(&self, key: Vec<&u64>) -> Vec> { key.into_iter().map(|k| self.get(k)).collect() @@ -65,6 +65,27 @@ where } } +#[derive(Debug, Clone, PartialEq)] +pub enum AnyValType { + Str(String), + I32(i32), + I64(i64), + F32(f32), + F64(f64), +} + +impl Hash for AnyValType { + fn hash(&self, state: &mut H) { + match self { + | AnyValType::Str(v) => v.hash(state), + | AnyValType::I32(v) => v.hash(state), + | AnyValType::I64(v) => v.hash(state), + | AnyValType::F32(v) => v.to_bits().hash(state), + | AnyValType::F64(v) => v.to_bits().hash(state), + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -77,7 +98,27 @@ mod tests { assert_eq!(store.get(&key1), Some(&"hello".to_string())); assert_eq!(store.get(&key2), Some(&"world".to_string())); assert_eq!(store.get(&0), None); - assert_eq!(store.get_all(vec![&key1, &key2, &0]), vec![Some(&"hello".to_string()), Some(&"world".to_string()), None]); + assert_eq!(store.get_all(vec![&key1, &key2, &0]), vec![ + Some(&"hello".to_string()), + Some(&"world".to_string()), + None + ]); } + #[test] + fn test_anyvaltype() { + let mut store = NaiveStore::::default(); + let str_key1 = store.add(AnyValType::Str("hello".to_string())); + let str_key2 = store.add(AnyValType::Str("world".to_string())); + assert_eq!( + store.get(&str_key1), + Some(&AnyValType::Str("hello".to_string())) + ); + assert_eq!( + store.get(&str_key2), + Some(&AnyValType::Str("world".to_string())) + ); + let float_key1 = store.add(AnyValType::F64(0.5)); + assert_eq!(store.get(&float_key1), Some(&AnyValType::F64(0.5))); + } } From 8a1f261e469057c942ea874999ae9eff96380c7f Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 13:36:53 +0200 Subject: [PATCH 14/28] Move anyvaltype into own crate --- kermit-kvs/src/anyvaltype.rs | 87 ++++++++++++++++++++++++++++++++++++ kermit-kvs/src/lib.rs | 1 + kermit-kvs/src/naivestore.rs | 22 +-------- 3 files changed, 89 insertions(+), 21 deletions(-) create mode 100644 kermit-kvs/src/anyvaltype.rs diff --git a/kermit-kvs/src/anyvaltype.rs b/kermit-kvs/src/anyvaltype.rs new file mode 100644 index 0000000..a745435 --- /dev/null +++ b/kermit-kvs/src/anyvaltype.rs @@ -0,0 +1,87 @@ +use std::hash::Hash; + +#[derive(Debug, Clone, PartialEq)] +pub enum AnyValType { + Str(String), + I32(i32), + I64(i64), + F32(f32), + F64(f64), +} + +// To Methods + +impl AnyValType { + pub fn to_str(&self) -> Option<&str> { + match self { + | AnyValType::Str(v) => Some(v), + | _ => None, + } + } + + pub fn to_i32(&self) -> Option { + match self { + | AnyValType::I32(v) => Some(*v), + | _ => None, + } + } + + pub fn to_i64(&self) -> Option { + match self { + | AnyValType::I64(v) => Some(*v), + | _ => None, + } + } + + pub fn to_f32(&self) -> Option { + match self { + | AnyValType::F32(v) => Some(*v), + | _ => None, + } + } + + pub fn to_f64(&self) -> Option { + match self { + | AnyValType::F64(v) => Some(*v), + | _ => None, + } + } +} + +// From Methods + +impl From<&str> for AnyValType { + fn from(v: &str) -> Self { AnyValType::Str(v.to_string()) } +} + +impl From for AnyValType { + fn from(v: String) -> Self { AnyValType::Str(v) } +} + +impl From for AnyValType { + fn from(v: i32) -> Self { AnyValType::I32(v) } +} + +impl From for AnyValType { + fn from(v: i64) -> Self { AnyValType::I64(v) } +} + +impl From for AnyValType { + fn from(v: f32) -> Self { AnyValType::F32(v) } +} + +impl From for AnyValType { + fn from(v: f64) -> Self { AnyValType::F64(v) } +} + +impl Hash for AnyValType { + fn hash(&self, state: &mut H) { + match self { + | AnyValType::Str(v) => v.hash(state), + | AnyValType::I32(v) => v.hash(state), + | AnyValType::I64(v) => v.hash(state), + | AnyValType::F32(v) => v.to_bits().hash(state), + | AnyValType::F64(v) => v.to_bits().hash(state), + } + } +} diff --git a/kermit-kvs/src/lib.rs b/kermit-kvs/src/lib.rs index a6577f5..37efdaf 100644 --- a/kermit-kvs/src/lib.rs +++ b/kermit-kvs/src/lib.rs @@ -1,2 +1,3 @@ pub mod keyvalstore; pub mod naivestore; +pub mod anyvaltype; diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index b60ba73..b96468d 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -65,30 +65,10 @@ where } } -#[derive(Debug, Clone, PartialEq)] -pub enum AnyValType { - Str(String), - I32(i32), - I64(i64), - F32(f32), - F64(f64), -} - -impl Hash for AnyValType { - fn hash(&self, state: &mut H) { - match self { - | AnyValType::Str(v) => v.hash(state), - | AnyValType::I32(v) => v.hash(state), - | AnyValType::I64(v) => v.hash(state), - | AnyValType::F32(v) => v.to_bits().hash(state), - | AnyValType::F64(v) => v.to_bits().hash(state), - } - } -} - #[cfg(test)] mod tests { use super::*; + use crate::anyvaltype::*; #[test] fn test_default() { From d68ef3d4179143d65d60f84dc2bad3f694e008af Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 13:37:25 +0200 Subject: [PATCH 15/28] Refactor --- kermit-kvs/src/naivestore.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index b96468d..07a0ac1 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -45,10 +45,10 @@ where VT: Hash + Clone, HB: BuildHasher, { - pub fn with_hasher(hasher: HB) -> Self { + pub fn with_hasher(hasher_builder: HB) -> Self { Self { map: HashMap::with_hasher(BuildNoHashHasher::::default()), - hash_builder: hasher, + hash_builder: hasher_builder, } } } From 41e8f4970fcdfd2a1bfa8549e08312ac9b611158 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 13:45:56 +0200 Subject: [PATCH 16/28] Refactor --- kermit-kvs/src/anyvaltype.rs | 3 ++- kermit-kvs/src/naivestore.rs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kermit-kvs/src/anyvaltype.rs b/kermit-kvs/src/anyvaltype.rs index a745435..247dd75 100644 --- a/kermit-kvs/src/anyvaltype.rs +++ b/kermit-kvs/src/anyvaltype.rs @@ -12,7 +12,7 @@ pub enum AnyValType { // To Methods impl AnyValType { - pub fn to_str(&self) -> Option<&str> { + pub fn to_string(&self) -> Option<&String> { match self { | AnyValType::Str(v) => Some(v), | _ => None, @@ -46,6 +46,7 @@ impl AnyValType { | _ => None, } } + } // From Methods diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 07a0ac1..36d3b35 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -88,15 +88,15 @@ mod tests { #[test] fn test_anyvaltype() { let mut store = NaiveStore::::default(); - let str_key1 = store.add(AnyValType::Str("hello".to_string())); - let str_key2 = store.add(AnyValType::Str("world".to_string())); + let str_key1 = store.add(AnyValType::from("hello")); + let str_key2 = store.add(AnyValType::from("world")); assert_eq!( store.get(&str_key1), - Some(&AnyValType::Str("hello".to_string())) + Some(&AnyValType::from("hello")) ); assert_eq!( store.get(&str_key2), - Some(&AnyValType::Str("world".to_string())) + Some(&AnyValType::from("world")) ); let float_key1 = store.add(AnyValType::F64(0.5)); assert_eq!(store.get(&float_key1), Some(&AnyValType::F64(0.5))); From 50bbf2db62976b72be9fdae66ae8400260ba02f1 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Fri, 16 Aug 2024 14:22:00 +0200 Subject: [PATCH 17/28] Add type id to hash --- kermit-kvs/src/anyvaltype.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kermit-kvs/src/anyvaltype.rs b/kermit-kvs/src/anyvaltype.rs index 247dd75..3de3a5f 100644 --- a/kermit-kvs/src/anyvaltype.rs +++ b/kermit-kvs/src/anyvaltype.rs @@ -1,4 +1,4 @@ -use std::hash::Hash; +use std::{any::TypeId, hash::Hash}; #[derive(Debug, Clone, PartialEq)] pub enum AnyValType { @@ -78,11 +78,11 @@ impl From for AnyValType { impl Hash for AnyValType { fn hash(&self, state: &mut H) { match self { - | AnyValType::Str(v) => v.hash(state), - | AnyValType::I32(v) => v.hash(state), - | AnyValType::I64(v) => v.hash(state), - | AnyValType::F32(v) => v.to_bits().hash(state), - | AnyValType::F64(v) => v.to_bits().hash(state), + | AnyValType::Str(v) => (TypeId::of::(), v).hash(state), + | AnyValType::I32(v) => (TypeId::of::(), v).hash(state), + | AnyValType::I64(v) => (TypeId::of::(), v).hash(state), + | AnyValType::F32(v) => (TypeId::of::(), v.to_bits()).hash(state), + | AnyValType::F64(v) => (TypeId::of::(), v.to_bits()).hash(state), } } } From 86304484c4e3156c7ee5c0910ff4e7c94dfd3e49 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:14:06 +0200 Subject: [PATCH 18/28] Add defaults and parsing functions to AnyValType --- kermit-kvs/src/anyvaltype.rs | 39 +++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/kermit-kvs/src/anyvaltype.rs b/kermit-kvs/src/anyvaltype.rs index 3de3a5f..1e528f6 100644 --- a/kermit-kvs/src/anyvaltype.rs +++ b/kermit-kvs/src/anyvaltype.rs @@ -9,6 +9,44 @@ pub enum AnyValType { F64(f64), } +// Defaults + +impl AnyValType { + pub fn default_str() -> Self { AnyValType::Str(String::new()) } + + pub fn default_i32() -> Self { AnyValType::I32(0) } + + pub fn default_i64() -> Self { AnyValType::I64(0) } + + pub fn default_f32() -> Self { AnyValType::F32(0.0) } + + pub fn default_f64() -> Self { AnyValType::F64(0.0) } +} + +// Parsing + +impl AnyValType { + pub fn parse_str(v: &str) -> Self { AnyValType::Str(v.to_string()) } + + pub fn parse_i32(v: &str) -> Self { AnyValType::I32(v.parse().unwrap()) } + + pub fn parse_i64(v: &str) -> Self { AnyValType::I64(v.parse().unwrap()) } + + pub fn parse_f32(v: &str) -> Self { AnyValType::F32(v.parse().unwrap()) } + + pub fn parse_f64(v: &str) -> Self { AnyValType::F64(v.parse().unwrap()) } + + pub fn parse_into_self(&self, v: &str) -> Self { + match self { + | AnyValType::Str(_) => AnyValType::parse_str(v), + | AnyValType::I32(_) => AnyValType::parse_i32(v), + | AnyValType::I64(_) => AnyValType::parse_i64(v), + | AnyValType::F32(_) => AnyValType::parse_f32(v), + | AnyValType::F64(_) => AnyValType::parse_f64(v), + } + } +} + // To Methods impl AnyValType { @@ -46,7 +84,6 @@ impl AnyValType { | _ => None, } } - } // From Methods From 35ab0addbaf4d6b5f374af36f725c5eb76cd065d Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:14:30 +0200 Subject: [PATCH 19/28] Add csv dep --- kermit-kvs/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/kermit-kvs/Cargo.toml b/kermit-kvs/Cargo.toml index fd87fd7..c238b06 100644 --- a/kermit-kvs/Cargo.toml +++ b/kermit-kvs/Cargo.toml @@ -10,4 +10,5 @@ readme.workspace = true repository.workspace = true [dependencies] +csv = "1.1" nohash-hasher = "0.2.0" From 672fc43f3503dcf4ca2795921d838f88f3ea1714 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:14:40 +0200 Subject: [PATCH 20/28] Add add_file function --- kermit-kvs/src/keyvalstore.rs | 1 + kermit-kvs/src/naivestore.rs | 50 ++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/kermit-kvs/src/keyvalstore.rs b/kermit-kvs/src/keyvalstore.rs index 1fcb127..56061d5 100644 --- a/kermit-kvs/src/keyvalstore.rs +++ b/kermit-kvs/src/keyvalstore.rs @@ -9,4 +9,5 @@ where fn add_all(&mut self, val: Vec) -> Vec; fn get(&self, key: &KT) -> Option<&VT>; fn get_all(&self, key: Vec<&KT>) -> Vec>; + fn keys(&self) -> Vec; } diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 36d3b35..c771298 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -1,10 +1,7 @@ use { - crate::keyvalstore::KeyValStore, - nohash_hasher::BuildNoHashHasher, - std::{ - collections::HashMap, - hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, - }, + crate::{anyvaltype::AnyValType, keyvalstore::KeyValStore}, csv::Error, nohash_hasher::BuildNoHashHasher, std::{ + collections::HashMap, fs::File, hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, path::Path + } }; pub struct NaiveStore @@ -38,6 +35,10 @@ where fn get_all(&self, key: Vec<&u64>) -> Vec> { key.into_iter().map(|k| self.get(k)).collect() } + + fn keys(&self) -> Vec { + self.map.keys().cloned().collect() + } } impl NaiveStore @@ -53,6 +54,30 @@ where } } +impl NaiveStore where HB: BuildHasher { + pub fn add_file>(&mut self, types: Vec, filepath: P) -> Result<(), Error> { + let file = File::open(filepath)?; + let mut rdr = csv::ReaderBuilder::new() + .has_headers(false) + .delimiter(b',') + .double_quote(false) + .escape(Some(b'\\')) + .flexible(false) + .comment(Some(b'#')) + .from_reader(file); + for result in rdr.records() { + let record = result?; + for (i, x) in record.iter().enumerate() { + let t = &types[i]; + let val = t.parse_into_self(x); + self.add(val); + } + + } + Ok(()) + } +} + impl Default for NaiveStore> where VT: Hash + Clone, @@ -67,8 +92,7 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::anyvaltype::*; + use {super::*, crate::anyvaltype::*}; #[test] fn test_default() { @@ -90,14 +114,8 @@ mod tests { let mut store = NaiveStore::::default(); let str_key1 = store.add(AnyValType::from("hello")); let str_key2 = store.add(AnyValType::from("world")); - assert_eq!( - store.get(&str_key1), - Some(&AnyValType::from("hello")) - ); - assert_eq!( - store.get(&str_key2), - Some(&AnyValType::from("world")) - ); + assert_eq!(store.get(&str_key1), Some(&AnyValType::from("hello"))); + assert_eq!(store.get(&str_key2), Some(&AnyValType::from("world"))); let float_key1 = store.add(AnyValType::F64(0.5)); assert_eq!(store.get(&float_key1), Some(&AnyValType::F64(0.5))); } From 87da81b1ec8833b225a9c727b2039fb7c1ee0834 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:20:53 +0200 Subject: [PATCH 21/28] Move tests --- kermit-kvs/src/naivestore.rs | 30 ------------------ kermit-kvs/tests/naivestore.rs | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 kermit-kvs/tests/naivestore.rs diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index c771298..9a9eace 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -90,33 +90,3 @@ where } } -#[cfg(test)] -mod tests { - use {super::*, crate::anyvaltype::*}; - - #[test] - fn test_default() { - let mut store = NaiveStore::::default(); - let key1 = store.add("hello".to_string()); - let key2 = store.add("world".to_string()); - assert_eq!(store.get(&key1), Some(&"hello".to_string())); - assert_eq!(store.get(&key2), Some(&"world".to_string())); - assert_eq!(store.get(&0), None); - assert_eq!(store.get_all(vec![&key1, &key2, &0]), vec![ - Some(&"hello".to_string()), - Some(&"world".to_string()), - None - ]); - } - - #[test] - fn test_anyvaltype() { - let mut store = NaiveStore::::default(); - let str_key1 = store.add(AnyValType::from("hello")); - let str_key2 = store.add(AnyValType::from("world")); - assert_eq!(store.get(&str_key1), Some(&AnyValType::from("hello"))); - assert_eq!(store.get(&str_key2), Some(&AnyValType::from("world"))); - let float_key1 = store.add(AnyValType::F64(0.5)); - assert_eq!(store.get(&float_key1), Some(&AnyValType::F64(0.5))); - } -} diff --git a/kermit-kvs/tests/naivestore.rs b/kermit-kvs/tests/naivestore.rs new file mode 100644 index 0000000..fe64350 --- /dev/null +++ b/kermit-kvs/tests/naivestore.rs @@ -0,0 +1,56 @@ +#[cfg(test)] +mod tests { + use kermit_kvs::{anyvaltype::*, keyvalstore::*, naivestore::*}; + + #[test] + fn test_default() { + let mut store = NaiveStore::::default(); + let key1 = store.add("hello".to_string()); + let key2 = store.add("world".to_string()); + assert_eq!(store.get(&key1), Some(&"hello".to_string())); + assert_eq!(store.get(&key2), Some(&"world".to_string())); + assert_eq!(store.get(&0), None); + assert_eq!(store.get_all(vec![&key1, &key2, &0]), vec![ + Some(&"hello".to_string()), + Some(&"world".to_string()), + None + ]); + } + + #[test] + fn test_anyvaltype() { + let mut store = NaiveStore::::default(); + let str_key1 = store.add(AnyValType::from("hello")); + let str_key2 = store.add(AnyValType::from("world")); + assert_eq!(store.get(&str_key1), Some(&AnyValType::from("hello"))); + assert_eq!(store.get(&str_key2), Some(&AnyValType::from("world"))); + let float_key1 = store.add(AnyValType::F64(0.5)); + assert_eq!(store.get(&float_key1), Some(&AnyValType::F64(0.5))); + } + + #[test] + fn read_file() { + let mut store = NaiveStore::::default(); + store + .add_file( + vec![ + AnyValType::default_str(), + AnyValType::default_str(), + AnyValType::default_str(), + ], + "test1.csv", + ) + .unwrap(); + store + .add_file( + vec![ + AnyValType::default_str(), + AnyValType::default_str(), + AnyValType::default_i32(), + AnyValType::default_i32(), + ], + "test2.csv", + ) + .unwrap(); + } +} From 529709214c90c4d8f0c0a70dc9ec8b7ab94b8e6c Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:23:03 +0200 Subject: [PATCH 22/28] Add size() --- kermit-kvs/src/keyvalstore.rs | 1 + kermit-kvs/src/naivestore.rs | 4 ++++ kermit-kvs/tests/naivestore.rs | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kermit-kvs/src/keyvalstore.rs b/kermit-kvs/src/keyvalstore.rs index 56061d5..3335ae2 100644 --- a/kermit-kvs/src/keyvalstore.rs +++ b/kermit-kvs/src/keyvalstore.rs @@ -10,4 +10,5 @@ where fn get(&self, key: &KT) -> Option<&VT>; fn get_all(&self, key: Vec<&KT>) -> Vec>; fn keys(&self) -> Vec; + fn size(&self) -> usize; } diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 9a9eace..7a4ef52 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -39,6 +39,10 @@ where fn keys(&self) -> Vec { self.map.keys().cloned().collect() } + + fn size(&self) -> usize { + self.map.len() + } } impl NaiveStore diff --git a/kermit-kvs/tests/naivestore.rs b/kermit-kvs/tests/naivestore.rs index fe64350..a763534 100644 --- a/kermit-kvs/tests/naivestore.rs +++ b/kermit-kvs/tests/naivestore.rs @@ -38,7 +38,7 @@ mod tests { AnyValType::default_str(), AnyValType::default_str(), ], - "test1.csv", + "tests/test1.csv", ) .unwrap(); store @@ -49,7 +49,7 @@ mod tests { AnyValType::default_i32(), AnyValType::default_i32(), ], - "test2.csv", + "tests/test2.csv", ) .unwrap(); } From 3e7fcde14cfcf9dd2b8630c4c3da474be48d2130 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:25:38 +0200 Subject: [PATCH 23/28] Add test files --- kermit-kvs/tests/naivestore.rs | 6 ++++-- kermit-kvs/tests/test1.csv.test | 2 ++ kermit-kvs/tests/test2.csv.test | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 kermit-kvs/tests/test1.csv.test create mode 100644 kermit-kvs/tests/test2.csv.test diff --git a/kermit-kvs/tests/naivestore.rs b/kermit-kvs/tests/naivestore.rs index a763534..dc77aeb 100644 --- a/kermit-kvs/tests/naivestore.rs +++ b/kermit-kvs/tests/naivestore.rs @@ -38,9 +38,10 @@ mod tests { AnyValType::default_str(), AnyValType::default_str(), ], - "tests/test1.csv", + "tests/test1.csv.test", ) .unwrap(); + assert_eq!(5, store.size()); store .add_file( vec![ @@ -49,8 +50,9 @@ mod tests { AnyValType::default_i32(), AnyValType::default_i32(), ], - "tests/test2.csv", + "tests/test2.csv.test", ) .unwrap(); + assert_eq!(11, store.size()); } } diff --git a/kermit-kvs/tests/test1.csv.test b/kermit-kvs/tests/test1.csv.test new file mode 100644 index 0000000..364deca --- /dev/null +++ b/kermit-kvs/tests/test1.csv.test @@ -0,0 +1,2 @@ +Apple,Is,Delicious +Banana,Is,Yellow diff --git a/kermit-kvs/tests/test2.csv.test b/kermit-kvs/tests/test2.csv.test new file mode 100644 index 0000000..d5def87 --- /dev/null +++ b/kermit-kvs/tests/test2.csv.test @@ -0,0 +1,2 @@ +house,locatedat,0,5 +chair,locatedat,2,5 From 04498e4aff6b802e365998043e380597d3230ede Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:29:20 +0200 Subject: [PATCH 24/28] Add contains_key() and contains_val() --- kermit-kvs/src/keyvalstore.rs | 2 ++ kermit-kvs/src/naivestore.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/kermit-kvs/src/keyvalstore.rs b/kermit-kvs/src/keyvalstore.rs index 3335ae2..ca1eafc 100644 --- a/kermit-kvs/src/keyvalstore.rs +++ b/kermit-kvs/src/keyvalstore.rs @@ -11,4 +11,6 @@ where fn get_all(&self, key: Vec<&KT>) -> Vec>; fn keys(&self) -> Vec; fn size(&self) -> usize; + fn contains_key(&self, key: &KT) -> bool; + fn contains_val(&self, val: &VT) -> bool; } diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 7a4ef52..23f6045 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -43,6 +43,14 @@ where fn size(&self) -> usize { self.map.len() } + + fn contains_key(&self, key: &u64) -> bool { + self.map.contains_key(key) + } + + fn contains_val(&self, val: &VT) -> bool { + self.contains_key(&self.hash_builder.hash_one(val)) + } } impl NaiveStore From f250732550293166aa10a585d500e34a40148fdd Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:36:35 +0200 Subject: [PATCH 25/28] Add more asserts to read_file test --- kermit-kvs/tests/naivestore.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kermit-kvs/tests/naivestore.rs b/kermit-kvs/tests/naivestore.rs index dc77aeb..f97fdb4 100644 --- a/kermit-kvs/tests/naivestore.rs +++ b/kermit-kvs/tests/naivestore.rs @@ -42,6 +42,11 @@ mod tests { ) .unwrap(); assert_eq!(5, store.size()); + assert!(store.contains_val(&"Apple".into())); + assert!(store.contains_val(&"Is".into())); + assert!(store.contains_val(&"Delicious".into())); + assert!(store.contains_val(&"Banana".into())); + assert!(store.contains_val(&"Yellow".into())); store .add_file( vec![ @@ -54,5 +59,11 @@ mod tests { ) .unwrap(); assert_eq!(11, store.size()); + assert!(store.contains_val(&"house".into())); + assert!(store.contains_val(&"locatedat".into())); + assert!(store.contains_val(&0_i32.into())); + assert!(store.contains_val(&5_i32.into())); + assert!(store.contains_val(&2_i32.into())); + assert!(store.contains_val(&"chair".into())); } } From 103034a4bcaa5b2e194b8cf4b8c544ca481aaa8f Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:41:32 +0200 Subject: [PATCH 26/28] Format --- kermit-kvs/src/lib.rs | 2 +- kermit-kvs/src/naivestore.rs | 39 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/kermit-kvs/src/lib.rs b/kermit-kvs/src/lib.rs index 37efdaf..37751d0 100644 --- a/kermit-kvs/src/lib.rs +++ b/kermit-kvs/src/lib.rs @@ -1,3 +1,3 @@ +pub mod anyvaltype; pub mod keyvalstore; pub mod naivestore; -pub mod anyvaltype; diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 23f6045..8336d9c 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -1,7 +1,13 @@ use { - crate::{anyvaltype::AnyValType, keyvalstore::KeyValStore}, csv::Error, nohash_hasher::BuildNoHashHasher, std::{ - collections::HashMap, fs::File, hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, path::Path - } + crate::{anyvaltype::AnyValType, keyvalstore::KeyValStore}, + csv::Error, + nohash_hasher::BuildNoHashHasher, + std::{ + collections::HashMap, + fs::File, + hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, + path::Path, + }, }; pub struct NaiveStore @@ -36,21 +42,13 @@ where key.into_iter().map(|k| self.get(k)).collect() } - fn keys(&self) -> Vec { - self.map.keys().cloned().collect() - } + fn keys(&self) -> Vec { self.map.keys().cloned().collect() } - fn size(&self) -> usize { - self.map.len() - } + fn size(&self) -> usize { self.map.len() } - fn contains_key(&self, key: &u64) -> bool { - self.map.contains_key(key) - } + fn contains_key(&self, key: &u64) -> bool { self.map.contains_key(key) } - fn contains_val(&self, val: &VT) -> bool { - self.contains_key(&self.hash_builder.hash_one(val)) - } + fn contains_val(&self, val: &VT) -> bool { self.contains_key(&self.hash_builder.hash_one(val)) } } impl NaiveStore @@ -66,8 +64,13 @@ where } } -impl NaiveStore where HB: BuildHasher { - pub fn add_file>(&mut self, types: Vec, filepath: P) -> Result<(), Error> { +impl NaiveStore +where + HB: BuildHasher, +{ + pub fn add_file>( + &mut self, types: Vec, filepath: P, + ) -> Result<(), Error> { let file = File::open(filepath)?; let mut rdr = csv::ReaderBuilder::new() .has_headers(false) @@ -84,7 +87,6 @@ impl NaiveStore where HB: BuildHasher { let val = t.parse_into_self(x); self.add(val); } - } Ok(()) } @@ -101,4 +103,3 @@ where } } } - From 5bbfc4c0d251ea0b094a4c0bd481835e3686aab1 Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:42:55 +0200 Subject: [PATCH 27/28] Fix clippy warning --- kermit-kvs/src/naivestore.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index 8336d9c..d5dd3e4 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -25,9 +25,7 @@ where HB: BuildHasher, { fn add(&mut self, val: VT) -> u64 { - let mut hasher = self.hash_builder.build_hasher(); - val.hash(&mut hasher); - let hash = hasher.finish(); + let hash = self.hash_builder.hash_one(&val); self.map.insert(hash, val); hash } From 60b68c8f720c5aa3547d22dbdf97a2c011b8f28b Mon Sep 17 00:00:00 2001 From: Aidan Bailey Date: Sat, 17 Aug 2024 11:43:15 +0200 Subject: [PATCH 28/28] Fix clippy warning --- kermit-kvs/src/naivestore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kermit-kvs/src/naivestore.rs b/kermit-kvs/src/naivestore.rs index d5dd3e4..e9ef53c 100644 --- a/kermit-kvs/src/naivestore.rs +++ b/kermit-kvs/src/naivestore.rs @@ -5,7 +5,7 @@ use { std::{ collections::HashMap, fs::File, - hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash, Hasher}, + hash::{BuildHasher, BuildHasherDefault, DefaultHasher, Hash}, path::Path, }, };