#include <MAUtil/Dictionary.h>
The Dictionary is a data storage mechanism that stores unique values. The Dictionary is sorted, by a method selectable by the user. It has fairly fast insert, erase and lookup operations. (O(log n), specifically.) It has an Iterator, which allows you to access all elements in order.
This particular implementation is built on top of kazlib's dictionary system, which makes it quite small, even when used with multiple data types.
This class is not meant to be instantiated directly. It is the base class for Set and Map.
Public Types | |
typedef int(* | CompareFunction )(const Key &, const Key &) |
Public Member Functions | |
Dictionary (const Dictionary &) | |
Constructs a copy of another Dictionary. All elements are also copied. | |
Dictionary & | operator= (const Dictionary &) |
Clears this Dictionary, then copies the other Dictionary to this one. | |
~Dictionary () | |
The destructor deletes all elements. | |
Iterator | find (const Key &) |
ConstIterator | find (const Key &) const |
bool | erase (const Key &) |
void | erase (Iterator) |
Iterator | begin () |
ConstIterator | begin () const |
Iterator | end () |
ConstIterator | end () const |
size_t | size () const |
void | clear () |
Protected Member Functions | |
void | init (CompareFunction) |
Dictionary (CompareFunction cf, int keyOffset) | |
Constructs an empty Dictionary. | |
Pair< Iterator, bool > | insert (const Storage &) |
Static Protected Member Functions | |
static dnode_t * | alloc (void *) |
static void | free (dnode_t *node, void *) |
Protected Attributes | |
dict_t | mDict |
int | mKeyOffset |
Classes | |
class | ConstIterator |
class | Iterator |
struct | DictNode |
|
|
|
Constructs a copy of another Dictionary. All elements are also copied.
|
|
The destructor deletes all elements.
|
|
Constructs an empty Dictionary.
|
|
Clears this Dictionary, then copies the other Dictionary to this one.
|
|
Searches the Dictionary for a specified Key. The returned Iterator points to the element matching the Key if one was found, or to Dictionary::end() if not. |
|
|
|
Deletes an element, matching the specified Key, from the Dictionary. Returns true if an element was erased, or false if there was no element matching the Key. |
|
Deletes an element, pointed to by the specified Iterator. The Iterator is invalidated, so if you want to continue iterating through the Dictionary, you must use a different Iterator instance.
|
|
Returns an Iterator pointing to the first element in the Dictionary. |
|
|
|
Returns an Iterator pointing to a place beyond the last element of the Dictionary. This Iterator is often used to determine when another Iterator has reached its end. |
|
|
|
Returns the number of elements in the Dictionary. |
|
Deletes all elements. |
|
|
|
|
|
|
|
Inserts a new value into the Dictionary. Returns a Pair. The Pair's second element is true if the value was indeed inserted. The Pair's first element is an Iterator that points to the element in the Dictionary. An element which compares equal to the new one may already be present in the Dictionary; in that case, this operation does nothing, and the Iterator returned will point to the old element. Reimplemented in MAUtil::Set< Key >. |
|
|
|
|