aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/astar/nodemap.rs
blob: 62d97c9c4b29bcc51b6b9d128bbe4502f9841063 (plain)
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
use std::hash::{BuildHasherDefault, Hash};

use indexmap::{IndexMap, map::Entry};
use rustc_hash::FxHasher;

use crate::pathfinder::astar::Node;

type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;

pub struct NodeMap<P> {
    map: FxIndexMap<P, Node>,
}
impl<P: Hash + Eq> NodeMap<P> {
    pub fn insert(&mut self, key: P, value: Node) {
        self.map.insert(key, value);
    }
    pub fn get_index(&self, index: u32) -> Option<(&P, &Node)> {
        self.map.get_index(index as usize)
    }
    pub fn entry(&mut self, key: P) -> Entry<'_, P, Node> {
        self.map.entry(key)
    }
}
impl<P> Default for NodeMap<P> {
    fn default() -> Self {
        Self {
            map: Default::default(),
        }
    }
}