diff --git a/include/mcpp/util.h b/include/mcpp/util.h index e503b43..942535f 100644 --- a/include/mcpp/util.h +++ b/include/mcpp/util.h @@ -68,6 +68,14 @@ struct Coordinate { */ Coordinate operator-(const Coordinate& obj) const; + /** + * @brief Implements hash algorithm for Coordinate object using XOR. + * + * @param obj The Coordinate object to hash. + * @return Hash of Coordinate object. + */ + std::size_t operator()(const Coordinate& obj) const; + /** * @brief Creates a copy of the Coordinate object. * diff --git a/src/util.cpp b/src/util.cpp index f52aa55..380805a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -41,6 +41,11 @@ Coordinate Coordinate::operator-(const Coordinate& obj) const { return result; } +std::size_t Coordinate::operator()(const Coordinate& obj) const { + return std::hash()(obj.x) ^ std::hash()(obj.y) ^ + std::hash()(obj.z); +} + Coordinate Coordinate::clone() const { return Coordinate(this->x, this->y, this->z); }