mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 05:27:38 +03:00
BitfieldMan::getMissingIndexes family functions now takes unsigned char* bitfield instead of stl container for efficiency. PieceSelector::select now takes this bitfield. RarestPieceSelector::select now also performs efficiently for this change. bitfield namespace is introduced and it has several helper functions to handle basic bitfield operations such as test, count set bits, etc. * src/BitfieldMan.cc * src/BitfieldMan.h * src/DefaultBtRequestFactory.cc * src/DefaultPieceStorage.cc * src/DefaultPieceStorage.h * src/LongestSequencePieceSelector.cc * src/LongestSequencePieceSelector.h * src/Makefile.am * src/Piece.cc * src/Piece.h * src/PieceSelector.h * src/RarestPieceSelector.cc * src/RarestPieceSelector.h * src/Util.cc * src/Util.h * src/bitfield.h * test/BitfieldManTest.cc * test/LongestSequencePieceSelectorTest.cc * test/Makefile.am * test/RarestPieceSelectorTest.cc * test/UtilTest.cc * test/bitfieldTest.cc
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#include "bitfield.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace aria2 {
|
|
|
|
class bitfieldTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(bitfieldTest);
|
|
CPPUNIT_TEST(testTest);
|
|
CPPUNIT_TEST(testCountBit32);
|
|
CPPUNIT_TEST(testCountSetBit);
|
|
CPPUNIT_TEST(testLastByteMask);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void testTest();
|
|
void testCountBit32();
|
|
void testCountSetBit();
|
|
void testLastByteMask();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( bitfieldTest );
|
|
|
|
void bitfieldTest::testTest()
|
|
{
|
|
unsigned char bitfield[] = { 0xaa };
|
|
|
|
CPPUNIT_ASSERT(bitfield::test(bitfield, 8, 0));
|
|
CPPUNIT_ASSERT(!bitfield::test(bitfield, 8, 1));
|
|
}
|
|
|
|
void bitfieldTest::testCountBit32()
|
|
{
|
|
CPPUNIT_ASSERT_EQUAL((size_t)32, bitfield::countBit32(UINT32_MAX));
|
|
CPPUNIT_ASSERT_EQUAL((size_t)8, bitfield::countBit32(255));
|
|
}
|
|
|
|
void bitfieldTest::testCountSetBit()
|
|
{
|
|
unsigned char bitfield[] = { 0xff, 0xff, 0xff, 0xf0, 0xff, 0x01 };
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)37, bitfield::countSetBit(bitfield, 48));
|
|
CPPUNIT_ASSERT_EQUAL((size_t)36, bitfield::countSetBit(bitfield, 47));
|
|
CPPUNIT_ASSERT_EQUAL((size_t)28, bitfield::countSetBit(bitfield, 32));
|
|
}
|
|
|
|
void bitfieldTest::testLastByteMask()
|
|
{
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)128,
|
|
(unsigned int)bitfield::lastByteMask(9));
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)240,
|
|
(unsigned int)bitfield::lastByteMask(12));
|
|
CPPUNIT_ASSERT_EQUAL((unsigned int)255,
|
|
(unsigned int)bitfield::lastByteMask(16));
|
|
}
|
|
|
|
} // namespace aria2
|