1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "parallel_sort.h"
7
8namespace embree
9{
10 /* implementation of a set of values with parallel construction */
11 template<typename T>
12 class parallel_set
13 {
14 public:
15
16 /*! default constructor for the parallel set */
17 parallel_set () {}
18
19 /*! construction from vector */
20 template<typename Vector>
21 parallel_set (const Vector& in) { init(in); }
22
23 /*! initialized the parallel set from a vector */
24 template<typename Vector>
25 void init(const Vector& in)
26 {
27 /* copy data to internal vector */
28 vec.resize(in.size());
29 parallel_for( size_t(0), in.size(), size_t(4*4096), [&](const range<size_t>& r) {
30 for (size_t i=r.begin(); i<r.end(); i++)
31 vec[i] = in[i];
32 });
33
34 /* sort the data */
35 std::vector<T> temp(in.size());
36 radix_sort<T>(vec.data(),temp.data(),vec.size());
37 }
38
39 /*! tests if some element is in the set */
40 __forceinline bool lookup(const T& elt) const {
41 return std::binary_search(vec.begin(), vec.end(), elt);
42 }
43
44 /*! clears all state */
45 void clear() {
46 vec.clear();
47 }
48
49 private:
50 std::vector<T> vec; //!< vector containing sorted elements
51 };
52}
53