Use rustc_hash for hashing in game_of_life

This seems to produce a 2x speedup.
This commit is contained in:
Héctor Ramón Jiménez 2020-05-02 03:31:31 +02:00
parent e7e8e76c28
commit 4fd8e47737
2 changed files with 4 additions and 3 deletions

View File

@ -8,3 +8,4 @@ publish = false
[dependencies]
iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
itertools = "0.9"
rustc-hash = "1.1"

View File

@ -159,7 +159,7 @@ mod grid {
canvas::{self, Cache, Canvas, Cursor, Event, Frame, Geometry, Path},
mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
};
use std::collections::{HashMap, HashSet};
use rustc_hash::{FxHashMap, FxHashSet};
pub struct Grid {
life: Life,
@ -395,12 +395,12 @@ mod grid {
#[derive(Default)]
pub struct Life {
cells: HashSet<Cell>,
cells: FxHashSet<Cell>,
}
impl Life {
fn tick(&mut self) {
let mut adjacent_life = HashMap::new();
let mut adjacent_life = FxHashMap::default();
for cell in &self.cells {
let _ = adjacent_life.entry(*cell).or_insert(0);