Skip to content

Commit

Permalink
Use ahash::AHashMap; pre-allocate tiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Oct 11, 2024
1 parent 09b6e5c commit 3ca75a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/pathfind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
publish.workspace = true

[dependencies]
ahash = "0.8"
meowtonin = { workspace = true }
pathfinding = "4"
bitflags = "2"
Expand Down
6 changes: 3 additions & 3 deletions crates/pathfind/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ahash::AHashMap;
use bitflags::bitflags;
use ordered_float::OrderedFloat;
use pathfinding::prelude::*;
use std::collections::HashMap;

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct Tile {
}

pub struct GameMap {
tiles: HashMap<Position, Tile>,
tiles: AHashMap<Position, Tile>,
width: i32,
height: i32,
}
Expand All @@ -43,7 +43,7 @@ pub struct GameState {
impl GameMap {
pub fn new(width: i32, height: i32) -> Self {
GameMap {
tiles: HashMap::new(),
tiles: AHashMap::with_capacity((width.max(0) as usize) * (height.max(0) as usize)),
width,
height,
}
Expand Down

0 comments on commit 3ca75a2

Please sign in to comment.