Using a sorted vector provides a much faster lookup time than a
std::set when the number of points on the circle (weight of the
backend) is huge.
A boost::flat_set is almost as fast as a sorted vector but the
insertion time is quite bad.
pthread_rwlock_destroy(&d_lock);
}
boost::uuids::uuid id;
- std::set<unsigned int> hashes;
+ std::vector<unsigned int> hashes;
mutable pthread_rwlock_t d_lock;
std::vector<int> sockets;
const std::string sourceItfName;
auto w = weight;
WriteLock wl(&d_lock);
hashes.clear();
+ hashes.reserve(w);
while (w > 0) {
std::string uuid = boost::str(boost::format("%s-%d") % id % w);
- unsigned int wshash = burtleCI((const unsigned char*)uuid.c_str(), uuid.size(), g_hashperturb);
- hashes.insert(wshash);
+ unsigned int wshash = burtleCI(reinterpret_cast<const unsigned char*>(uuid.c_str()), uuid.size(), g_hashperturb);
+ hashes.push_back(wshash);
--w;
}
+ std::sort(hashes.begin(), hashes.end());
}
void DownstreamState::setId(const boost::uuids::uuid& newId)
first = server;
}
- auto hash_it = server->hashes.lower_bound(qhash);
+ auto hash_it = std::lower_bound(server->hashes.begin(), server->hashes.end(), qhash);
if (hash_it != server->hashes.end()) {
if (*hash_it < sel) {
sel = *hash_it;