本文整理汇总了C++中smart_ptr::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ smart_ptr::Update方法的具体用法?C++ smart_ptr::Update怎么用?C++ smart_ptr::Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smart_ptr
的用法示例。
在下文中一共展示了smart_ptr::Update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OverFillBuckets
int OverFillBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt)
{
int added = 0;
DhtID dctr;
DhtPeerID peerId;
peerId.addr.set_port(128);
peerId.addr.set_addr4(0xf0f0f0f0);
int numPrefixBits;
for(int bucketNum=0; bucketNum < dhtObj->_buckets.size(); ++bucketNum)
{
numPrefixBits = 160 - dhtObj->_buckets[bucketNum]->span;
for(int ctr=0; ctr<16; ++ctr)
{
// copy "first"
for(int y=0; y<5; ++y)
peerId.id.id[y] = dhtObj->_buckets[bucketNum]->first.id[y];
dctr.id[4] = ctr;
// move the counter bits (4 bits) into the bits immediatly following the prefix bits
// the bit range is 0 -> 159
for(int x=0; x<4; ++x)
{
ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, 3-x));
}
(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
}
}
return added;
}
示例2: FillPreallocatedBuckets
int FillPreallocatedBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt)
{
int added = 0;
DhtID dctr;
DhtPeerID peerId;
peerId.addr.set_port(128);
peerId.addr.set_addr4(0xf0f0f0f0);
for(int ctr=0; ctr<32; ++ctr)
{
dctr.id[4] = ctr;
// put 8 nodes in the bucket
for(int nodenum=0; nodenum<8; nodenum++)
{
// make a random myID
for(int y=0; y<5; ++y)
peerId.id.id[y] = rand();
// copy the counter bits (5 bits) into the upper 5 bits of the id to be added
// (to address the particular preallocated bucket)
for(int x=0; x<5; ++x)
{
ProgramBit(peerId.id, 159-x, GetBit(dctr, 4-x));
}
// add the node
(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
}
}
return added;
}
示例3: FillBucketList
/**
Uses the dht's ID (myId) as the base for nodes to be added. New nodes are always added
to the bucket that contains myId thus forcing the split. The dht buckets quit splitting
once the span of the bucket containing myId reaches 3 (decending from 160). At this
there are only 8 possible ID's that can fill the 8 slots in the bucket.
Note that the number of additions returned includes both new nodes added and existing
nodes already in the list that are updated.
*/
int FillBucketList(smart_ptr<DhtImpl> &dhtObj, time_t rtt, SubPrefixType subPrefixType, int numPrefixBits = 0, int diff = 1)
{
int added = 0;
if(numPrefixBits >=160 || numPrefixBits < 0)
return added;
DhtID subPrefixBits;
DhtPeerID peerId;
peerId.addr.set_port(128);
peerId.addr.set_addr4(0xf0f0f0f0);
for(int ctr=0; ctr<16; ++ctr)
{
// copy myID
for(int y=0; y<5; ++y)
peerId.id.id[y] = dhtObj->_my_id.id[y];
subPrefixBits.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand();
if(subPrefixType==evenBitDistribution)
{
// move the counter bits (4 bits) into the bits immediatly following the prefix bits
// the bit range is 0 -> 159
for(int x=0; x<4; ++x)
{
ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, 3-x));
}
}
else
{
for(int x=0; x<32; ++x)
{
ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, x));
}
}
//dctr.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand();
//// move the counter bits (4 bits) into the bits immediatly following the prefix bits
//// the bit range is 0 -> 159
//for(int x=0; x<32; ++x)
//{
// ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, x));
//}
(dhtObj->Update(peerId, 0, true, rtt))? ++added:0;
}
added += FillBucketList(dhtObj, rtt, subPrefixType, numPrefixBits+diff, diff);
return added;
}