mirror of https://github.com/aria2/aria2
2009-04-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten isInRange() * src/DHTBucket.cc * test/DHTBucketTest.ccpull/1/head
parent
752fb34bbb
commit
5541477dce
|
@ -1,3 +1,9 @@
|
||||||
|
2009-04-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Rewritten isInRange()
|
||||||
|
* src/DHTBucket.cc
|
||||||
|
* test/DHTBucketTest.cc
|
||||||
|
|
||||||
2009-03-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-03-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Fixed typo
|
Fixed typo
|
||||||
|
|
|
@ -33,6 +33,11 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "DHTUtil.h"
|
#include "DHTUtil.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
@ -40,9 +45,6 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DHTConstants.h"
|
#include "DHTConstants.h"
|
||||||
#include "a2functional.h"
|
#include "a2functional.h"
|
||||||
#include <cstring>
|
|
||||||
#include <cassert>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -89,25 +91,16 @@ bool DHTBucket::isInRange(const unsigned char* nodeID) const
|
||||||
return isInRange(nodeID, _max, _min);
|
return isInRange(nodeID, _max, _min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if nodeID is in [min, max] (inclusive).
|
||||||
bool DHTBucket::isInRange(const unsigned char* nodeID,
|
bool DHTBucket::isInRange(const unsigned char* nodeID,
|
||||||
const unsigned char* max,
|
const unsigned char* max,
|
||||||
const unsigned char* min) const
|
const unsigned char* min) const
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < DHT_ID_LENGTH; ++i) {
|
return
|
||||||
if(nodeID[i] < min[i]) {
|
!std::lexicographical_compare(&nodeID[0], &nodeID[DHT_ID_LENGTH],
|
||||||
return false;
|
&min[0], &min[DHT_ID_LENGTH]) &&
|
||||||
} else if(min[i] < nodeID[i]) {
|
!std::lexicographical_compare(&max[0], &max[DHT_ID_LENGTH],
|
||||||
break;
|
&nodeID[0], &nodeID[DHT_ID_LENGTH]);
|
||||||
}
|
|
||||||
}
|
|
||||||
for(size_t i = 0; i < DHT_ID_LENGTH; ++i) {
|
|
||||||
if(max[i] < nodeID[i]) {
|
|
||||||
return false;
|
|
||||||
} else if(nodeID[i] < max[i]) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
|
bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
|
||||||
|
|
|
@ -139,10 +139,10 @@ void DHTBucketTest::testIsInRange()
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// nodeID is out of range: larger than this range
|
// nodeID is out of range: larger than this range
|
||||||
unsigned char nodeID[] = { 0x10, 0x00, 0x00, 0x00, 0x00,
|
unsigned char nodeID[] = { 0x01, 0x02, 0xff, 0xff, 0xff,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00 };
|
0xff, 0xff, 0xff, 0xff, 0xff };
|
||||||
SharedHandle<DHTNode> node(new DHTNode(nodeID));
|
SharedHandle<DHTNode> node(new DHTNode(nodeID));
|
||||||
DHTBucket bucket(16, max, min, localNode);
|
DHTBucket bucket(16, max, min, localNode);
|
||||||
CPPUNIT_ASSERT(!bucket.isInRange(node));
|
CPPUNIT_ASSERT(!bucket.isInRange(node));
|
||||||
|
|
Loading…
Reference in New Issue