Don't use the default hasher
This commit is contained in:
parent
11a4fcb33d
commit
49a749534c
|
@ -17,6 +17,7 @@ use self::block::BlockSet;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::hash::{BuildHasherDefault, Hasher};
|
||||||
use types::bit;
|
use types::bit;
|
||||||
use types::nibble;
|
use types::nibble;
|
||||||
use protocol;
|
use protocol;
|
||||||
|
@ -197,7 +198,7 @@ impl World {
|
||||||
section.dirty = true;
|
section.dirty = true;
|
||||||
|
|
||||||
let bit_size = try!(data.read_u8());
|
let bit_size = try!(data.read_u8());
|
||||||
let mut block_map = HashMap::new();
|
let mut block_map = HashMap::with_hasher(BuildHasherDefault::<FNVHash>::default());
|
||||||
if bit_size <= 8 {
|
if bit_size <= 8 {
|
||||||
let count = try!(VarInt::read_from(&mut data)).0;
|
let count = try!(VarInt::read_from(&mut data)).0;
|
||||||
for i in 0 .. count {
|
for i in 0 .. count {
|
||||||
|
@ -359,6 +360,27 @@ impl Chunk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FNVHash(u64);
|
||||||
|
|
||||||
|
impl Hasher for FNVHash {
|
||||||
|
fn write(&mut self, bytes: &[u8]) {
|
||||||
|
for b in bytes {
|
||||||
|
self.0 = self.0.wrapping_mul(0x100000001b3);
|
||||||
|
self.0 ^= *b as u64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish(&self) -> u64 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for FNVHash {
|
||||||
|
fn default() -> Self {
|
||||||
|
FNVHash(0xcbf29ce484222325)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash)]
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
pub struct SectionKey {
|
pub struct SectionKey {
|
||||||
pos: (i32, u8, i32),
|
pos: (i32, u8, i32),
|
||||||
|
@ -370,7 +392,7 @@ struct Section {
|
||||||
|
|
||||||
blocks: bit::Map,
|
blocks: bit::Map,
|
||||||
block_map: Vec<(&'static block::Block, u32)>,
|
block_map: Vec<(&'static block::Block, u32)>,
|
||||||
rev_block_map: HashMap<usize, usize>,
|
rev_block_map: HashMap<usize, usize, BuildHasherDefault<FNVHash>>,
|
||||||
|
|
||||||
block_light: nibble::Array,
|
block_light: nibble::Array,
|
||||||
sky_light: nibble::Array,
|
sky_light: nibble::Array,
|
||||||
|
@ -391,7 +413,7 @@ impl Section {
|
||||||
block_map: vec![
|
block_map: vec![
|
||||||
(block::AIR.base(), 0xFFFFFFFF)
|
(block::AIR.base(), 0xFFFFFFFF)
|
||||||
],
|
],
|
||||||
rev_block_map: HashMap::new(),
|
rev_block_map: HashMap::with_hasher(BuildHasherDefault::default()),
|
||||||
|
|
||||||
block_light: nibble::Array::new(16 * 16 * 16),
|
block_light: nibble::Array::new(16 * 16 * 16),
|
||||||
sky_light: nibble::Array::new(16 * 16 * 16),
|
sky_light: nibble::Array::new(16 * 16 * 16),
|
||||||
|
|
Loading…
Reference in New Issue