-
Notifications
You must be signed in to change notification settings - Fork 167
Open
Labels
Description
Consider following rust code, which compares usage of HashMap and StateMap:
use std::collections::HashMap;
use sov_state::{DefaultStorageSpec, Prefix, ProverStorage, StateMap, WorkingSet};
pub fn hashmap() {
let mut map: HashMap<Vec<u8>, u64> = HashMap::new();
map.insert(vec![1, 2, 3], 1);
map.insert(vec![4, 5, 6], 2);
map.insert(vec![7, 8, 9], 3);
println!("HASH MAP: {:?}", map);
let check_this: [u8; 3] = [1, 2, 3];
let v = map.get(&check_this[..]);
assert!(v.is_some());
assert_eq!(v, Some(&1));
}
pub fn sovstatemap() {
let tmpdir = tempfile::tempdir().unwrap();
let mut working_set = WorkingSet::new(ProverStorage::<DefaultStorageSpec>::with_path(tmpdir.path()).unwrap());
let map: StateMap<Vec<u8>, u64> = StateMap::new(Prefix::new(vec![1, 2, 3]));
let a = vec![1, 2, 3];
let b = vec![4, 5, 6];
let c = vec![7, 8, 9];
map.set(&a, &1, &mut working_set);
map.set(&b, &2, &mut working_set);
map.set(&c, &3, &mut working_set);
// Uncomment this to get compiler error
// let check_this: [u8; 3] = [1, 2, 3];
// let v = map.get(&check_this[..]);
// assert!(v.is_some());
}It would be nice to be able to use slice the same as with standard HashMap, it will remove some unnecessary clonings in default STF.
Reactions are currently unavailable