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>
|
||||
|
||||
Fixed typo
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "DHTBucket.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#include "DHTUtil.h"
|
||||
#include "DHTNode.h"
|
||||
#include "LogFactory.h"
|
||||
|
@ -40,9 +45,6 @@
|
|||
#include "Util.h"
|
||||
#include "DHTConstants.h"
|
||||
#include "a2functional.h"
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -89,25 +91,16 @@ bool DHTBucket::isInRange(const unsigned char* nodeID) const
|
|||
return isInRange(nodeID, _max, _min);
|
||||
}
|
||||
|
||||
// Returns true if nodeID is in [min, max] (inclusive).
|
||||
bool DHTBucket::isInRange(const unsigned char* nodeID,
|
||||
const unsigned char* max,
|
||||
const unsigned char* min) const
|
||||
{
|
||||
for(size_t i = 0; i < DHT_ID_LENGTH; ++i) {
|
||||
if(nodeID[i] < min[i]) {
|
||||
return false;
|
||||
} else if(min[i] < nodeID[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
return
|
||||
!std::lexicographical_compare(&nodeID[0], &nodeID[DHT_ID_LENGTH],
|
||||
&min[0], &min[DHT_ID_LENGTH]) &&
|
||||
!std::lexicographical_compare(&max[0], &max[DHT_ID_LENGTH],
|
||||
&nodeID[0], &nodeID[DHT_ID_LENGTH]);
|
||||
}
|
||||
|
||||
bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
|
||||
|
|
|
@ -139,10 +139,10 @@ void DHTBucketTest::testIsInRange()
|
|||
}
|
||||
{
|
||||
// nodeID is out of range: larger than this range
|
||||
unsigned char nodeID[] = { 0x10, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char nodeID[] = { 0x01, 0x02, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
SharedHandle<DHTNode> node(new DHTNode(nodeID));
|
||||
DHTBucket bucket(16, max, min, localNode);
|
||||
CPPUNIT_ASSERT(!bucket.isInRange(node));
|
||||
|
|
Loading…
Reference in New Issue