Skip to content
Ned Bingham edited this page Mar 23, 2017 · 2 revisions

std/hash_map.h


template <class key_type, class value_type, uint32_t (*hash_func)(const char *,int,uint32_t)>
struct hash_map : hash_set<implier<key_type, value_type>, hash_func>

This structure implements a mapping from keys to values accessible in constant time using hashes. In this structure, multiple values can be mapped to the same key.

Member Functions

hash_map()

The default constructor, calls the default constructor of hash_set.

value_type &operator[](const key_type &key)

Finds the value mapped to the given key and returns it. If there isn't one, a value is inserted with the given key using the default constructor.

iterator insert(const key_type &key, const value_type &value)

Places a key-value implier into the map bucketed by the hash of the key.

iterator find(const key_type &key)
const_iterator find(const key_type &key)

Returns an iterator to the first implier with the given key.

bool contains(const key_type &key)

checks to see if this map contains an implier with the given key

Examples

#include <std/ascii_stream.h>
#include <std/hash_map.h>

using namespace core;

int main()
{
    hash_map<int, int> m;
    m.insert(5, 3);
    m.insert(3, 10);
    m.insert(8, 2);
    cout << m << endl;
    return 0;
}
{5: 3, 3: 10, 8: 2}

Simple Containers

Standard Containers

Interface Containers

Specialized Containers

Input/Output

Algorithm

Clone this wiki locally