parallel_map.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2009-2020 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include "parallel_map.h"
  4. #include "../sys/regression.h"
  5. namespace embree
  6. {
  7. struct parallel_map_regression_test : public RegressionTest
  8. {
  9. parallel_map_regression_test(const char* name) : RegressionTest(name) {
  10. registerRegressionTest(this);
  11. }
  12. bool run ()
  13. {
  14. bool passed = true;
  15. /* create key/value vectors with random numbers */
  16. const size_t N = 10000;
  17. std::vector<uint32_t> keys(N);
  18. std::vector<uint32_t> vals(N);
  19. for (size_t i=0; i<N; i++) keys[i] = 2*unsigned(i)*647382649;
  20. for (size_t i=0; i<N; i++) std::swap(keys[i],keys[rand()%N]);
  21. for (size_t i=0; i<N; i++) vals[i] = 2*rand();
  22. /* create map */
  23. parallel_map<uint32_t,uint32_t> map;
  24. map.init(keys,vals);
  25. /* check that all keys are properly mapped */
  26. for (size_t i=0; i<N; i++) {
  27. const uint32_t* val = map.lookup(keys[i]);
  28. passed &= val && (*val == vals[i]);
  29. }
  30. /* check that these keys are not in the map */
  31. for (size_t i=0; i<N; i++) {
  32. passed &= !map.lookup(keys[i]+1);
  33. }
  34. return passed;
  35. }
  36. };
  37. parallel_map_regression_test parallel_map_regression("parallel_map_regression_test");
  38. }