async_ecs/storage/
btree_storage.rs

1use std::collections::BTreeMap;
2
3use hibitset::BitSetLike;
4
5use crate::entity::Index;
6
7use super::{DistinctStorage, Storage};
8
9pub struct BTreeStorage<T>(BTreeMap<Index, T>);
10
11impl<T> Default for BTreeStorage<T> {
12    fn default() -> Self {
13        Self(Default::default())
14    }
15}
16
17impl<T> Storage<T> for BTreeStorage<T> {
18    unsafe fn get(&self, index: Index) -> &T {
19        &self.0[&index]
20    }
21
22    unsafe fn get_mut(&mut self, index: Index) -> &mut T {
23        self.0.get_mut(&index).unwrap()
24    }
25
26    unsafe fn insert(&mut self, index: Index, value: T) {
27        self.0.insert(index, value);
28    }
29
30    unsafe fn remove(&mut self, index: Index) -> T {
31        self.0.remove(&index).unwrap()
32    }
33
34    unsafe fn clean<B>(&mut self, _has: B)
35    where
36        B: BitSetLike,
37    {
38    }
39}
40
41impl<T> DistinctStorage for BTreeStorage<T> {}