poke_data/collections/
locations.rs

1use crate::data::link_context::LinkContext;
2use crate::data_structures::entity_collection::{EntityCollection, HasNameSearchIndex};
3use crate::data_structures::string_search_index::StringSearchIndex;
4use crate::models::location::{Location, LocationId};
5use crate::traits::has_identifier::IdentifierDictionary;
6use std::collections::HashMap;
7use std::sync::Arc;
8
9pub struct LocationsCollection {
10    entities: HashMap<LocationId, Arc<Location>>,
11    name_search_index: StringSearchIndex<LocationId>,
12}
13
14impl EntityCollection<LocationId, Location> for LocationsCollection {
15    fn new(context: &LinkContext) -> Self {
16        let entities = context.locations.clone();
17        let dictionary = entities.build_identifier_dictionary();
18        let name_search_index = StringSearchIndex::new(dictionary);
19        Self {
20            entities,
21            name_search_index,
22        }
23    }
24
25    fn entities(&self) -> &HashMap<LocationId, Arc<Location>> {
26        &self.entities
27    }
28}
29
30impl HasNameSearchIndex<LocationId, Location> for LocationsCollection {
31    fn name_search_index(&self) -> &StringSearchIndex<LocationId> {
32        &self.name_search_index
33    }
34}