Skip to content

Commit

Permalink
Fixed comments for hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshEliades committed Dec 4, 2024
1 parent 08a37b9 commit 5eefa33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/mcpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ struct Coordinate {
Coordinate operator-(const Coordinate& obj) const;

/**
* @brief Implements hash algorithm for Coordinate object using XOR, bit
* shifts and prime multiplication
* @brief Implements hash algorithm for Coordinate object using non-negative
* mapping and weighted coordinate values.
*
* @param obj The Coordinate object to hash.
* @return Hash of Coordinate object.
Expand Down
9 changes: 6 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ Coordinate Coordinate::operator-(const Coordinate& obj) const {
}

std::size_t Coordinate::operator()(const mcpp::Coordinate& obj) const {
// Minecraft coordinate bounds
int lower = -3e7, upper = 3e7;
size_t base = upper - lower + 1;

// Make x,y,z non negative
size_t nx = obj.x - lower, ny = obj.y - lower, nz = obj.z - lower;
// Convert coordinate attributes to non-negative values
size_t nx = obj.x - lower;
size_t ny = obj.y - lower;
size_t nz = obj.z - lower;

// Use overflow instead of modding
// Combine and weight coordinate values using the boundary range
return nx * base * base + ny * base + nz;
}

Expand Down

0 comments on commit 5eefa33

Please sign in to comment.