![]() |
http://www.sim.no http://www.coin3d.org |
The SbDict class organizes a dictionary of keys and values.It uses hashing to quickly insert and find entries in the dictionary. An entry consists of an unique key and a generic pointer. More...
#include <Inventor/SbDict.h>
Public Types | |
typedef unsigned long | Key |
Public Member Functions | |
SbDict (const int entries=251) | |
SbDict (const SbDict &from) | |
~SbDict () | |
SbDict & | operator= (const SbDict &from) |
void | applyToAll (void(*rtn)(Key key, void *value)) const |
void | applyToAll (void(*rtn)(Key key, void *value, void *data), void *data) const |
void | clear (void) |
SbBool | enter (const Key key, void *const value) |
SbBool | find (const Key key, void *&value) const |
void | makePList (SbPList &keys, SbPList &values) |
SbBool | remove (const Key key) |
void | setHashingFunction (Key(*func)(const Key key)) |
The SbDict class organizes a dictionary of keys and values.
It uses hashing to quickly insert and find entries in the dictionary. An entry consists of an unique key and a generic pointer.
SbDict::SbDict | ( | const int | entries = 251 | ) |
Constructor with entries specifying the initial number of buckets in the hash list -- so it need to be larger than 0. Other than this, no special care needs to be taken in choosing the value since it is always rounded up to the nearest power of two.
SbDict::SbDict | ( | const SbDict & | from | ) |
Copy constructor.
References operator=().
SbDict::~SbDict | ( | ) |
Destructor.
Make a shallow copy of the contents of dictionary from into this dictionary.
References applyToAll(), and clear().
Referenced by SbDict().
void SbDict::applyToAll | ( | void(*)(Key key, void *value) | rtn | ) | const |
Applies rtn to all entries in the dictionary.
Referenced by operator=().
void SbDict::applyToAll | ( | void(*)(Key key, void *value, void *data) | rtn, |
void * | data | ||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void SbDict::clear | ( | void | ) |
Clear all entries in the dictionary.
Referenced by operator=().
SbBool SbDict::enter | ( | const Key | key, |
void *const | value | ||
) |
Inserts a new entry into the dictionary. key should be a unique number, and value is the generic user data.
If key does not exist in the dictionary, a new entry is created and TRUE
is returned. Otherwise, the generic user data is changed to value, and FALSE
is returned.
SbBool SbDict::find | ( | const Key | key, |
void *& | value | ||
) | const |
Searches for key in the dictionary. If an entry with this key exists, TRUE
is returned and the entry value is returned in value. Otherwise, FALSE
is returned.
Creates lists with all entries in the dictionary.
SbBool SbDict::remove | ( | const Key | key | ) |
Removes the entry with key key. TRUE
is returned if an entry with this key was present, FALSE
otherwise.
void SbDict::setHashingFunction | ( | Key(*)(const Key key) | func | ) |
Sets a new hashing function for this dictionary. Default hashing function just returns the key.
If you find that items entered into the dictionary seems to make clusters in only a few buckets, you should try setting a hashing function. If you're for instance using strings, you could use the static SbString::hash() function (you'd need to make a static function that will cast from SbDict::Key to char * of course).
This function is not part of the OIV API.
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Mon Feb 28 2011 10:12:01 for Coin by Doxygen. 1.7.3