本文整理汇总了C++中unordered_map::bucket_count方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::bucket_count方法的具体用法?C++ unordered_map::bucket_count怎么用?C++ unordered_map::bucket_count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::bucket_count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
int initialize(const configuration &conf,
const std::string &outputDirectory,
const std::string &)
{
if (conf.get(maxFlows, "max-flows", "sensor_dns")
!= configuration::OK)
{
cerr << "sensor_dns: missing or invalid max-flows" << endl;
return 1;
}
if (conf.get(queryTimeout, "query-timeout", "sensor_dns")
!= configuration::OK)
{
cerr << "sensor_dns: missing or invalid query-timeout" << endl;
return 1;
}
flowTable.rehash(maxFlows);
boost::shared_ptr<StrftimeWriteEnumerator<DNS> >
enumerator(new StrftimeWriteEnumerator<DNS>(
outputDirectory, "%Y/%m/%d/dns_%H"));
boost::shared_ptr<InferFileWriter<FlatFileWriter<DNS> > > inferWriter(new InferFileWriter<FlatFileWriter<DNS> >(enumerator));
writer = new AsynchronousWriter<InferFileWriter<FlatFileWriter<DNS> > >(inferWriter);
flowTableLocks = new pthread_mutex_t[flowTable.bucket_count()];
for (size_t bucket = 0; bucket < flowTable.bucket_count(); ++bucket) {
if (pthread_mutex_init(&(flowTableLocks[bucket]), NULL) != 0) {
abort();
}
}
pthread_mutex_init(&flushLock, NULL);
return 0;
}
示例2: flush
int flush() {
static time_t _time;
static size_t bucket, index;
static unordered_map <string, DNS*>::local_iterator flowItr;
static vector <string> eraseList;
_time = time(NULL);
/* Debug output. */
cout << "dns: flush() called (flowTable: " << flowTable.size()
<< ", numBadPackets: " << numBadPackets << ')' << endl;
/* Prevents interference with finish(). */
pthread_mutex_lock(&flushLock);
if (flowTable.size()) {
for (bucket = 0; bucket < flowTable.bucket_count(); ++bucket) {
if (eraseList.size() > 0) {
eraseList.clear();
}
/* Prevents interference with processPacket(). */
pthread_mutex_lock(&flowTableLocks[bucket]);
for (flowItr = flowTable.begin(bucket);
flowItr != flowTable.end(bucket);
++flowItr)
{
if (_time - flowItr -> second -> queryTime().seconds() >= queryTimeout) {
writer->write(flowItr -> second);
eraseList.push_back(flowItr -> first);
}
}
for (index = 0; index < eraseList.size(); ++index) {
flowTable.erase(flowTable.find(eraseList[index]));
}
pthread_mutex_unlock(&flowTableLocks[bucket]);
}
}
pthread_mutex_unlock(&flushLock);
return 0;
}