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


C++ unordered_set::empty方法代码示例

本文整理汇总了C++中boost::unordered_set::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_set::empty方法的具体用法?C++ unordered_set::empty怎么用?C++ unordered_set::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::unordered_set的用法示例。


在下文中一共展示了unordered_set::empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: distanceToCluster

float KernelKmeansClusterer::distanceToCluster(int sampleId,
		const boost::unordered_set<int>& clusterIdSet) {
	if (clusterIdSet.empty()) {
		return FLT_MAX;
	}
	// the sum of weight of the cluster
	float weightSum = 0.0f;
	// the sum of kernels from the sample to all samples in the cluster, multiplied by the weight
	float kernelSum = 0.0f;
	// the sum of kernels from each pair of samples in the cluster, multiplied by weights
	float kernelPairSum = 0.0f;
	for (boost::unordered_set<int>::const_iterator iter = clusterIdSet.begin();
			iter != clusterIdSet.end(); ++iter) {
		float weight = mWeightArray[*iter];
		weightSum += weight;
		float kernelResult = (*mpKernel)(sampleId, *iter);
		kernelSum += weight * kernelResult;
		for (boost::unordered_set<int>::const_iterator _iter =
				clusterIdSet.begin(); _iter != clusterIdSet.end(); ++_iter) {
			float _kernelResult = (*mpKernel)(*iter, *_iter);
			kernelPairSum += weight * mWeightArray[*_iter] * _kernelResult;
		}
	}
	float kernelSelf = (*mpKernel)(sampleId, sampleId);
	if (weightSum == 0.0f) {
		return FLT_MAX;
	}
	return kernelSelf - 2 * kernelSum / weightSum
			+ kernelPairSum / (weightSum * weightSum);
}
开发者ID:zixuanwang,项目名称:Research,代码行数:30,代码来源:KernelKmeansClusterer.cpp

示例2: collectShortcuts

static bool collectShortcuts(const std::string & str, StringVector & vs) 
{
	static boost::unordered_set<std::string> commonFilters;
	if(commonFilters.empty()) {
#if RULE_KEY_HASH_LENGTH==7 // 7
		commonFilters.insert("http://");
		commonFilters.insert("ttp://w");
		commonFilters.insert("tp://ww");
		commonFilters.insert("p://www");
		commonFilters.insert("://www.");
#elif RULE_KEY_HASH_LENGTH==8 // 8
		commonFilters.insert("http://w");
		commonFilters.insert("ttp://ww");
		commonFilters.insert("tp://www");
		commonFilters.insert("p://www.");
#elif RULE_KEY_HASH_LENGTH==9 // 9
		commonFilters.insert("http://ww");
		commonFilters.insert("ttp://www");
		commonFilters.insert("tp://www.");
#endif
	}

	int i = 0;
	bool isFindShoutcut = false;
	while (i < abpmin(str.length() - RULE_KEY_HASH_LENGTH,80)) 
	{
		unsigned int j = i;
		for (; j < str.length(); j++) {
			if ((str[j] == '*' || str[j] == '^'))
			{
				break;
			}
		}
		for (unsigned int k = i; j - k >= RULE_KEY_HASH_LENGTH; k++) 
		{
			std::string key = str.substr(k, RULE_KEY_HASH_LENGTH);
			if(commonFilters.find(key)!=commonFilters.end())
				continue;
			isFindShoutcut = true;
			vs.push_back(key); //append(key);
		}
		i = j + 1;
	}
	return isFindShoutcut;
}
开发者ID:fanliaokeji,项目名称:lvdun,代码行数:45,代码来源:FilterManager.cpp


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