A STL-vector that supports inserts sorted by an OverlayKey found somewhere in the type. More...
#include <NodeVector.h>
Public Types | |
typedef std::vector< T >::iterator | iterator |
iterator for this vector | |
typedef std::vector< T > ::const_iterator | const_iterator |
read-only iterator for this vector | |
Public Member Functions | |
BaseKeySortedVector (uint16_t maxSize=0, const Comparator< OverlayKey > *comparator=NULL, const AbstractProxComparator *proxComparator=NULL, const AbstractProxKeyComparator *proxKeyComparator=NULL, uint16_t sizeProx=0, uint16_t sizeComb=0) | |
constructor | |
virtual | ~BaseKeySortedVector () |
destructor | |
bool | isAddable (const T &element) const |
indicates if an object of type T can be added to the NodeVector | |
bool | isFull () const |
indicates if NodeVector holds maxSize nodes | |
bool | isEmpty () const |
indicates if NodeVector holds at least one node | |
int | add (const T &element) |
adds an element of type T in increasing order to the NodeVector and returns the position of the added element or -1 if the element was not added | |
const bool | contains (const OverlayKey &key) const |
Searches for an OverlayKey in NodeVector and returns true, if it is found. | |
const T & | find (const OverlayKey &key) const |
searches for an OverlayKey in NodeVector | |
iterator | findIterator (const OverlayKey &key) |
Searches for an OberlayKey in a NodeVector and returns an appropriate iterator. | |
void | downsizeTo (const uint32_t maxElements) |
Downsize the vector to a maximum of maxElements. | |
void | setComparator (const Comparator< OverlayKey > *comparator) |
Static Public Attributes | |
static const T | UNSPECIFIED_ELEMENT |
unspecified element of type T | |
Private Attributes | |
const Comparator< OverlayKey > * | comparator |
the OverlayKey Comparator for this vector | |
const AbstractProxComparator * | proxComparator |
const AbstractProxKeyComparator * | proxKeyComparator |
uint16_t | maxSize |
maximum nodes this vector holds | |
uint16_t | sizeProx |
uint16_t | sizeComb |
A STL-vector that supports inserts sorted by an OverlayKey found somewhere in the type.
maxSize | maximum nodes this vector holds | |
comparator | OverlayKey Comparator for this vector | |
useRtt | sort by rtt after sorting using the comparator destructor indicates if an object of type T can be added to the NodeVector | |
element | the element to add |
element | the element to add |
key | the OverlayKey to find |
key | the OverlayKey to find |
key | The key to search |
maxElements | The maximum number of elements after downsizing |
Definition at line 327 of file NodeVector.h.
typedef std::vector<T>::const_iterator BaseKeySortedVector< T, T_key, T_prox >::const_iterator |
read-only iterator for this vector
Definition at line 368 of file NodeVector.h.
typedef std::vector<T>::iterator BaseKeySortedVector< T, T_key, T_prox >::iterator |
iterator for this vector
Definition at line 365 of file NodeVector.h.
BaseKeySortedVector< T, T_key, T_prox >::BaseKeySortedVector | ( | uint16_t | maxSize = 0 , |
|
const Comparator< OverlayKey > * | comparator = NULL , |
|||
const AbstractProxComparator * | proxComparator = NULL , |
|||
const AbstractProxKeyComparator * | proxKeyComparator = NULL , |
|||
uint16_t | sizeProx = 0 , |
|||
uint16_t | sizeComb = 0 | |||
) | [inline] |
constructor
maxSize | maximum nodes this vector holds | |
comparator | OverlayKey comparator for this vector | |
proxComparator | proximity comparator for this vector | |
proxKeyComparator | proximity/key comparator for this vector | |
sizeProx | number of nodes sorted by proximity | |
sizeComb | number of nodes sorted by proximity/key |
Definition at line 348 of file NodeVector.h.
: std::vector<T>(), comparator(comparator), proxComparator(proxComparator), proxKeyComparator(proxKeyComparator), maxSize(maxSize), sizeProx(sizeProx), sizeComb(sizeComb) { };
virtual BaseKeySortedVector< T, T_key, T_prox >::~BaseKeySortedVector | ( | ) | [inline, virtual] |
int BaseKeySortedVector< T, T_key, T_prox >::add | ( | const T & | element | ) | [inline] |
adds an element of type T in increasing order to the NodeVector and returns the position of the added element or -1 if the element was not added
element | the element to add |
Definition at line 428 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), IterativePathLookup::add(), IterativeLookup::addSibling(), IterativeLookup::checkStop(), BrooseBucket::fillVector(), PastryRoutingTable::findCloserNodes(), PastryNeighborhoodSet::findCloserNodes(), PastryLeafSet::findCloserNodes(), MyOverlay::findNode(), Kademlia::findNode(), Broose::findNode(), BasePastry::findNode(), IterativePathLookup::handleFailedNodeResponse(), DHT::handlePutRequest(), IterativePathLookup::handleTimeout(), Kademlia::refillSiblingTable(), and Kademlia::routingAdd().
{ int pos = -1; // check if handle is addable if (isAddable(element)) { // yes -> // add handle to the appropriate position if ((std::vector<T>::size() != 0) && (comparator || proxComparator || proxKeyComparator)) { iterator i; for (i = std::vector<T>::begin(), pos=0; i != std::vector<T>::end(); i++, pos++) { // don't add node with same key twice if (T_key::key(element) == T_key::key(*i)) { return -1; } if (pos < sizeProx) { assert(proxComparator); // only compare proximity int compResult = proxComparator->compare(T_prox::prox(element), T_prox::prox(*i)); //if (T_prox::prox(element).compareTo(T_prox::prox(*i))) { if (compResult < 0) { iterator temp_it = std::vector<T>::insert(i, element); T temp = *(temp_it++); std::vector<T>::erase(temp_it); //re-insert replaced entry into other 2 ranges add(temp); break; } } else if (pos < sizeProx + sizeComb) { assert(proxKeyComparator); // compare proximity and key distance int compResult = proxKeyComparator->compare(ProxKey(T_prox::prox(element), T_key::key(element)), ProxKey(T_prox::prox(*i), T_key::key(*i))); if (compResult < 0) { iterator temp_it = std::vector<T>::insert(i, element); T temp = *(temp_it++); std::vector<T>::erase(temp_it); //re-insert replaced entry into last range add(temp); break; } } else { assert(comparator); // only consider key distance int compResult = comparator->compare(T_key::key(element), T_key::key(*i)); if (compResult < 0) { std::vector<T>::insert(i, element); break; } } } if (i == std::vector<T>::end()) { pos = std::vector<T>::size(); push_back(element); } } else { for (iterator i = std::vector<T>::begin(); i != std::vector<T>::end(); i++) { // don't add node with same key twice if (T_key::key(element) == T_key::key(*i)) { return -1; } } pos = std::vector<T>::size(); push_back(element); } // adjust size if ((maxSize != 0) && (std::vector<T>::size() > maxSize)) { std::vector<T>::resize(maxSize); } } return pos; };
const bool BaseKeySortedVector< T, T_key, T_prox >::contains | ( | const OverlayKey & | key | ) | const [inline] |
Searches for an OverlayKey in NodeVector and returns true, if it is found.
key | the OverlayKey to find |
Definition at line 517 of file NodeVector.h.
Referenced by BasePastry::isSiblingFor().
{ for (const_iterator i = std::vector<T>::begin(); i != std::vector<T>::end(); i++) { if (T_key::key(*i) == key) return true; } return false; }
void BaseKeySortedVector< T, T_key, T_prox >::downsizeTo | ( | const uint32_t | maxElements | ) | [inline] |
Downsize the vector to a maximum of maxElements.
maxElements | The maximum number of elements after downsizing |
Definition at line 562 of file NodeVector.h.
Referenced by oversim::Chord::findNode().
{
if (std::vector<T>::size() > maxElements) {
std::vector<T>::erase(std::vector<T>::begin()+maxElements, std::vector<T>::end());
}
}
const T& BaseKeySortedVector< T, T_key, T_prox >::find | ( | const OverlayKey & | key | ) | const [inline] |
searches for an OverlayKey in NodeVector
key | the OverlayKey to find |
Definition at line 533 of file NodeVector.h.
{ for (const_iterator i = std::vector<T>::begin(); i != std::vector<T>::end(); i++) { if (T_key::key(*i) == key) return *i; } return UNSPECIFIED_ELEMENT; };
iterator BaseKeySortedVector< T, T_key, T_prox >::findIterator | ( | const OverlayKey & | key | ) | [inline] |
Searches for an OberlayKey in a NodeVector and returns an appropriate iterator.
key | The key to search |
Definition at line 549 of file NodeVector.h.
Referenced by IterativePathLookup::handleTimeout(), Kademlia::routingAdd(), and Kademlia::routingTimeout().
{ iterator i; for (i = std::vector<T>::begin(); i != std::vector<T>::end(); i++) if (T_key::key(*i) == key) break; return i; }
bool BaseKeySortedVector< T, T_key, T_prox >::isAddable | ( | const T & | element | ) | const [inline] |
indicates if an object of type T can be added to the NodeVector
element | the element to add |
Definition at line 381 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), IterativeLookup::addSibling(), and Kademlia::routingAdd().
{ if (maxSize == 0) { return true; } return (std::vector<T>::size() != maxSize || (comparator && (comparator->compare(T_key::key(element), T_key::key(std::vector<T>::back())) <= 0 )) || (proxComparator && (proxComparator->compare(T_prox::prox(element), T_prox::prox(std::vector<T>::back())) <= 0 )) || (proxKeyComparator && (proxKeyComparator->compare(ProxKey(T_prox::prox(element), T_key::key(element)), ProxKey(T_prox::prox(std::vector<T>::back()), T_key::key(std::vector<T>::back()))) <= 0 ))); };
bool BaseKeySortedVector< T, T_key, T_prox >::isEmpty | ( | ) | const [inline] |
indicates if NodeVector holds at least one node
Definition at line 416 of file NodeVector.h.
Referenced by Kademlia::findNode().
{
return(std::vector<T>::size() == 0);
};
bool BaseKeySortedVector< T, T_key, T_prox >::isFull | ( | ) | const [inline] |
indicates if NodeVector holds maxSize nodes
Definition at line 406 of file NodeVector.h.
Referenced by IterativeLookup::addSibling(), Kademlia::findNode(), Kademlia::isSiblingFor(), Kademlia::refillSiblingTable(), and Kademlia::routingAdd().
{ return(std::vector<T>::size() == maxSize); };
void BaseKeySortedVector< T, T_key, T_prox >::setComparator | ( | const Comparator< OverlayKey > * | comparator | ) | [inline] |
Definition at line 569 of file NodeVector.h.
Referenced by Broose::findNode(), and Kademlia::routingInit().
{ this->comparator = comparator; }
const Comparator<OverlayKey>* BaseKeySortedVector< T, T_key, T_prox >::comparator [private] |
the OverlayKey Comparator for this vector
Definition at line 330 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), and BaseKeySortedVector< LookupEntry >::isAddable().
uint16_t BaseKeySortedVector< T, T_key, T_prox >::maxSize [private] |
maximum nodes this vector holds
Definition at line 333 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), BaseKeySortedVector< LookupEntry >::isAddable(), and BaseKeySortedVector< LookupEntry >::isFull().
const AbstractProxComparator* BaseKeySortedVector< T, T_key, T_prox >::proxComparator [private] |
Definition at line 331 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), and BaseKeySortedVector< LookupEntry >::isAddable().
const AbstractProxKeyComparator* BaseKeySortedVector< T, T_key, T_prox >::proxKeyComparator [private] |
Definition at line 332 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add(), and BaseKeySortedVector< LookupEntry >::isAddable().
uint16_t BaseKeySortedVector< T, T_key, T_prox >::sizeComb [private] |
Definition at line 335 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add().
uint16_t BaseKeySortedVector< T, T_key, T_prox >::sizeProx [private] |
Definition at line 334 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::add().
const T BaseKeySortedVector< T, T_key, T_rtt >::UNSPECIFIED_ELEMENT [static] |
unspecified element of type T
an unspecified element of the NodeVector
Definition at line 370 of file NodeVector.h.
Referenced by BaseKeySortedVector< LookupEntry >::find().