mirror of https://github.com/aria2/aria2
2008-05-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten the portion of the code that mangaes allowed fast indexes. * src/PeerSessionResource.cc * src/PeerSessionResource.hpull/1/head
parent
738996932a
commit
99f07b515f
|
@ -1,3 +1,9 @@
|
||||||
|
2008-05-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Rewritten the portion of the code that mangaes allowed fast indexes.
|
||||||
|
* src/PeerSessionResource.cc
|
||||||
|
* src/PeerSessionResource.h
|
||||||
|
|
||||||
2008-05-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-05-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Removed the invalid string including '\r' from ru.po and
|
Removed the invalid string including '\r' from ru.po and
|
||||||
|
|
|
@ -203,22 +203,24 @@ const std::deque<size_t>& PeerSessionResource::peerAllowedIndexSet() const
|
||||||
return _peerAllowedIndexSet;
|
return _peerAllowedIndexSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
static void updateIndexSet(std::deque<size_t>& c, size_t index)
|
||||||
bool PeerSessionResource::indexIncluded(const std::deque<T>& c, T index) const
|
|
||||||
{
|
{
|
||||||
return std::find(c.begin(), c.end(), index) != c.end();
|
std::deque<size_t>::iterator i = std::lower_bound(c.begin(), c.end(), index);
|
||||||
|
if(i == c.end() || (*i) != index) {
|
||||||
|
c.insert(i, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::addPeerAllowedIndex(size_t index)
|
void PeerSessionResource::addPeerAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
if(!indexIncluded(_peerAllowedIndexSet, index)) {
|
updateIndexSet(_peerAllowedIndexSet, index);
|
||||||
_peerAllowedIndexSet.push_back(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::peerAllowedIndexSetContains(size_t index) const
|
bool PeerSessionResource::peerAllowedIndexSetContains(size_t index) const
|
||||||
{
|
{
|
||||||
return indexIncluded(_peerAllowedIndexSet, index);
|
return std::binary_search(_peerAllowedIndexSet.begin(),
|
||||||
|
_peerAllowedIndexSet.end(),
|
||||||
|
index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<size_t>& PeerSessionResource::amAllowedIndexSet() const
|
const std::deque<size_t>& PeerSessionResource::amAllowedIndexSet() const
|
||||||
|
@ -228,14 +230,14 @@ const std::deque<size_t>& PeerSessionResource::amAllowedIndexSet() const
|
||||||
|
|
||||||
void PeerSessionResource::addAmAllowedIndex(size_t index)
|
void PeerSessionResource::addAmAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
if(!indexIncluded(_amAllowedIndexSet, index)) {
|
updateIndexSet(_amAllowedIndexSet, index);
|
||||||
_amAllowedIndexSet.push_back(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::amAllowedIndexSetContains(size_t index) const
|
bool PeerSessionResource::amAllowedIndexSetContains(size_t index) const
|
||||||
{
|
{
|
||||||
return indexIncluded(_amAllowedIndexSet, index);
|
return std::binary_search(_amAllowedIndexSet.begin(),
|
||||||
|
_amAllowedIndexSet.end(),
|
||||||
|
index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::extendedMessagingEnabled() const
|
bool PeerSessionResource::extendedMessagingEnabled() const
|
||||||
|
|
|
@ -80,9 +80,6 @@ private:
|
||||||
Time _lastDownloadUpdate;
|
Time _lastDownloadUpdate;
|
||||||
|
|
||||||
Time _lastAmUnchoking;
|
Time _lastAmUnchoking;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool indexIncluded(const std::deque<T>& c, T index) const;
|
|
||||||
public:
|
public:
|
||||||
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
|
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue