本文整理汇总了C++中CUInt128::SetBit方法的典型用法代码示例。如果您正苦于以下问题:C++ CUInt128::SetBit方法的具体用法?C++ CUInt128::SetBit怎么用?C++ CUInt128::SetBit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUInt128
的用法示例。
在下文中一共展示了CUInt128::SetBit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeCloseTarget
CUInt128 CKademlia::MakeCloseTarget(int *pDistance)
{
if(!m_pKadHandler)
{
if(pDistance)
*pDistance = -1;
return 0;
}
CUInt128 uMyID = m_pRootZone->GetID();
NodeMap Nodes;
m_pRootZone->GetClosestNodes(uMyID, Nodes, Cfg()->GetInt("BucketSize"));
if(Nodes.size() < 2)
{
if(pDistance)
*pDistance = -1;
return 0;
}
// Find Median distance difference between nodes closest to us
vector<CUInt128> Diff;
for(NodeMap::iterator np = Nodes.begin(), n = np++; np != Nodes.end(); n = np++)
Diff.push_back(np->first - n->first);
CUInt128 Sep = Median(Diff);
// generate ID that is closer to us than the closest node by a few difference
CUInt128 uDistance = Nodes.begin()->first;
for(int i=0; i < 3 && uDistance > Sep; i++)
uDistance = uDistance - Sep;
CUInt128 uCloser = uMyID ^ uDistance;
// count the matchign bits
UINT uLevel=0;
for(; uLevel < uMyID.GetBitSize(); uLevel++)
{
if(uCloser.GetBit(uLevel) != uMyID.GetBit(uLevel))
break;
}
// add a few more matching bytes
for(UINT i=0; i < 4 && uLevel < uMyID.GetBitSize() - 1; i++)
{
uCloser.SetBit(uLevel, uMyID.GetBit(uLevel));
uLevel++;
}
if(pDistance)
*pDistance = (int)uMyID.GetBitSize() - uLevel;
// create a random ID that we are closest to
CUInt128 uRandom(uCloser, uLevel);
//wstring sTest = (uMyID ^ uRandom).ToBin();
return uRandom;
}