Tools made in assistance of the Metacall Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 rivejä
828 B

  1. #include "lfhmap.hpp"
  2. #include <string>
  3. #include <iostream>
  4. #include <future>
  5. #include <vector>
  6. template<typename fn>
  7. void repeat(size_t nb, fn v) {
  8. while(nb--) {
  9. v();
  10. }
  11. }
  12. int main() {
  13. constexpr size_t thread_cnt = 16;
  14. size_t v = 0;
  15. auto map = new mct20::lfhmap<size_t, std::string, 80000>();
  16. std::vector<std::future<int>> finals;
  17. repeat(thread_cnt, [&](){
  18. size_t v2 = v;
  19. v++;
  20. finals.push_back(std::async(std::launch::async, [&map, v2](){
  21. for(int a = v2; a < 250000; a+=thread_cnt) {
  22. map->set(a, std::to_string(a));
  23. if(auto acc = map->get(a); acc) {
  24. const std::string& t = acc.value();
  25. if(t != std::to_string(a))
  26. return 1;
  27. } else
  28. return 1;
  29. }
  30. return 0;
  31. }));
  32. });
  33. for(auto& a : finals) a.wait();
  34. int ret = 0;
  35. for(auto& a : finals) ret += a.get();
  36. return ret;
  37. }