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.
00354 : 00355 std::vector<T>(), 00356 comparator(comparator), 00357 proxComparator(proxComparator), 00358 proxKeyComparator(proxKeyComparator), 00359 maxSize(maxSize), 00360 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().
00429 { 00430 int pos = -1; 00431 00432 // check if handle is addable 00433 if (isAddable(element)) { // yes -> 00434 00435 // add handle to the appropriate position 00436 if ((std::vector<T>::size() != 0) && 00437 (comparator || proxComparator || proxKeyComparator)) { 00438 iterator i; 00439 for (i = std::vector<T>::begin(), pos=0; 00440 i != std::vector<T>::end(); i++, pos++) { 00441 00442 // don't add node with same key twice 00443 if (T_key::key(element) == T_key::key(*i)) { 00444 return -1; 00445 } 00446 00447 if (pos < sizeProx) { 00448 assert(proxComparator); 00449 // only compare proximity 00450 int compResult = 00451 proxComparator->compare(T_prox::prox(element), 00452 T_prox::prox(*i)); 00453 //if (T_prox::prox(element).compareTo(T_prox::prox(*i))) { 00454 if (compResult < 0) { 00455 iterator temp_it = std::vector<T>::insert(i, element); 00456 T temp = *(temp_it++); 00457 std::vector<T>::erase(temp_it); 00458 //re-insert replaced entry into other 2 ranges 00459 add(temp); 00460 break; 00461 } 00462 } else if (pos < sizeProx + sizeComb) { 00463 assert(proxKeyComparator); 00464 // compare proximity and key distance 00465 int compResult = proxKeyComparator->compare(ProxKey(T_prox::prox(element), T_key::key(element)), 00466 ProxKey(T_prox::prox(*i), T_key::key(*i))); 00467 if (compResult < 0) { 00468 iterator temp_it = std::vector<T>::insert(i, element); 00469 T temp = *(temp_it++); 00470 std::vector<T>::erase(temp_it); 00471 //re-insert replaced entry into last range 00472 add(temp); 00473 break; 00474 } 00475 } else { 00476 assert(comparator); 00477 // only consider key distance 00478 int compResult = comparator->compare(T_key::key(element), 00479 T_key::key(*i)); 00480 if (compResult < 0) { 00481 std::vector<T>::insert(i, element); 00482 break; 00483 } 00484 } 00485 } 00486 if (i == std::vector<T>::end()) { 00487 pos = std::vector<T>::size(); 00488 push_back(element); 00489 } 00490 } else { 00491 for (iterator i = std::vector<T>::begin(); i != std::vector<T>::end(); 00492 i++) { 00493 // don't add node with same key twice 00494 if (T_key::key(element) == T_key::key(*i)) { 00495 return -1; 00496 } 00497 } 00498 pos = std::vector<T>::size(); 00499 push_back(element); 00500 } 00501 00502 // adjust size 00503 if ((maxSize != 0) && (std::vector<T>::size() > maxSize)) { 00504 std::vector<T>::resize(maxSize); 00505 } 00506 } 00507 return pos; 00508 };
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().
00517 { 00518 for (const_iterator i = std::vector<T>::begin(); 00519 i != std::vector<T>::end(); i++) { 00520 if (T_key::key(*i) == key) return true; 00521 } 00522 00523 return false; 00524 }
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().
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.
00534 { 00535 for (const_iterator i = std::vector<T>::begin(); 00536 i != std::vector<T>::end(); i++) { 00537 if (T_key::key(*i) == key) return *i; 00538 } 00539 return UNSPECIFIED_ELEMENT; 00540 };
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().
00550 { 00551 iterator i; 00552 for (i = std::vector<T>::begin(); i != std::vector<T>::end(); i++) 00553 if (T_key::key(*i) == key) break; 00554 return i; 00555 }
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().
00382 { 00383 if (maxSize == 0) { 00384 return true; 00385 } 00386 00387 return (std::vector<T>::size() != maxSize || 00388 (comparator && 00389 (comparator->compare(T_key::key(element), 00390 T_key::key(std::vector<T>::back())) <= 0 )) || 00391 (proxComparator && 00392 (proxComparator->compare(T_prox::prox(element), 00393 T_prox::prox(std::vector<T>::back())) <= 0 )) || 00394 (proxKeyComparator && 00395 (proxKeyComparator->compare(ProxKey(T_prox::prox(element), 00396 T_key::key(element)), 00397 ProxKey(T_prox::prox(std::vector<T>::back()), 00398 T_key::key(std::vector<T>::back()))) <= 0 ))); 00399 };
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().
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().
00407 { 00408 return(std::vector<T>::size() == maxSize); 00409 };
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().
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 [inline, 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().