switched to a fast hashing algorithm

This commit is contained in:
JOLIMAITRE Matthieu 2022-09-03 14:17:43 +02:00
parent 9cb320e357
commit a6b7824648
6 changed files with 34 additions and 2 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
.vscode

7
Cargo.lock generated
View file

@ -12,6 +12,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
name = "golrs" name = "golrs"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"metrohash",
"termion", "termion",
] ]
@ -21,6 +22,12 @@ version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
name = "metrohash"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ba553cb19e2acbc54baa16faef215126243fe45e53357a3b2e9f4ebc7b0506c"
[[package]] [[package]]
name = "numtoa" name = "numtoa"
version = "0.1.0" version = "0.1.0"

View file

@ -9,3 +9,4 @@ repository = "https://github.com/MajorBarnulf/golrs"
[dependencies] [dependencies]
termion = "1.5" termion = "1.5"
metrohash = "1.0"

View file

@ -1,3 +1,3 @@
# #
# #
# #

21
patterns/gen.ts Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env -S deno run
const { args } = Deno;
const size = parseInt(args[0] ?? "5");
const frequency = parseFloat(args[1] ?? "0.5");
function* range(from: number, to: number) {
let current = from;
while (current < to) yield current++;
}
let result = "";
for (const _y of range(0, size)) {
for (const _x of range(0, size))
result += Math.random() < frequency ? '#' : ' ';
result += '\n';
}
console.log(result);

View file

@ -1,5 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use metrohash::MetroBuildHasher;
use crate::{pos, Cell, Pos, World}; use crate::{pos, Cell, Pos, World};
const CHUNK_SIZE: usize = 16; const CHUNK_SIZE: usize = 16;
@ -34,7 +36,7 @@ struct ChunkPos(Pos);
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct HashedWorld { pub struct HashedWorld {
chunks: HashMap<ChunkPos, Chunk>, chunks: HashMap<ChunkPos, Chunk, MetroBuildHasher>,
} }
impl HashedWorld { impl HashedWorld {