template class Core::HashMap

Overview

Hash map container class. More…

#include <corehashmap.h>

template <class TKey, class TValue>
class HashMap
{
public:
    // typedefs

    typedef KeyValue<TKey, TValue> TAssociation;
    typedef Vector<TAssociation> TList;
    typedef VectorIterator<TAssociation> TIterator;

    typedef int (*HashFunc)(
        const TKey &key,
        int size
        );

    // construction

    HashMap(int size, TValue errorValue);
    HashMap(int size, HashFunc hashFunc = hashInt, TValue errorValue = TValue());
    HashMap(const HashMap& other);

    // methods

    HashMap& operator = (const HashMap& other);
    bool isEmpty() const;
    int count() const;
    void add(const TKey& key, const TValue& value);
    bool remove(const TKey& key);
    bool replaceValue(const TKey& key, const TValue& value);
    void removeAll();
    const TValue& lookup(const TKey& key) const;
    bool get(TValue& value, const TKey& key) const;
    bool contains(const TKey& key) const;
    bool getKey(TKey& key, const TValue& value) const;
    RangeIterator<HashMap<TKey, TValue>, HashMapIterator<TKey, TValue>, TValue> begin() const;
    RangeIterator<HashMap<TKey, TValue>, HashMapIterator<TKey, TValue>, TValue> end() const;
};

Detailed Documentation

Hash map container class.

Typedefs

typedef int (*HashFunc)(
    const TKey &key,
    int size
    )

Hash function type.

Construction

HashMap(int size, TValue errorValue)

Construct with built-in integer hash function.

HashMap(int size, HashFunc hashFunc = hashInt, TValue errorValue = TValue())

Construct with custom hash function.

HashMap(const HashMap& other)

Copy constructor.

Methods

HashMap& operator = (const HashMap& other)

Assign (copy) other hash map.

bool isEmpty() const

Check if container is empty.

int count() const

Count elements in container.

void add(const TKey& key, const TValue& value)

Add key/value pair.

bool remove(const TKey& key)

Remove key.

bool replaceValue(const TKey& key, const TValue& value)

Replace value for key.

void removeAll()

Remove all elements from container.

const TValue& lookup(const TKey& key) const

Look-up value for key.

bool get(TValue& value, const TKey& key) const

Get value for key, returns false if not found.

bool contains(const TKey& key) const

Check if key is contained in map.

bool getKey(TKey& key, const TValue& value) const

Get key for given value (reverse look-up).