summaryrefslogtreecommitdiff
path: root/src/PeerSessionResource.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-05-16 14:51:14 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-05-16 14:51:14 +0000
commit99f07b515fe8a9facb3093da588f898b8f5ec5c4 (patch)
tree012f5bd05a35a59836ef8e3596b30eca521b959e /src/PeerSessionResource.cc
parent738996932abd301d1cd9f654d1e693efbbd3fdf5 (diff)
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
Diffstat (limited to 'src/PeerSessionResource.cc')
-rw-r--r--src/PeerSessionResource.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc
index a5c54fc7..1a111a2b 100644
--- a/src/PeerSessionResource.cc
+++ b/src/PeerSessionResource.cc
@@ -203,22 +203,24 @@ const std::deque<size_t>& PeerSessionResource::peerAllowedIndexSet() const
return _peerAllowedIndexSet;
}
-template<typename T>
-bool PeerSessionResource::indexIncluded(const std::deque<T>& c, T index) const
+static void updateIndexSet(std::deque<size_t>& c, size_t index)
{
- 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)
{
- if(!indexIncluded(_peerAllowedIndexSet, index)) {
- _peerAllowedIndexSet.push_back(index);
- }
+ updateIndexSet(_peerAllowedIndexSet, index);
}
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
@@ -228,14 +230,14 @@ const std::deque<size_t>& PeerSessionResource::amAllowedIndexSet() const
void PeerSessionResource::addAmAllowedIndex(size_t index)
{
- if(!indexIncluded(_amAllowedIndexSet, index)) {
- _amAllowedIndexSet.push_back(index);
- }
+ updateIndexSet(_amAllowedIndexSet, index);
}
bool PeerSessionResource::amAllowedIndexSetContains(size_t index) const
{
- return indexIncluded(_amAllowedIndexSet, index);
+ return std::binary_search(_amAllowedIndexSet.begin(),
+ _amAllowedIndexSet.end(),
+ index);
}
bool PeerSessionResource::extendedMessagingEnabled() const