diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-16 15:33:52 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-16 15:34:01 +0200 |
commit | a24dd4b81ad8f87d34f1c55efa17cd3840d2ac5e (patch) | |
tree | 7ffdf92a44f73d6f7c5db4a30f2254117dc8f49b /server/src/data/index.rs | |
parent | 8f949e36143eabd8b176dbd16c3d90045d256a74 (diff) | |
download | hurrycurry-a24dd4b81ad8f87d34f1c55efa17cd3840d2ac5e.tar hurrycurry-a24dd4b81ad8f87d34f1c55efa17cd3840d2ac5e.tar.bz2 hurrycurry-a24dd4b81ad8f87d34f1c55efa17cd3840d2ac5e.tar.zst |
generate index for passive recipes by input for faster lookup
Diffstat (limited to 'server/src/data/index.rs')
-rw-r--r-- | server/src/data/index.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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<ItemIndex, Vec<RecipeIndex>>, +} + +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); + } + _ => (), + } + } + } +} |