/* */ #ifndef _D_PIECE_STAT_MAN_H_ #define _D_PIECE_STAT_MAN_H_ #include "common.h" #include #include "SharedHandle.h" namespace aria2 { class PieceStat { private: size_t _order; size_t _index; size_t _count; public: PieceStat(size_t index); bool operator<(const PieceStat& pieceStat) const { if(_count == pieceStat._count) { return _order < pieceStat._order; } else { return _count < pieceStat._count; } } void addCount(); void subCount(); size_t getOrder() const { return _order; } void setOrder(size_t order) { _order = order; } size_t getIndex() const { return _index; } size_t getCount() const { return _count; } }; class PieceStatMan { private: std::vector > _pieceStats; std::vector _sortedPieceStatIndexes; public: PieceStatMan(size_t pieceNum, bool randomShuffle); void addPieceStats(size_t index); void addPieceStats(const unsigned char* bitfield, size_t bitfieldLength); void subtractPieceStats(const unsigned char* bitfield, size_t bitfieldLength); void updatePieceStats(const unsigned char* newBitfield, size_t newBitfieldLength, const unsigned char* oldBitfield); // Returns piece index in rarest first order. const std::vector& getRarerPieceIndexes() const { return _sortedPieceStatIndexes; } const std::vector >& getPieceStats() const { return _pieceStats; } }; } // namespace aria2 #endif // _D_PIECE_STAT_MAN_H_