File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,6 +176,15 @@ struct Coordinate2D {
176176 */
177177 Coordinate2D operator -(const Coordinate2D& obj) const ;
178178
179+ /* *
180+ * @brief Implements hash algorithm for Coordinate2D object using non-negative
181+ * mapping and weighted coordinate values.
182+ *
183+ * @param obj The Coordinate2D object to hash.
184+ * @return Hash of Coordinate2D object.
185+ */
186+ std::size_t operator ()(const Coordinate2D& obj) const ;
187+
179188 /* *
180189 * @brief Outputs the Coordinate2D object to an ostream.
181190 *
Original file line number Diff line number Diff line change @@ -79,6 +79,16 @@ Coordinate2D Coordinate2D::operator-(const Coordinate2D& obj) const {
7979 return result;
8080}
8181
82+ std::size_t Coordinate2D::operator ()(const mcpp::Coordinate2D& obj) const {
83+ int lower = -3e7 , upper = 3e7 ;
84+ size_t base = upper - lower + 1 ;
85+
86+ size_t nx = obj.x - lower;
87+ size_t nz = obj.z - lower;
88+
89+ return nx * base + nz;
90+ }
91+
8292std::string to_string (const Coordinate2D& coord) {
8393 using std::to_string;
8494 return " (" + to_string (coord.x ) + " ," + to_string (coord.z ) + " )" ;
You can’t perform that action at this time.
0 commit comments