parallel_map.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "parallel_map.h"
  17. #include "../sys/regression.h"
  18. namespace embree
  19. {
  20. struct parallel_map_regression_test : public RegressionTest
  21. {
  22. parallel_map_regression_test(const char* name) : RegressionTest(name) {
  23. registerRegressionTest(this);
  24. }
  25. bool run ()
  26. {
  27. bool passed = true;
  28. /* create key/value vectors with random numbers */
  29. const size_t N = 10000;
  30. std::vector<uint32_t> keys(N);
  31. std::vector<uint32_t> vals(N);
  32. for (size_t i=0; i<N; i++) keys[i] = 2*unsigned(i)*647382649;
  33. for (size_t i=0; i<N; i++) std::swap(keys[i],keys[rand()%N]);
  34. for (size_t i=0; i<N; i++) vals[i] = 2*rand();
  35. /* create map */
  36. parallel_map<uint32_t,uint32_t> map;
  37. map.init(keys,vals);
  38. /* check that all keys are properly mapped */
  39. for (size_t i=0; i<N; i++) {
  40. const uint32_t* val = map.lookup(keys[i]);
  41. passed &= val && (*val == vals[i]);
  42. }
  43. /* check that these keys are not in the map */
  44. for (size_t i=0; i<N; i++) {
  45. passed &= !map.lookup(keys[i]+1);
  46. }
  47. return passed;
  48. }
  49. };
  50. parallel_map_regression_test parallel_map_regression("parallel_map_regression_test");
  51. }