diff --git a/src/ray/constants.h b/src/ray/constants.h index bdae39ff2..eab76e374 100644 --- a/src/ray/constants.h +++ b/src/ray/constants.h @@ -1,12 +1,17 @@ #ifndef RAY_CONSTANTS_H_ #define RAY_CONSTANTS_H_ +#include + /// Length of Ray IDs in bytes. constexpr int64_t kUniqueIDSize = 20; /// An ObjectID's bytes are split into the task ID itself and the index of the /// object's creation. This is the maximum width of the object index in bits. constexpr int kObjectIdIndexSize = 32; +static_assert(kObjectIdIndexSize % CHAR_BIT == 0, + "ObjectID prefix not a multiple of bytes"); + /// The maximum number of objects that can be returned by a task when finishing /// execution. An ObjectID's bytes are split into the task ID itself and the /// index of the object's creation. A positive index indicates an object diff --git a/src/ray/id.cc b/src/ray/id.cc index 4d9634623..c61c306c6 100644 --- a/src/ray/id.cc +++ b/src/ray/id.cc @@ -1,5 +1,6 @@ #include "ray/id.h" +#include #include #include "ray/constants.h" @@ -83,7 +84,8 @@ bool UniqueID::operator==(const UniqueID &rhs) const { size_t UniqueID::hash() const { size_t result; - std::memcpy(&result, id_, sizeof(size_t)); + // Skip the bytes for the object prefix. + std::memcpy(&result, id_ + (kObjectIdIndexSize / CHAR_BIT), sizeof(size_t)); return result; }