Commit a334c19b authored by Joseph Noir's avatar Joseph Noir

Fix node_id::compare

parent 001a9721
...@@ -82,14 +82,16 @@ int node_id::compare(const node_id& other) const { ...@@ -82,14 +82,16 @@ int node_id::compare(const node_id& other) const {
return 0; // shortcut for comparing to self or identical instances return 0; // shortcut for comparing to self or identical instances
if (! data_ != ! other.data_) if (! data_ != ! other.data_)
return data_ ? 1 : -1; // invalid instances are always smaller return data_ ? 1 : -1; // invalid instances are always smaller
int tmp = strncmp(reinterpret_cast<const char*>(host_id().data()), // use mismatch instead of strncmp because the
reinterpret_cast<const char*>(other.host_id().data()), // latter bails out on the first 0-byte
host_id_size); auto last = host_id().end();
return tmp != 0 auto ipair = std::mismatch(host_id().begin(), last, other.host_id().begin());
? tmp if (ipair.first == last)
: (process_id() < other.process_id() return static_cast<int>(process_id())-static_cast<int>(other.process_id());
? -1 else if (*ipair.first < *ipair.second)
: (process_id() == other.process_id() ? 0 : 1)); return -1;
else
return 1;
} }
node_id::data::data() : pid_(0) { node_id::data::data() : pid_(0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment