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.

43 regels
881 B

3 jaren geleden
  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. }
  24. for(int a = v2; a < 250000; a+=thread_cnt) {
  25. if(auto acc = map->get(a); acc) {
  26. const std::string& t = acc.value();
  27. if(t != std::to_string(a))
  28. return 1;
  29. } else
  30. return 1;
  31. }
  32. return 0;
  33. }));
  34. });
  35. for(auto& a : finals) a.wait();
  36. int ret = 0;
  37. for(auto& a : finals) ret += a.get();
  38. return ret;
  39. }