• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Basic HashMap (Hash Table) Implementation in C++

HashMap Build Status Coverage Status

Basic Hash Map Implementation in C++

Usage

Example

Define a hash function by overloading operator() for integer typed key

struct MyKeyHash {
	unsigned long operator()(const int& key) const
	{
		return key % 10;
    	}
};

Declare a hash map with integer typed key and string type value pair

size_t tableSize = 10;
HashMap<int, string, tableSize, MyKeyHash> hmap;

Put a key-value pair into the hashmap

hmap.put(1, "1");

Get the value by key; returns true if successful with value updated

string value;
bool result = hmap.get(2, value);

Build

This is a header only library, so no compile step is required. To use the functionality below however, you must use cmake to generate the makefiles.

mkdir build
cd build
cmake ..

Install

make install

(Optional) You can also create packages in the build directory. See cpack for details, here is an example for ubuntu.

cpack -G DEB
sudo dpkg -i *.deb

Test

From build directory, run tests:

make test

You can also check the test coverage:

make coverage

License

Licensed under the Apache 2.0 license.