Rudiments
|
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 | remove (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 () |
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.
dictionary< keytype, valuetype >::dictionary | ( | ) |
Creates an empty instance of the dictionary class.
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.
|
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.
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.
void dictionary< keytype, valuetype >::clearAndArrayDelete | ( | ) |
Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well, which is both presumed to be arrays.
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.
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.
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.
void dictionary< keytype, valuetype >::clearAndDelete | ( | ) |
Deletes all dictionarynodes currently in the dictionary, deleting the key and value stored in each dictionarynode as well.
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.
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.
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.
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.
linkedlist< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getList | ( | ) |
Returns the list used internally.
dictionarynode<keytype,valuetype>* dictionary< keytype, valuetype >::getNode | ( | keytype | key | ) |
Returns the node associated with "key" or NULL if "key" wasn't found.
bool dictionary< keytype, valuetype >::getTrackInsertionOrder | ( | ) |
Returns "true" if insertion order tracking is enabled and false otherwise.
avltree< dictionarynode<keytype,valuetype> *>* dictionary< keytype, valuetype >::getTree | ( | ) |
Returns the tree used internally.
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.
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".
void dictionary< keytype, valuetype >::print | ( | ) |
Prints out a representation of the dictionary.
bool dictionary< keytype, valuetype >::remove | ( | keytype | key | ) |
Removes the dictionarynode associated with "key". Returns true on success or false if "key" wasn't found.
bool dictionary< keytype, valuetype >::remove | ( | dictionarynode< keytype, valuetype > * | node | ) |
Removes the specified dictionarynode. Returns true on success or false if "node" was NULL.
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).
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".
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".
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".
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".