当前位置: 首页>>代码示例>>C++>>正文


C++ unordered_map::bucket_count方法代码示例

本文整理汇总了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;
	}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例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;
	}
开发者ID:,项目名称:,代码行数:36,代码来源:


注:本文中的unordered_map::bucket_count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。