Skip to content

TheProgrammingArchive/hash-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

hash-table

Hash Table (seperate chaining)

Note :
To use the table for custom class definitions you must inject your custom class into the std::hash definition, here's an example

class Foo{
    public:
    std::string bar;
    
    Foo(const std::string& str){
        this->bar = str;
    }
};

template <>
struct std::hash<Foo>{
    std::size_t operator()(const Foo& foo) const{
        return std::hash<std::string>{}(foo.bar);
    }
};

Usage:

HashTable<std::string, int> table = {{"A", 1}, {"B", 3}};
table.update({"C", 5});
table.update({"A", 0});
table.remove("A");

for (const std::string& key : table.get_keys()){
    std::cout << key << " : " << table.get(key) << '\n';
}

About

unordered map using hash table (separate chaining)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages