1use crate::entity::{Entity, EntityId};
4use crate::hashing::IndexSet;
5use crate::prelude::{IndexableProperty, Property};
6
7mod full_index;
8mod value_count_index;
9
10pub use full_index::*;
11pub use value_count_index::*;
12
13#[derive(Debug)]
14pub enum IndexSetResult<'a, E: Entity> {
15 Unsupported,
17 Empty,
19 Set(&'a IndexSet<EntityId<E>>),
21}
22
23#[derive(PartialEq, Eq, Debug)]
24pub enum IndexCountResult {
25 Unsupported,
27 Count(usize),
29}
30
31#[derive(Debug, Copy, Clone, PartialEq, Eq)]
32pub enum PropertyIndexType {
33 Unindexed,
34 FullIndex,
35 ValueCountIndex,
36}
37
38impl PropertyIndexType {
39 pub(crate) fn new_property_index<E, P>(self) -> Option<Box<dyn PropertyIndex<E, P>>>
41 where
42 E: Entity,
43 P: IndexableProperty<E>,
44 {
45 match self {
46 Self::Unindexed => None,
47 Self::FullIndex => Some(Box::new(FullIndex::<E, P>::new())),
48 Self::ValueCountIndex => Some(Box::new(ValueCountIndex::<E, P>::new())),
49 }
50 }
51}
52
53pub trait PropertyIndex<E: Entity, P: Property<E>> {
54 #[must_use]
55 fn index_type(&self) -> PropertyIndexType;
56
57 #[must_use]
58 fn get_index_set_result(&self, value: &P) -> IndexSetResult<'_, E>;
59
60 #[must_use]
61 fn get_index_count_result(&self, value: &P) -> IndexCountResult;
62
63 fn remove_entity(&mut self, value: &P, entity_id: EntityId<E>);
64
65 fn add_entity(&mut self, value: &P, entity_id: EntityId<E>);
66}