1use crate::{
2 funvec_ref::FunVecRef,
3 funvec_val::FunVec,
4 index::{FromIndex, IntoIndex},
5};
6use std::{
7 collections::{BTreeMap, HashMap},
8 hash::Hash,
9};
10
11impl<const DIM: usize, Key, T> FunVec<DIM, T> for HashMap<Key, T>
13where
14 Key: FromIndex<DIM> + PartialEq + Eq + Hash,
15 T: Clone + Copy,
16{
17 #[inline(always)]
18 fn at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<T> {
19 let index = Key::from_index(index.into_index());
20 self.get(&index).copied()
21 }
22}
23impl<const DIM: usize, Key, T> FunVec<DIM, T> for BTreeMap<Key, T>
24where
25 Key: FromIndex<DIM> + Ord,
26 T: Clone + Copy,
27{
28 #[inline(always)]
29 fn at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<T> {
30 let index = Key::from_index(index.into_index());
31 self.get(&index).copied()
32 }
33}
34
35impl<const DIM: usize, Key, T> FunVecRef<DIM, T> for HashMap<Key, T>
37where
38 Key: FromIndex<DIM> + PartialEq + Eq + Hash,
39{
40 #[inline(always)]
41 fn ref_at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<&T> {
42 let index = Key::from_index(index.into_index());
43 self.get(&index)
44 }
45}
46impl<const DIM: usize, Key, T> FunVecRef<DIM, T> for BTreeMap<Key, T>
47where
48 Key: FromIndex<DIM> + Ord,
49{
50 #[inline(always)]
51 fn ref_at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<&T> {
52 let index = Key::from_index(index.into_index());
53 self.get(&index)
54 }
55}