Esempio n. 1
0
int node_id::compare(const node_id& other) const {
    int tmp = strncmp(reinterpret_cast<const char*>(host_id().data()),
                      reinterpret_cast<const char*>(other.host_id().data()),
                      host_id_size);
    if (tmp == 0) {
        if (m_process_id < other.process_id()) return -1;
        else if (m_process_id == other.process_id()) return 0;
        return 1;
    }
    return tmp;
}
Esempio n. 2
0
int node_id::compare(const node_id& other) const {
    if (this == &other || data_ == other.data_)
        return 0; // shortcut for comparing to self or identical instances
    if (! data_ != ! other.data_)
        return data_ ? 1 : -1; // invalid instances are always smaller
    int tmp = strncmp(reinterpret_cast<const char*>(host_id().data()),
                      reinterpret_cast<const char*>(other.host_id().data()),
                      host_id_size);
    return tmp != 0
           ? tmp
           : (process_id() < other.process_id()
              ? -1
              : (process_id() == other.process_id() ? 0 : 1));
}
Esempio n. 3
0
std::string to_string(const node_id& x) {
  if (!x)
    return "none";
  return deep_to_string(meta::type_name("node_id"),
                        x.process_id(),
                        meta::hex_formatted(),
                        x.host_id());
}
Esempio n. 4
0
int node_id::compare(const node_id& other) const {
  if (this == &other) {
    return 0; // shortcut for comparing to self
  }
  if (m_data == other.m_data) {
    return 0; // shortcut for identical instances
  }
  if ((m_data != nullptr) != (other.m_data != nullptr)) {
    return m_data ? 1 : -1; // invalid instances are always smaller
  }
  int tmp = strncmp(reinterpret_cast<const char*>(host_id().data()),
                    reinterpret_cast<const char*>(other.host_id().data()),
                    host_id_size);
  if (tmp == 0) {
    if (process_id() < other.process_id()) {
      return -1;
    } else if (process_id() == other.process_id()) {
      return 0;
    }
    return 1;
  }
  return tmp;
}
Esempio n. 5
0
int node_id::compare(const node_id& other) const {
  if (this == &other || data_ == other.data_)
    return 0; // shortcut for comparing to self or identical instances
  if (!data_ != !other.data_)
    return data_ ? 1 : -1; // invalid instances are always smaller
  // use mismatch instead of strncmp because the
  // latter bails out on the first 0-byte
  auto last = host_id().end();
  auto ipair = std::mismatch(host_id().begin(), last, other.host_id().begin());
  if (ipair.first == last)
    return static_cast<int>(process_id())-static_cast<int>(other.process_id());
  else if (*ipair.first < *ipair.second)
    return -1;
  else
    return 1;
}
Esempio n. 6
0
std::string to_string(const node_id& what) {
    std::ostringstream oss;
    oss << what.process_id() << "@" << to_string(what.host_id());
    return oss.str();
}
Esempio n. 7
0
node_id::node_id(const node_id& other)
: super(), m_process_id(other.process_id()), m_host_id(other.host_id()) { }