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


C++ smart_ptr::Update方法代码示例

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

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

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


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