summaryrefslogtreecommitdiff
path: root/ecs/src/util.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-02-06 13:38:46 +0100
committerHampusM <hampus@hampusmat.com>2025-02-12 21:29:41 +0100
commit64eddc633cea0f4bc5603cc2d4c4c6eafac5c177 (patch)
tree3248da82180c4307f4b7ca2a71c16dec32fb8cb3 /ecs/src/util.rs
parent2a8718f7c671ab1fc5e38340b467e2bd77f16cc0 (diff)
refactor(ecs): rewrite component storageHEADmaster
Diffstat (limited to 'ecs/src/util.rs')
-rw-r--r--ecs/src/util.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/ecs/src/util.rs b/ecs/src/util.rs
index 0273b18..71021cd 100644
--- a/ecs/src/util.rs
+++ b/ecs/src/util.rs
@@ -1,5 +1,38 @@
+use std::hash::Hash;
use std::ops::BitAnd;
+use hashbrown::HashMap;
+
+pub trait HashMapExt<Key, Value>
+{
+ /// Returns true if the keys are a subset of another [`HashMap`]'s keys, i.e., `other`
+ /// contains at least all the keys in `self`.
+ fn keys_is_subset(&self, other: &Self) -> bool;
+
+ /// Returns true if the keys are a superset of another [`HashMap`]'s keys, i.e.,
+ /// `self` contains at least all the keys in `other`.
+ fn keys_is_superset(&self, other: &Self) -> bool;
+}
+
+impl<Key, Value> HashMapExt<Key, Value> for HashMap<Key, Value>
+where
+ Key: Eq + Hash,
+{
+ fn keys_is_subset(&self, other: &Self) -> bool
+ {
+ if self.len() <= other.len() {
+ self.keys().all(|key| other.contains_key(key))
+ } else {
+ false
+ }
+ }
+
+ fn keys_is_superset(&self, other: &Self) -> bool
+ {
+ other.keys_is_subset(self)
+ }
+}
+
pub trait Array<Item>:
AsRef<[Item]>
+ AsMut<[Item]>