dictionary< keytype, valuetype > Class Template Reference

## Public Member Functions

| dictionary ()
| dictionary (bool trackinsertionorder)
virtual | ~dictionary ()
bool | setTrackInsertionOrder (bool trackinsertionorder)
bool | getTrackInsertionOrder ()
void | setValue (keytype key, valuetype value)
void | setValues (keytype *keys, valuetype *values)
void | setValues (keytype const *keys, valuetype const *values)
void | setValues (keytype *keys, valuetype *values, uint64_t count)
void | setValues (keytype const *keys, valuetype const *values, uint64_t count)
void | setValues (dictionary< keytype, valuetype > *dict)
bool | getValue (keytype key, valuetype *value)
dictionarynode< keytype, valuetype > * | getNode (keytype key)
valuetype | getValue (keytype key)
bool | remove (keytype key)
bool | removeAndDelete (keytype key)
bool | removeAndArrayDelete (keytype key)
bool | removeAndDeleteKey (keytype key)
bool | removeAndArrayDeleteKey (keytype key)
bool | removeAndDeleteValue (keytype key)
bool | removeAndArrayDeleteValue (keytype key)
bool | removeAndDeleteKeyAndArrayDeleteValue (keytype key)
bool | removeAndArrayDeleteKeyAndDeleteValue (keytype key)
bool | remove (dictionarynode< keytype, valuetype > *node)
bool | removeAndDelete (dictionarynode< keytype, valuetype > *node)
bool | removeAndArrayDelete (dictionarynode< keytype, valuetype > *node)
bool | removeAndDeleteKey (dictionarynode< keytype, valuetype > *node)
bool | removeAndArrayDeleteKey (dictionarynode< keytype, valuetype > *node)
bool | removeAndDeleteValue (dictionarynode< keytype, valuetype > *node)
bool | removeAndArrayDeleteValue (dictionarynode< keytype, valuetype > *node)
bool | removeAndDeleteKeyAndArrayDeleteValue (dictionarynode< keytype, valuetype > *node)
bool | removeAndArrayDeleteKeyAndDeleteValue (dictionarynode< keytype, valuetype > *node)
linkedlist< keytype > * | getKeys ()
avltree< dictionarynode< keytype, valuetype > * > * | getTree ()
linkedlist< dictionarynode< keytype, valuetype > * > * | getList ()
void | clear ()
void | clearAndDelete ()
void | clearAndArrayDelete ()
void | clearAndDeleteKeys ()
void | clearAndArrayDeleteKeys ()
void | clearAndDeleteValues ()
void | clearAndArrayDeleteValues ()
void | clearAndDeleteKeysAndArrayDeleteValues ()
void | clearAndArrayDeleteKeysAndDeleteValues ()
void | print ()

## Detailed Description

### template<class keytype, class valuetype>
class dictionary< keytype, valuetype >

The dictionary class allows you to store arbitrary numbers of key/value pairs.

Each dictionary is composed of a set of dictionarynodes. Each dictionarynode contains the key and value.

Internally, the dictionary class uses a linkedlist to store the values though this is potentially inefficient though, and may change in a future version.

## Constructor & Destructor Documentation

## dictionary() [1/2]

template<class keytype , class valuetype >

dictionary< keytype, valuetype >::dictionary | ( |  | ) |

Creates an empty instance of the dictionary class.

## dictionary() [2/2]

template<class keytype , class valuetype >

dictionary< keytype, valuetype >::dictionary | ( | bool | trackinsertionorder | ) |

Creates an empty instance of the dictionary class.

If "trackinsertionorder" is true then the order of key insertion is tracked and getKeys() and getList() below return a list of key-value pairs in the order that they were inserted.

If "trackinsertionorder" is false then the order of key insertion is not tracked and getList() and getList() below return alist of key-value pairs in ascending order.

## ~dictionary()

template<class keytype , class valuetype >

virtual dictionary< keytype, valuetype >::~dictionary | ( |  | ) |

virtual

Deletes this instance of the dictionary class and all of its dictionarynodes. Note however, that neither the key nor value stored in each dictionarynode are deleted by this call.

## Member Function Documentation

## clear()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clear | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary. Note however, that the key and value stored in each dictionarynode is not deleted by this call.

## clearAndArrayDelete()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndArrayDelete | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well, which are both presumed to be arrays.

## clearAndArrayDeleteKeys()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndArrayDeleteKeys | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key (but not the value) stored in each dictionarynode as well, which is presumed to be an array.

## clearAndArrayDeleteKeysAndDeleteValues()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndArrayDeleteKeysAndDeleteValues | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well. Each key is presumed to be an array.

## clearAndArrayDeleteValues()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndArrayDeleteValues | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the value (but not the key) stored in each dictionarynode as well, which is presumed to be an array.

## clearAndDelete()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndDelete | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well.

## clearAndDeleteKeys()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndDeleteKeys | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key (but not the value) stored in each dictionarynode as well.

## clearAndDeleteKeysAndArrayDeleteValues()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndDeleteKeysAndArrayDeleteValues | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well. Each value is presumed to be an array.

## clearAndDeleteValues()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::clearAndDeleteValues | ( |  | ) |

Deletes all dictionarynodes currently in the dictionary, deleting the value (but not the key) stored in each dictionarynode as well.

## getKeys()

template<class keytype , class valuetype >

linkedlist<keytype>* dictionary< keytype, valuetype >::getKeys | ( |  | ) |

Returns a list of the keys in the dictionary.

Note that the linkedlist returned is allocated internally and returned. The calling program must delete the linkedlist.

## getList()

template<class keytype , class valuetype >

linkedlist< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getList | ( |  | ) |

Returns the list used internally.

## getNode()

template<class keytype , class valuetype >

dictionarynode<keytype,valuetype>* dictionary< keytype, valuetype >::getNode | ( | keytype | key | ) |

Returns the node associated with "key" or NULL if "key" wasn't found.

## getTrackInsertionOrder()

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::getTrackInsertionOrder | ( |  | ) |

Returns "true" if insertion order tracking is enabled and false otherwise.

## getTree()

template<class keytype , class valuetype >

avltree< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getTree | ( |  | ) |

Returns the tree used internally.

## getValue() [1/2]

template<class keytype , class valuetype >

valuetype dictionary< keytype, valuetype >::getValue | ( | keytype | key | ) |

Returns the value associated with "key" or NULL if "key" wasn't found. Note that there is no way to distinguish between failure to find "key" and a valid value of NULL associated with "key".

## getValue() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::getValue | ( | keytype | key,
|  | valuetype * | value
| ) |  |

Sets "value" to the value associated with "key". Returns true on success or false if "key" wasn't found.

## print()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::print | ( |  | ) |

Prints out a representation of the dictionary.

## remove() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::remove | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode. Returns true on success or false if "node" was NULL.

## remove() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::remove | ( | keytype | key | ) |

Removes the dictionarynode associated with "key". Returns true on success or false if "key" wasn't found.

## removeAndArrayDelete() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDelete | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the key and value stored in the dictionarynode as well, which are both presumed to be arrays. Returns true on success or false if "key" wasn't found.

## removeAndArrayDelete() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDelete | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the key and value stored in the dictionarynode as well, which are both presumed to be arrays. Returns true on success or false if "key" wasn't found.

## removeAndArrayDeleteKey() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteKey | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the key stored in the dictionarynode as well, which is presumed to be an array. Returns true on success or false if "key" wasn't found.

## removeAndArrayDeleteKey() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteKey | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the key stored in the dictionarynode as well, which is presumed to be an array. Returns true on success or false if "key" wasn't found.

## removeAndArrayDeleteKeyAndDeleteValue() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteKeyAndDeleteValue | ( | dictionarynode< keytype, valuetype > * | node | ) |

Deletes the specified dictionarynode, deleting the key and value stored in the dictionarynode as well. The key is presumed to be an array.

## removeAndArrayDeleteKeyAndDeleteValue() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteKeyAndDeleteValue | ( | keytype | key | ) |

Deletes the dictionarynodes associated with "key", deleting the key and value stored in the dictionarynode as well. The key is presumed to be an array.

## removeAndArrayDeleteValue() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteValue | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the value stored in the dictionarynode as well, which is presumed to be an array. Returns true on success or false if "key" wasn't found.

## removeAndArrayDeleteValue() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndArrayDeleteValue | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the value stored in the dictionarynode as well, which is presumed to be an array. Returns true on success or false if "key" wasn't found.

## removeAndDelete() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDelete | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the key and value stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## removeAndDelete() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDelete | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the key and value stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## removeAndDeleteKey() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteKey | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the key stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## removeAndDeleteKey() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteKey | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the key stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## removeAndDeleteKeyAndArrayDeleteValue() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteKeyAndArrayDeleteValue | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the key and value stored in the dictionarynode as well. The value is presumed to be an array.

## removeAndDeleteKeyAndArrayDeleteValue() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteKeyAndArrayDeleteValue | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the key and value stored in the dictionarynode as well. The value is presumed to be an array.

## removeAndDeleteValue() [1/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteValue | ( | dictionarynode< keytype, valuetype > * | node | ) |

Removes the specified dictionarynode, deleting the value stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## removeAndDeleteValue() [2/2]

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::removeAndDeleteValue | ( | keytype | key | ) |

Removes the dictionarynode associated with "key", deleting the value stored in the dictionarynode as well. Returns true on success or false if "key" wasn't found.

## setTrackInsertionOrder()

template<class keytype , class valuetype >

bool dictionary< keytype, valuetype >::setTrackInsertionOrder | ( | bool | trackinsertionorder | ) |

Sets whether tracking of the order of key insertion is enabled or not.

If "trackinsertionorder" is true then the order of key insertion is tracked and getKeys() and getList() below return a list of key-value pairs in the order that they were inserted.

If "trackinsertionorder" is false then the order of key insertion is not tracked and getList() and getList() below return alist of key-value pairs in ascending order.

Defaults to "true".

Note, this can only be changed when there are no nodes in the dictionary. Eg. before the first call to setValue() or after a call to clear().

Returns true if the call succeeded and false if it failed (eg. because the dictionary contained nodes).

## setValue()

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::setValue | ( | keytype | key,
|  | valuetype | value
| ) |  |

Sets the value associated with "key" to "value". If "key" already exists, the value currently accociated with it is replaced with "value".

## setValues() [1/3]

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::setValues | ( | dictionary< keytype, valuetype > * | dict | ) |

Sets the value associated with each key in "dict" to the corresponding value from "dict". If "key" already exists, the value currently accociated with it is replaced with "value".

## setValues() [2/3]

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::setValues | ( | keytype * | keys,
|  | valuetype * | values
| ) |  |

Sets the value associated with each key in the "keys" array to the corresponding value in the "values" array. Assumes that keys is NULL terminated. If "key" already exists, the value currently accociated with it is replaced with "value".

## setValues() [3/3]

template<class keytype , class valuetype >

void dictionary< keytype, valuetype >::setValues | ( | keytype * | keys,
|  | valuetype * | values,
|  | uint64_t | count
| ) |  |

Sets the value associated with each of "count" keys in the "keys" array to the corresponding value in the "values" array. If "key" already exists, the value currently accociated with it is replaced with "value".