1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::{
    funvec_ref::FunVecRef,
    funvec_val::FunVec,
    index::{FromIndex, IntoIndex},
};
use std::{
    collections::{BTreeMap, HashMap},
    hash::Hash,
};

// val
impl<const DIM: usize, Key, T> FunVec<DIM, T> for HashMap<Key, T>
where
    Key: FromIndex<DIM> + PartialEq + Eq + Hash,
    T: Clone + Copy,
{
    #[inline(always)]
    fn at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<T> {
        let index = Key::from_index(index.into_index());
        self.get(&index).copied()
    }
}
impl<const DIM: usize, Key, T> FunVec<DIM, T> for BTreeMap<Key, T>
where
    Key: FromIndex<DIM> + Ord,
    T: Clone + Copy,
{
    #[inline(always)]
    fn at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<T> {
        let index = Key::from_index(index.into_index());
        self.get(&index).copied()
    }
}

// ref
impl<const DIM: usize, Key, T> FunVecRef<DIM, T> for HashMap<Key, T>
where
    Key: FromIndex<DIM> + PartialEq + Eq + Hash,
{
    #[inline(always)]
    fn ref_at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<&T> {
        let index = Key::from_index(index.into_index());
        self.get(&index)
    }
}
impl<const DIM: usize, Key, T> FunVecRef<DIM, T> for BTreeMap<Key, T>
where
    Key: FromIndex<DIM> + Ord,
{
    #[inline(always)]
    fn ref_at<Idx: IntoIndex<DIM>>(&self, index: Idx) -> Option<&T> {
        let index = Key::from_index(index.into_index());
        self.get(&index)
    }
}