2009-07-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Refactored BitfieldMan::getSparseMissingUnusedIndex()
	* src/BitfieldMan.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-07-02 16:44:31 +00:00
parent ffaeb271f9
commit 63735eab8e
2 changed files with 13 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2009-07-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Refactored BitfieldMan::getSparseMissingUnusedIndex()
* src/BitfieldMan.cc
2009-07-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-07-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten PeerStats handling in SegmentMan.cc. Now we have 2 list Rewritten PeerStats handling in SegmentMan.cc. Now we have 2 list

View File

@ -300,8 +300,8 @@ bool BitfieldMan::getMissingUnusedIndex(size_t& index) const
} }
template<typename Array> template<typename Array>
static size_t getStartIndex(size_t index, const Array& bitfield, const unsigned char* useBitfield, size_t blocks) { static size_t getStartIndex(size_t index, const Array& bitfield, size_t blocks) {
while(index < blocks && (bitfield::test(bitfield, blocks, index) || bitfield::test(useBitfield, blocks, index))) { while(index < blocks && bitfield::test(bitfield, blocks, index)) {
++index; ++index;
} }
if(blocks <= index) { if(blocks <= index) {
@ -312,8 +312,8 @@ static size_t getStartIndex(size_t index, const Array& bitfield, const unsigned
} }
template<typename Array> template<typename Array>
static size_t getEndIndex(size_t index, const Array& bitfield, const unsigned char* useBitfield, size_t blocks) { static size_t getEndIndex(size_t index, const Array& bitfield, size_t blocks) {
while(index < blocks && (!bitfield::test(bitfield, blocks, index) && !bitfield::test(useBitfield, blocks, index))) { while(index < blocks && !bitfield::test(bitfield, blocks, index)) {
++index; ++index;
} }
return index; return index;
@ -332,12 +332,12 @@ static bool getSparseMissingUnusedIndex
size_t nextIndex = 0; size_t nextIndex = 0;
while(nextIndex < blocks) { while(nextIndex < blocks) {
currentRange.startIndex = currentRange.startIndex =
getStartIndex(nextIndex, bitfield, useBitfield, blocks); getStartIndex(nextIndex, bitfield, blocks);
if(currentRange.startIndex == blocks) { if(currentRange.startIndex == blocks) {
break; break;
} }
currentRange.endIndex = currentRange.endIndex =
getEndIndex(currentRange.startIndex, bitfield, useBitfield, blocks); getEndIndex(currentRange.startIndex, bitfield, blocks);
if(maxRange < currentRange) { if(maxRange < currentRange) {
maxRange = currentRange; maxRange = currentRange;
} }
@ -365,11 +365,11 @@ bool BitfieldMan::getSparseMissingUnusedIndex
{ {
if(filterEnabled) { if(filterEnabled) {
return aria2::getSparseMissingUnusedIndex return aria2::getSparseMissingUnusedIndex
(index, array(ignoreBitfield)|~array(filterBitfield)|array(bitfield), (index, array(ignoreBitfield)|~array(filterBitfield)|array(bitfield)|array(useBitfield),
useBitfield, blocks); useBitfield, blocks);
} else { } else {
return aria2::getSparseMissingUnusedIndex return aria2::getSparseMissingUnusedIndex
(index, array(ignoreBitfield)|array(bitfield), (index, array(ignoreBitfield)|array(bitfield)|array(useBitfield),
useBitfield, blocks); useBitfield, blocks);
} }
} }