Rudiments
Public Member Functions | List of all members
dictionary< keytype, valuetype > Class Template Reference

Inherits dictionarycollection< keytype, valuetype >.

Public Member Functions

 dictionary ()
 
 dictionary (bool trackinsertionorder)
 
 dictionary (dictionary< keytype, valuetype > &a)
 
 dictionary (dictionarycollection< keytype, valuetype > &a)
 
dictionary< keytype, valuetype > & operator= (dictionary< keytype, valuetype > &a)
 
dictionary< keytype, valuetype > & operator= (dictionarycollection< keytype, valuetype > &a)
 
 ~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)
 
valuetype getValue (keytype key)
 
bool getKey (keytype key, keytype *k)
 
keytype getKey (keytype key)
 
linkedlist< keytype > * getKeys ()
 
uint64_t getCount ()
 
bool remove (keytype key)
 
bool clear ()
 
- Public Member Functions inherited from dictionarycollection< keytype, valuetype >
virtual const char * getType ()
 
virtual ssize_t write ()
 
virtual ssize_t write (output *out)
 
virtual ssize_t writeJson ()
 
virtual ssize_t writeJson (bool indent)
 
virtual ssize_t writeJson (output *out)
 
virtual ssize_t writeJson (output *out, bool indent)
 
- Public Member Functions inherited from collection
 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ dictionary() [1/4]

template<class keytype , class valuetype >
dictionary< keytype, valuetype >::dictionary
inline

Creates an empty instance of the dictionary class.

◆ dictionary() [2/4]

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() [3/4]

template<class keytype , class valuetype >
dictionary< keytype, valuetype >::dictionary ( dictionary< keytype, valuetype > &  a)
inline

Creates an instance of the dictionary class that is a copy of "a".

◆ dictionary() [4/4]

template<class keytype , class valuetype >
dictionary< keytype, valuetype >::dictionary ( dictionarycollection< keytype, valuetype > &  a)
inline

Creates an instance of the dictionary class that is a copy of "a".

◆ ~dictionary()

template<class keytype , class valuetype >
dictionary< keytype, valuetype >::~dictionary
inline

Deletes this instance of the dictionary class.

The key stored in each pair is only deleted if setManageKeys(true) or setManageArrayKeys(true) has been called.

The value stored in each pair is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Member Function Documentation

◆ clear()

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::clear
inlinevirtual

Deletes all key-value pairs currently in the dictionary.

The key stored in each pair is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

The key stored in each pair is only deleted if setManageKeys(true) or setManageArrayKeys(true) has been called.

The value stored in each pair is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Always returns true.

Implements collection.

◆ getCount()

template<class keytype , class valuetype >
uint64_t dictionary< keytype, valuetype >::getCount
inlinevirtual

Returns the number of key-value pairs in the dictionary.

Implements collection.

◆ getKey() [1/2]

template<class keytype , class valuetype >
keytype dictionary< keytype, valuetype >::getKey ( keytype  key)
inlinevirtual

Returns the key 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 key of NULL associated with "key".

Implements dictionarycollection< keytype, valuetype >.

◆ getKey() [2/2]

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::getKey ( keytype  key,
keytype *  k 
)
inlinevirtual

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

Implements dictionarycollection< keytype, valuetype >.

◆ getKeys()

template<class keytype , class valuetype >
linkedlist< keytype > * dictionary< keytype, valuetype >::getKeys
inlinevirtual

Returns a list of the keys in the dictionary.

Implements dictionarycollection< keytype, valuetype >.

◆ getTrackInsertionOrder()

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::getTrackInsertionOrder
inlinevirtual

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

If getTrackInsertionOrder() is true then the order of key insertion is tracked and getKeys() returns a list of keys in the order that they were inserted.

If getTrackInsertionOrder() is false then the order of key insertion is not tracked and getKeys() returns a list of keys in ascending order.

Implements dictionarycollection< keytype, valuetype >.

◆ getValue() [1/2]

template<class keytype , class valuetype >
valuetype dictionary< keytype, valuetype >::getValue ( keytype  key)
inlinevirtual

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".

Implements dictionarycollection< keytype, valuetype >.

◆ getValue() [2/2]

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::getValue ( keytype  key,
valuetype *  value 
)
inlinevirtual

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

Implements dictionarycollection< keytype, valuetype >.

◆ operator=() [1/2]

template<class keytype , class valuetype >
dictionary< keytype, valuetype > & dictionary< keytype, valuetype >::operator= ( dictionary< keytype, valuetype > &  a)
inline

Makes this instance of the dictionary class identical to "a".

◆ operator=() [2/2]

template<class keytype , class valuetype >
dictionary< keytype, valuetype > & dictionary< keytype, valuetype >::operator= ( dictionarycollection< keytype, valuetype > &  a)
inline

Makes this instance of the dictionary class identical to "a".

◆ remove()

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::remove ( keytype  key)
inlinevirtual

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

The key stored in the pair is only deleted if setManageKeys(true) or setManageArrayKeys(true) has been called.

The value stored in the pair is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Implements dictionarycollection< keytype, valuetype >.

◆ setTrackInsertionOrder()

template<class keytype , class valuetype >
bool dictionary< keytype, valuetype >::setTrackInsertionOrder ( bool  trackinsertionorder)
inline

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() returns a list of keys in the order that they were inserted.

If "trackinsertionorder" is false then the order of key insertion is not tracked and getKeys() returns a list of keys in ascending order.

Defaults to "true".

Note, this can only be changed when there are no key-value pairs 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 key-value pairs).

◆ setValue()

template<class keytype , class valuetype >
void dictionary< keytype, valuetype >::setValue ( keytype  key,
valuetype  value 
)
inlinevirtual

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

Implements dictionarycollection< keytype, valuetype >.

◆ setValues() [1/5]

template<class keytype , class valuetype >
void dictionary< keytype, valuetype >::setValues ( dictionary< keytype, valuetype > *  dict)
inline

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/5]

template<class keytype , class valuetype >
void dictionary< keytype, valuetype >::setValues ( keytype *  keys,
valuetype *  values 
)
inlinevirtual

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".

Implements dictionarycollection< keytype, valuetype >.

◆ setValues() [3/5]

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

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".

Implements dictionarycollection< keytype, valuetype >.

◆ setValues() [4/5]

template<class keytype , class valuetype >
void dictionary< keytype, valuetype >::setValues ( keytype const *  keys,
valuetype const *  values 
)
inlinevirtual

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".

Implements dictionarycollection< keytype, valuetype >.

◆ setValues() [5/5]

template<class keytype , class valuetype >
void dictionary< keytype, valuetype >::setValues ( keytype const *  keys,
valuetype const *  values,
uint64_t  count 
)
inlinevirtual

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".

Implements dictionarycollection< keytype, valuetype >.