The following code works as expected and prints the value after the get().
fn test_skipmap() {
let mut map: HashMap<Arc<Vector>, String> = HashMap::new();
let v = Arc::new(Vector::randomized(3));
let v2 = Arc::new(Vector::randomized(3));
let v3 = Arc::new(Vector::randomized(3));
map.insert(Arc::clone(&v), "Harry".into());
map.insert(Arc::clone(&v2), "Neville".into());
map.insert(Arc::clone(&v3), "Ron".into());
println!("map len {}", map.len());
let val = map.get(Arc::clone(&v).as_ref());
if let Some(val) = val {
println!("val is {}", val);
}
}
Vector is some struct that implements all the requisite traits to be used as a key in a HashMap. However if I change the HashMap to be Crossbeam SkipMap my get() always fails. What am I missing?
Crossbeam’s SkipMap is an ordered map. This requires the keys to implement Ord, which is a requirement different from the Eq + Hash that hashmaps require for their keys.
But maybe your issue is unrelated to this. In any case, you should better explain what exactly you mean with “my get() always fails”. “Fails” as in compilation error or panic, or does it return None? If it’s the latter, you could try making the Ord implementation explicit (in case it isn’t already – also, rust analyzer can help with that whilst keeping the default behavior of the derived one) and add some println debugging to it to see if it gets called properly and behaves as expected; if it’s a compilation error or panic, you should share the error.