ariba::utility::Identifier Class Reference

#include <source/ariba/utility/types/Identifier.h>

Inherits Address.

Inherited by ariba::utility::LinkID, ariba::utility::NodeID, and ariba::utility::SpoVNetID.

Collaboration diagram for ariba::utility::Identifier:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void clearAddress ()
virtual bool setAddress (string address)
virtual string getAddress () const
 Identifier ()
 Identifier (uint32_t num)
 Identifier (const unsigned char *buffer, uint size)
 Identifier (const std::string &str, uint base=16)
 Identifier (const Identifier &rhs)
virtual ~Identifier ()
virtual std::string toString (uint base=16) const
bool isUnspecified () const
bool operator< (const Identifier &compKey) const
bool operator> (const Identifier &compKey) const
bool operator<= (const Identifier &compKey) const
bool operator>= (const Identifier &compKey) const
bool operator== (const Identifier &compKey) const
bool operator!= (const Identifier &compKey) const
int compareTo (const Identifier &compKey) const
Identifieroperator= (const Identifier &rhs)
Identifieroperator-- ()
Identifieroperator++ ()
Identifieroperator+= (const Identifier &rhs)
Identifieroperator-= (const Identifier &rhs)
Identifier operator+ (const Identifier &rhs) const
Identifier operator- (const Identifier &rhs) const
Identifier operator-- (int)
Identifier operator++ (int)
Identifier operator>> (uint num) const
Identifier operator<< (uint num) const
Identifier operator& (const Identifier &rhs) const
Identifier operator| (const Identifier &rhs) const
Identifier operator^ (const Identifier &rhs) const
Identifier operator~ () const
IdentifierBit operator[] (uint n)
IdentifiersetBitAt (uint pos, bool value)
uint32_t get (uint p, uint n) const
size_t hash () const
int log_2 () const
Identifier randomSuffix (uint pos) const
Identifier randomPrefix (uint pos) const
uint sharedPrefixLength (const Identifier &compKey) const
bool isBetween (const Identifier &keyA, const Identifier &keyB) const
bool isBetweenR (const Identifier &keyA, const Identifier &keyB) const
bool isBetweenL (const Identifier &keyA, const Identifier &keyB) const
bool isBetweenLR (const Identifier &keyA, const Identifier &keyB) const

Static Public Member Functions

static void setKeyLength (uint length)
static uint getLength ()
static Identifier random ()
static Identifier max ()
static Identifier sha1 (const string &value)
static Identifier sha1 (const uint8_t *value, size_t length)
static Identifier pow2 (uint exponent)

Static Public Attributes

static const Identifier UNSPECIFIED_KEY
static const Identifier ZERO
static const Identifier ONE

Private Member Functions

 use_logging_h (Identifier)
void seed ()
void trim ()
void clear ()

Private Attributes

 VSERIALIZEABLE
bool isUnspec
mp_limb_t key [array_size+1]

Static Private Attributes

static uint keyLength = MAX_KEYLENGTH
static uint aSize
static mp_limb_t GMP_MSB_MASK
static const size_t array_size

Friends

std::ostream & operator<< (std::ostream &os, const Identifier &c)


Detailed Description

An abstract address class for identifier.

This class is the base for all identifier classes.

Definition at line 67 of file Identifier.h.


Constructor & Destructor Documentation

ariba::utility::Identifier::Identifier (  ) 

Default constructor

Contructs an unspecified overlay key

Definition at line 91 of file Identifier.cpp.

References isUnspec, seed(), and trim().

ariba::utility::Identifier::Identifier ( uint32_t  num  ) 

Constructs an overlay key initialized with a common integer

Parameters:
num The integer to initialize this key with

Definition at line 98 of file Identifier.cpp.

References clearAddress(), key, seed(), and trim().

ariba::utility::Identifier::Identifier ( const unsigned char *  buffer,
uint  size 
)

Constructs a key out of a buffer

Parameters:
buffer Source buffer
size Buffer size (in bytes)

Definition at line 106 of file Identifier.cpp.

References aSize, clearAddress(), key, seed(), and trim().

ariba::utility::Identifier::Identifier ( const std::string &  str,
uint  base = 16 
)

Constructs a key out of a string number.

Definition at line 117 of file Identifier.cpp.

References clearAddress(), key, logging_error, seed(), and trim().

ariba::utility::Identifier::Identifier ( const Identifier rhs  ) 

Copy constructor.

Parameters:
rhs The key to copy.

Definition at line 148 of file Identifier.cpp.

References seed().

ariba::utility::Identifier::~Identifier (  )  [virtual]

Default destructor.

Does nothing ATM.

Definition at line 154 of file Identifier.cpp.


Member Function Documentation

void ariba::utility::Identifier::clear (  )  [private]

set this->key to 0 and isUnspec to false

void ariba::utility::Identifier::clearAddress (  )  [virtual]

Definition at line 71 of file Identifier.cpp.

References array_size, isUnspec, key, and trim().

Referenced by Identifier(), random(), and sha1().

int ariba::utility::Identifier::compareTo ( const Identifier compKey  )  const

Unifies all compare operations in one method

Parameters:
compKey key to compare with
Returns:
int -1 if smaller, 0 if equal, 1 if greater

Definition at line 677 of file Identifier.cpp.

References aSize, isUnspec, and key.

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), and sharedPrefixLength().

uint32_t ariba::utility::Identifier::get ( uint  p,
uint  n 
) const

Returns a sub integer at position p with n-bits. p is counted starting from the least significant bit of the key as bit 0. Bit p of the key becomes bit 0 of the returned integer.

Parameters:
p the position of the sub-integer
n the number of bits to be returned (max.32)
Returns:
The sub-integer.

Definition at line 435 of file Identifier.cpp.

References key, keyLength, and logging_error.

string ariba::utility::Identifier::getAddress (  )  const [virtual]

Definition at line 82 of file Identifier.cpp.

References Address::toString().

uint ariba::utility::Identifier::getLength (  )  [static]

Returns the length in number of bits.

Returns:
The length in number of bits.

Definition at line 190 of file Identifier.cpp.

References keyLength.

size_t ariba::utility::Identifier::hash (  )  const

Returns a hash value for the key

Returns:
size_t The hash value

Definition at line 535 of file Identifier.cpp.

References key.

bool ariba::utility::Identifier::isBetween ( const Identifier keyA,
const Identifier keyB 
) const

Returns true, if this key is element of the interval (keyA, keyB) on the ring.

Parameters:
keyA The left border of the interval
keyB The right border of the interval
Returns:
True, if the key is element of the interval (keyA, keyB)

Definition at line 540 of file Identifier.cpp.

References isUnspec.

bool ariba::utility::Identifier::isBetweenL ( const Identifier keyA,
const Identifier keyB 
) const

Returns true, if this key is element of the interval [keyA, keyB) on the ring.

Parameters:
keyA The left border of the interval
keyB The right border of the interval
Returns:
True, if the key is element of the interval [keyA, keyB)

Definition at line 558 of file Identifier.cpp.

References isUnspec.

bool ariba::utility::Identifier::isBetweenLR ( const Identifier keyA,
const Identifier keyB 
) const

Returns true, if this key is element of the interval [keyA, keyB] on the ring.

Parameters:
keyA The left border of the interval
keyB The right border of the interval
Returns:
True, if the key is element of the interval [keyA, keyB]

Definition at line 567 of file Identifier.cpp.

References isUnspec.

bool ariba::utility::Identifier::isBetweenR ( const Identifier keyA,
const Identifier keyB 
) const

Returns true, if this key is element of the interval (keyA, keyB] on the ring.

Parameters:
keyA The left border of the interval
keyB The right border of the interval
Returns:
True, if the key is element of the interval (keyA, keyB]

Definition at line 549 of file Identifier.cpp.

References isUnspec.

bool ariba::utility::Identifier::isUnspecified (  )  const

int ariba::utility::Identifier::log_2 (  )  const

Returns the position of the msb in this key, which represents just the logarithm to base 2.

Returns:
The logarithm to base 2 of this key.

Definition at line 513 of file Identifier.cpp.

References aSize, and key.

Identifier ariba::utility::Identifier::max (  )  [static]

Returns the maximum key, i.e. a key filled with bit 1

Returns:
The maximum key, i.e. a key filled with bit 1

Definition at line 587 of file Identifier.cpp.

References aSize, isUnspec, key, and trim().

bool ariba::utility::Identifier::operator!= ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is not equal to this->key, else false

Definition at line 327 of file Identifier.cpp.

References compareTo().

Identifier ariba::utility::Identifier::operator& ( const Identifier rhs  )  const

bitwise AND of rhs->key and this->key

Parameters:
rhs the Identifier AND is calculated with
Returns:
this Identifier object

Definition at line 352 of file Identifier.cpp.

References aSize, and key.

Identifier ariba::utility::Identifier::operator+ ( const Identifier rhs  )  const

adds rhs->key to this->key

Parameters:
rhs the Identifier with the defined key
Returns:
this Identifier object

Definition at line 294 of file Identifier.cpp.

Identifier ariba::utility::Identifier::operator++ ( int   ) 

adds 1 to this->key

Returns:
this Identifier object

Definition at line 271 of file Identifier.cpp.

References ONE.

Identifier & ariba::utility::Identifier::operator++ (  ) 

adds 1 to this->key

Returns:
this Identifier object

Definition at line 266 of file Identifier.cpp.

References ONE.

Identifier & ariba::utility::Identifier::operator+= ( const Identifier rhs  ) 

adds rhs->key to this->key

Parameters:
rhs the Identifier with the defined key
Returns:
this Identifier object

Definition at line 278 of file Identifier.cpp.

References aSize, isUnspec, key, and trim().

Identifier ariba::utility::Identifier::operator- ( const Identifier rhs  )  const

substracts rhs->key from this->key

Parameters:
rhs the Identifier with the defined key
Returns:
this Identifier object

Definition at line 301 of file Identifier.cpp.

Identifier ariba::utility::Identifier::operator-- ( int   ) 

substracts 1 from this->key

Returns:
this Identifier object

Definition at line 259 of file Identifier.cpp.

References ONE.

Identifier & ariba::utility::Identifier::operator-- (  ) 

substracts 1 from this->key

Returns:
this Identifier object

Definition at line 254 of file Identifier.cpp.

References ONE.

Identifier & ariba::utility::Identifier::operator-= ( const Identifier rhs  ) 

substracts rhs->key from this->key

Parameters:
rhs the Identifier with the defined key
Returns:
this Identifier object

Definition at line 286 of file Identifier.cpp.

References aSize, isUnspec, key, and trim().

bool ariba::utility::Identifier::operator< ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is smaller than this->key, else false

Definition at line 308 of file Identifier.cpp.

References compareTo().

Identifier ariba::utility::Identifier::operator<< ( uint  num  )  const

bitwise shift left

Parameters:
num number of bits to shift
Returns:
this Identifier object

Definition at line 392 of file Identifier.cpp.

References aSize, isUnspec, key, trim(), and ZERO.

bool ariba::utility::Identifier::operator<= ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is smaller than or equal to this->key, else false

Definition at line 314 of file Identifier.cpp.

References compareTo().

Identifier & ariba::utility::Identifier::operator= ( const Identifier rhs  ) 

assigns Identifier of rhs to this->key

Parameters:
rhs the Identifier with the defined key
Returns:
this Identifier object

Definition at line 247 of file Identifier.cpp.

References aSize, isUnspec, and key.

bool ariba::utility::Identifier::operator== ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is equal to this->key, else false

Definition at line 320 of file Identifier.cpp.

References compareTo(), and isUnspecified().

bool ariba::utility::Identifier::operator> ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is greater than this->key, else false

Definition at line 311 of file Identifier.cpp.

References compareTo().

bool ariba::utility::Identifier::operator>= ( const Identifier compKey  )  const

compares this to a given Identifier

Parameters:
compKey the the Identifier to compare this to
Returns:
true if compKey->key is greater than or equal to this->key, else false

Definition at line 317 of file Identifier.cpp.

References compareTo().

Identifier ariba::utility::Identifier::operator>> ( uint  num  )  const

bitwise shift right

Parameters:
num number of bits to shift
Returns:
this Identifier object

Definition at line 373 of file Identifier.cpp.

References aSize, isUnspec, key, trim(), and ZERO.

IdentifierBit ariba::utility::Identifier::operator[] ( uint  n  ) 

returns the n-th bit of this->key

Parameters:
n the position of the returned bit
Returns:
the bit on position n in this->key

Definition at line 411 of file Identifier.cpp.

Identifier ariba::utility::Identifier::operator^ ( const Identifier rhs  )  const

bitwise XOR of rhs->key and this->key

Parameters:
rhs the Identifier XOR is calculated with
Returns:
this Identifier object

Definition at line 332 of file Identifier.cpp.

References aSize, and key.

Identifier ariba::utility::Identifier::operator| ( const Identifier rhs  )  const

bitwise OR of rhs->key and this->key

Parameters:
rhs the Identifier OR is calculated with
Returns:
this Identifier object

Definition at line 342 of file Identifier.cpp.

References aSize, and key.

Identifier ariba::utility::Identifier::operator~ (  )  const

bitwise NOT of this->key

Returns:
this Identifier object

Definition at line 362 of file Identifier.cpp.

References aSize, key, and trim().

Identifier ariba::utility::Identifier::pow2 ( uint  exponent  )  [static]

Returns a key 2^exponent.

Parameters:
exponent The exponent.
Returns:
Key=2^exponent.

Definition at line 657 of file Identifier.cpp.

References key, and ZERO.

Identifier ariba::utility::Identifier::random (  )  [static]

Returns a random key.

Returns:
A random key.

Definition at line 600 of file Identifier.cpp.

References aSize, clearAddress(), isUnspecified(), key, trim(), and ZERO.

Referenced by ariba::utility::LinkID::create().

Identifier ariba::utility::Identifier::randomPrefix ( uint  pos  )  const

Fills the prefix starting at pos with random bits to msb.

Parameters:
pos 
Returns:
Identifier

Definition at line 467 of file Identifier.cpp.

References aSize, key, and trim().

Identifier ariba::utility::Identifier::randomSuffix ( uint  pos  )  const

Fills the suffix starting at pos with random bits to lsb.

Parameters:
pos 
Returns:
Identifier

Definition at line 451 of file Identifier.cpp.

References key, and trim().

void ariba::utility::Identifier::seed (  )  [private]

Definition at line 157 of file Identifier.cpp.

References ariba::utility::randstate.

Referenced by Identifier().

bool ariba::utility::Identifier::setAddress ( string  address  )  [virtual]

Definition at line 78 of file Identifier.cpp.

Identifier & ariba::utility::Identifier::setBitAt ( uint  pos,
bool  value 
)

sets a bit of this->key

Parameters:
pos the position of the bit to set
value new value for bit at position pos
Returns:
*this

Definition at line 415 of file Identifier.cpp.

References key.

Referenced by ariba::utility::IdentifierBit::operator=(), and ariba::utility::IdentifierBit::operator^=().

void ariba::utility::Identifier::setKeyLength ( uint  length  )  [static]

Set the length of an Identifier

Parameters:
length keylength in bits

Definition at line 171 of file Identifier.cpp.

References aSize, GMP_MSB_MASK, keyLength, logging_error, and MAX_KEYLENGTH.

Identifier ariba::utility::Identifier::sha1 ( const uint8_t *  value,
size_t  length 
) [static]

Identifier ariba::utility::Identifier::sha1 ( const string &  value  )  [static]

Returns a key with the SHA1 cryptographic hash of a string

Parameters:
value A string value.
Returns:
SHA1 of value

Definition at line 620 of file Identifier.cpp.

References aSize, clearAddress(), CSHA1::Final(), CSHA1::GetHash(), isUnspec, key, CSHA1::Reset(), trim(), and CSHA1::Update().

uint ariba::utility::Identifier::sharedPrefixLength ( const Identifier compKey  )  const

Calculates the number of equal bits from the left with another Key (shared prefix length)

Parameters:
compKey the Key to compare with
Returns:
length of shared prefix

Definition at line 486 of file Identifier.cpp.

References aSize, compareTo(), key, and keyLength.

std::string ariba::utility::Identifier::toString ( uint  base = 16  )  const [virtual]

Returns a string representation of this key

Returns:
String representation of this key

Definition at line 198 of file Identifier.cpp.

References aSize, ariba::utility::HEX, isUnspec, key, keyLength, logging_error, and MAX_KEYLENGTH.

Referenced by ariba::utility::PathloadMeasurement::blockingFunction(), ariba::overlay::BaseOverlay::createSpoVNet(), ariba::overlay::BaseOverlay::dropLink(), ariba::communication::BaseCommunication::dropLink(), ariba::overlay::BaseOverlay::establishDirectLink(), ariba::overlay::BaseOverlay::establishLink(), ariba::communication::BaseCommunication::establishLink(), ariba::overlay::OneHop::eventFunction(), ariba::overlay::Chord::eventFunction(), ariba::application::pingpong::PingPong::eventFunction(), ariba::overlay::BaseOverlay::getLinkHTMLInfo(), ariba::overlay::BaseOverlay::handleData(), ariba::overlay::BaseOverlay::handleJoinReply(), ariba::overlay::BaseOverlay::handleJoinRequest(), ariba::overlay::BaseOverlay::handleLinkReply(), ariba::overlay::BaseOverlay::handleLinkUpdate(), ariba::overlay::OverlayBootstrap::handleSystemEvent(), ariba::overlay::BaseOverlay::joinSpoVNet(), ariba::utility::PathloadMeasurement::measure(), ariba::application::pingpong::PingPong::onJoinCompleted(), ariba::application::pingpong::PingPong::onJoinFailed(), ariba::application::pingpong::PingPong::onLeaveCompleted(), ariba::application::pingpong::PingPong::onLeaveFailed(), ariba::application::pingpong::PingPong::onLinkChanged(), ariba::overlay::OneHop::onLinkDown(), ariba::overlay::Chord::onLinkDown(), ariba::application::pingpong::PingPong::onLinkDown(), ariba::overlay::BaseOverlay::onLinkFail(), ariba::application::pingpong::PingPong::onLinkFail(), ariba::overlay::BaseOverlay::onLinkQoSChanged(), ariba::application::pingpong::PingPong::onLinkRequest(), ariba::overlay::Chord::onLinkUp(), ariba::overlay::BaseOverlay::onLinkUp(), ariba::application::pingpong::PingPong::onLinkUp(), ariba::overlay::OneHop::onMessage(), ariba::overlay::Chord::onMessage(), ariba::application::pingpong::PingPong::onMessage(), ariba::overlay::BaseOverlay::onNodeJoin(), ariba::utility::operator<<(), ariba::overlay::OverlayBootstrap::publish(), ariba::communication::BaseCommunication::receiveMessage(), ariba::overlay::BaseOverlay::refreshRelayInformation(), ariba::overlay::OneHop::resolveNode(), ariba::overlay::OneHop::routeMessage(), ariba::overlay::BaseOverlay::send_link(), ariba::overlay::BaseOverlay::sendMessage(), ariba::communication::BaseCommunication::sendMessage(), ariba::overlay::Chord::setup(), ariba::overlay::Chord::showLinks(), ariba::overlay::BaseOverlay::stabilizeRelays(), ariba::application::pingpong::PingPong::startup(), ariba::overlay::LinkDescriptor::to_string(), ariba::utility::OvlVis::visChangeNodeColor(), ariba::utility::OvlVis::visChangeNodeIcon(), ariba::utility::OvlVis::visChangeStatus(), ariba::utility::OvlVis::visCLIOEndMeasurement(), ariba::utility::OvlVis::visCLIOInitMeasurement(), ariba::utility::OvlVis::visConnect(), ariba::utility::OvlVis::visCreate(), ariba::utility::OvlVis::visDeleteNodeLabel(), ariba::utility::OvlVis::visFailedConnect(), ariba::utility::OvlVis::visSendMessage(), ariba::utility::OvlVis::visShowLinkBubble(), ariba::utility::OvlVis::visShowNodeBubble(), ariba::utility::OvlVis::visShowNodeLabel(), ariba::utility::OvlVis::visShowOnLinkIcon(), ariba::utility::OvlVis::visShowShiftedNodeIcon(), and ariba::utility::OvlVis::visShutdown().

void ariba::utility::Identifier::trim (  )  [inline, private]

trims key after key operations

Definition at line 671 of file Identifier.cpp.

References array_size, GMP_MSB_MASK, and key.

Referenced by clearAddress(), Identifier(), max(), operator+=(), operator-=(), operator<<(), operator>>(), operator~(), random(), randomPrefix(), randomSuffix(), and sha1().

ariba::utility::Identifier::use_logging_h ( Identifier   )  [private]


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Identifier c 
) [friend]

Common stdc++ console output method

Definition at line 580 of file Identifier.cpp.


Member Data Documentation

const size_t ariba::utility::Identifier::array_size [static, private]

Initial value:

 MAX_KEYLENGTH / (8 * sizeof(mp_limb_t))
                        + (MAX_KEYLENGTH % (8 * sizeof(mp_limb_t)) != 0 ? 1 : 0)

Definition at line 511 of file Identifier.h.

Referenced by clearAddress(), and trim().

uint ariba::utility::Identifier::aSize [static, private]

Initial value:

 Identifier::keyLength / (8 * sizeof(mp_limb_t))
                + (Identifier::keyLength % (8 * sizeof(mp_limb_t)) != 0 ? 1 : 0)
number of needed machine words to hold the key

Definition at line 502 of file Identifier.h.

Referenced by compareTo(), Identifier(), log_2(), max(), operator&(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), operator^(), operator|(), operator~(), random(), randomPrefix(), setKeyLength(), sha1(), sharedPrefixLength(), and toString().

mp_limb_t ariba::utility::Identifier::GMP_MSB_MASK [static, private]

Initial value:

 (Identifier::keyLength % GMP_LIMB_BITS)
                != 0 ? (((mp_limb_t) 1 << (Identifier::keyLength % GMP_LIMB_BITS)) - 1)
                : (mp_limb_t) -1
bits to fill up if key does not exactly fit in one or more machine words

Definition at line 503 of file Identifier.h.

Referenced by setKeyLength(), and trim().

uint ariba::utility::Identifier::keyLength = MAX_KEYLENGTH [static, private]

actual length of the key

Definition at line 501 of file Identifier.h.

Referenced by get(), getLength(), setKeyLength(), sharedPrefixLength(), and toString().

Identifier with key initialized as 1

Definition at line 86 of file Identifier.h.

Referenced by operator++(), and operator--().

Identifier without defined key

Definition at line 84 of file Identifier.h.

Reimplemented from Address.

Definition at line 68 of file Identifier.h.

Identifier with key initialized as 0

Definition at line 85 of file Identifier.h.

Referenced by operator<<(), operator>>(), pow2(), and random().


The documentation for this class was generated from the following files:

Generated on Fri Aug 14 23:39:40 2009 for Ariba by  doxygen 1.5.8