diff options
| author | mat <git@matdoes.dev> | 2023-10-02 19:57:13 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-10-02 19:57:13 -0500 |
| commit | 985327241d341caf2ce357955cb46657cfa303cb (patch) | |
| tree | 285f7b4a1d07707c7de1e308b54d9fb2110aaf6a /azalea-core/src/position.rs | |
| parent | 7b10e5cd7e80be85f7b0517f941b175e733d3fc4 (diff) | |
| download | azalea-drasl-985327241d341caf2ce357955cb46657cfa303cb.tar.xz | |
yet another W for linear searches
Diffstat (limited to 'azalea-core/src/position.rs')
| -rwxr-xr-x | azalea-core/src/position.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 16578517..6d0b28da 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -228,11 +228,17 @@ impl Add<ChunkPos> for ChunkPos { } } } +impl From<ChunkPos> for u64 { + #[inline] + fn from(pos: ChunkPos) -> Self { + ((pos.x as u64) << 32) | (pos.z as u64) + } +} impl Hash for ChunkPos { + #[inline] fn hash<H: std::hash::Hasher>(&self, state: &mut H) { // optimized hash that only calls hash once - let combined = (self.x as u64) << 32 | (self.z as u64); - combined.hash(state); + u64::from(*self).hash(state); } } /// nohash_hasher lets us have IntMap<ChunkPos, _> which is significantly faster @@ -316,6 +322,15 @@ impl From<BlockPos> for ChunkSectionPos { } } } +impl From<&BlockPos> for ChunkSectionPos { + fn from(pos: &BlockPos) -> Self { + ChunkSectionPos { + x: pos.x.div_floor(16), + y: pos.y.div_floor(16), + z: pos.z.div_floor(16), + } + } +} impl From<ChunkSectionPos> for ChunkPos { fn from(pos: ChunkSectionPos) -> Self { |
