From a24dd4b81ad8f87d34f1c55efa17cd3840d2ac5e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 16 Sep 2024 15:33:52 +0200 Subject: generate index for passive recipes by input for faster lookup --- server/src/data/index.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 server/src/data/index.rs (limited to 'server/src/data/index.rs') diff --git a/server/src/data/index.rs b/server/src/data/index.rs new file mode 100644 index 00000000..1c206d83 --- /dev/null +++ b/server/src/data/index.rs @@ -0,0 +1,25 @@ +use hurrycurry_protocol::{Gamedata, ItemIndex, Recipe, RecipeIndex}; +use std::collections::HashMap; + +#[derive(Debug, Default)] +pub struct GamedataIndex { + pub recipe_passive_by_input: HashMap>, +} + +impl GamedataIndex { + pub fn update(&mut self, data: &Gamedata) { + self.recipe_passive_by_input.clear(); + + for (ri, r) in data.recipes() { + match r { + Recipe::Passive { input, .. } => { + self.recipe_passive_by_input + .entry(*input) + .or_default() + .push(ri); + } + _ => (), + } + } + } +} -- cgit v1.2.3-70-g09d2