X Tutup
The Wayback Machine - https://web.archive.org/web/20230415063819/https://github.com/bas524/ConcurrentHashMap
Skip to content

bas524/ConcurrentHashMap

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

ConcurrentHashMap

ConcurrentHashMap implementation with functional (lambda) signatures. For read-write locks I used std::shared_timed_mutex. C++14 requred.

Example

#include <iostream>
#include <thread>
#include "ConcurrentHashMap.h"

int main() {
  using TestMapType = ConcurrentHashMap<int, std::string>;

  TestMapType concurrentHashMap;

  for (int i = 0; i < 10000; ++i) {
    concurrentHashMap.insert(i, std::to_string(i));
  }
  
  std::cout << " --------------- " << std::endl;

  std::thread thr1([&concurrentHashMap]() { concurrentHashMap.doForEeach([](TestMapType::ValueType &pair) { pair.second.append("+1"); }); });

  std::thread thr2([&concurrentHashMap]() { concurrentHashMap.doForEeach([](TestMapType::ValueType &pair) { pair.second.append("+2"); }); });

  thr1.join();
  thr2.join();

  concurrentHashMap.doForEeach([](const TestMapType::ValueType &pair) { std::cout << pair.first << " [" << pair.second << "]" << std::endl; });

  std::cout << " --------------- " << std::endl;
}

Releases

No releases published

Packages

No packages published
X Tutup