Path: blob/master/thirdparty/embree/common/algorithms/parallel_set.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "parallel_sort.h"67namespace embree8{9/* implementation of a set of values with parallel construction */10template<typename T>11class parallel_set12{13public:1415/*! default constructor for the parallel set */16parallel_set () {}1718/*! construction from vector */19template<typename Vector>20parallel_set (const Vector& in) { init(in); }2122/*! initialized the parallel set from a vector */23template<typename Vector>24void init(const Vector& in)25{26/* copy data to internal vector */27vec.resize(in.size());28parallel_for( size_t(0), in.size(), size_t(4*4096), [&](const range<size_t>& r) {29for (size_t i=r.begin(); i<r.end(); i++)30vec[i] = in[i];31});3233/* sort the data */34std::vector<T> temp(in.size());35radix_sort<T>(vec.data(),temp.data(),vec.size());36}3738/*! tests if some element is in the set */39__forceinline bool lookup(const T& elt) const {40return std::binary_search(vec.begin(), vec.end(), elt);41}4243/*! clears all state */44void clear() {45vec.clear();46}4748private:49std::vector<T> vec; //!< vector containing sorted elements50};51}525354