This section is a reference guide to classes/interfaces built by API on top of Associative Array abstract data type:
Advantages and disadvantages of each data structure as Associative Array implementation are described in great detail by this section. Please review it carefully in order to decide which solution suits your business needs!
To see how can above classes be iterated, please review iterators section. To see a real life example how can above classes be used, please have a look at unit tests.
Interface that defines operations one can perform on an Associative Array abstract data type
template <typename K, typename V>
class Map
| Method | Signature | Description |
| ~Map | virtual ~Map () | Deletes elements inside from heap memory |
| operator[] | virtual const VALUE& operator[] (const KEY& index) = 0 | Gets value in associative array by key |
| clear | virtual void clear () = 0 | Clears associative array of all elements |
| containsKey | virtual bool containsKey (const K&) const = 0 | Checks if associative array contains key |
| containsValue | virtual bool containsValue (const V&) const = 0 | Checks if associative array contains value |
| isEmpty | virtual bool isEmpty () const = 0 | Checks if associative array is empty |
| size | virtual const std::size_t& size () const = 0 | Gets associative array size |
| get | virtual const V& get (const K&) const = 0 | Gets value in associative array by key |
| set | virtual void set (const K&, const V&) = 0 | Sets value in associative array by key |
| removeKey | virtual void removeKey (const K&) = 0 | Removes element from associative array by key |
| removeValue | virtual void removeValue (const V&) = 0 | Removes element from associative array by value |
| begin | virtual MapIterator<K,V>* begin () = 0 | Returns an iterator to the first element of map |
| end | virtual MapIterator<K,V>* end () = 0 | Returns an iterator to the element following last element of map |
Class that implements Hash Table data structure on top of Associative Array abstract data type
template <typename K, typename V, int (*compareByKey)(const K&, const K&) = comparator<K>, std::size_t (*hash)(const K&) = hash<K>, int (*compareByValue)(const V&, const V&) = comparator<V>>
class HashMap : public Map<K,V>
| Method | Signature | Description |
| HashMap | HashMap () | Constructs a Hash Table of unknown initial size |
| HashMap | HashMap (const std::size_t& reservedSize) | Constructs a Hash Table of known size |
Class that implements Linked Hash Table data structure on top of Associative Array abstract data type
template <typename K, typename V, int (*compareByKey)(const K&, const K&) = comparator<K>, std::size_t (*hash)(const K&) = hash<K>, int (*compareByValue)(const V&, const V&) = comparator<V>>
class LinkedHashMap : public Map<K,V>
| Method | Signature | Description |
| LinkedHashMap | LinkedHashMap () | Constructs a Linked Hash Table of unknown initial size |
| LinkedHashMap | LinkedHashMap (const std::size_t& reservedSize) | Constructs a Linked Hash Table of known size |
| sortByKey | void sortByKey (bool (*comparator) (const K&, const K&)) | Sorts elements inside by key comparator |
| sortByValue | void sortByValue (bool (*comparator) (const V&, const V&)) | Sorts elements inside by value comparator |
Class that implements Red Black Tree data structure on top of Associative Array abstract data type
template <typename K, typename V, int (*compareByKey)(const K&, const K&) = comparator<K>, int (*compareByValue)(const V&, const V&) = comparator<V>>
class TreeMap : public Map<K,V>
| Method | Signature | Description |
| TreeMap | TreeMap () | Constructs a Red Black Tree of unknown initial size |
Struct that defines the key/value pair that typifies Associative Array entries
template <typename K, typename V>
struct MapEntry
| Name | Type | Description |
| key | K | Associative array key |
| value | V | Associative array value |