21 #ifndef __TBB_concurrent_priority_queue_H 22 #define __TBB_concurrent_priority_queue_H 33 #include __TBB_STD_SWAP_HEADER 35 #if __TBB_INITIALIZER_LISTS_PRESENT 36 #include <initializer_list> 39 #if __TBB_CPP11_IS_COPY_CONSTRUCTIBLE_PRESENT 40 #include <type_traits> 44 namespace interface5 {
46 #if __TBB_CPP11_IS_COPY_CONSTRUCTIBLE_PRESENT 48 struct use_element_copy_constructor {
52 struct use_element_copy_constructor <T,false> {
66 template <
typename T,
typename Compare=std::less<T>,
typename A=cache_aligned_allocator<T> >
90 my_aggregator.initialize_handler(my_functor_t(
this));
95 mark(0), my_size(0),
data(a)
97 data.reserve(init_capacity);
98 my_aggregator.initialize_handler(my_functor_t(
this));
102 template<
typename InputIterator>
104 mark(0),
data(begin, end, a)
106 my_aggregator.initialize_handler(my_functor_t(
this));
108 my_size =
data.size();
111 #if __TBB_INITIALIZER_LISTS_PRESENT 114 mark(0),
data(init_list.begin(), init_list.end(), a)
116 my_aggregator.initialize_handler(my_functor_t(
this));
118 my_size =
data.size();
120 #endif //# __TBB_INITIALIZER_LISTS_PRESENT 125 my_size(src.my_size),
data(src.
data.begin(), src.
data.end(), src.
data.get_allocator())
127 my_aggregator.initialize_handler(my_functor_t(
this));
134 my_size(src.my_size),
data(src.
data.begin(), src.
data.end(), a)
136 my_aggregator.initialize_handler(my_functor_t(
this));
151 #if __TBB_CPP11_RVALUE_REF_PRESENT 157 my_aggregator.initialize_handler(my_functor_t(
this));
163 my_size(src.my_size),
172 my_aggregator.initialize_handler(my_functor_t(
this));
173 #if !__TBB_ALLOCATOR_TRAITS_PRESENT 174 if (a != src.data.get_allocator()){
175 data.reserve(src.data.size());
176 data.assign(std::make_move_iterator(src.data.begin()), std::make_move_iterator(src.data.end()));
188 my_size = src.my_size;
189 #if !__TBB_ALLOCATOR_TRAITS_PRESENT 190 if (
data.get_allocator() != src.data.get_allocator()){
191 vector_t(std::make_move_iterator(src.data.begin()), std::make_move_iterator(src.data.end()),
data.get_allocator()).
swap(
data);
200 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 203 template<
typename InputIterator>
204 void assign(InputIterator begin, InputIterator end) {
207 my_size =
data.size();
211 #if __TBB_INITIALIZER_LISTS_PRESENT 212 void assign(std::initializer_list<T> il) { this->assign(il.begin(), il.end()); }
217 this->assign(il.begin(), il.end());
220 #endif //# __TBB_INITIALIZER_LISTS_PRESENT 234 void push(const_reference elem) {
235 #if __TBB_CPP11_IS_COPY_CONSTRUCTIBLE_PRESENT 238 cpq_operation op_data(elem, PUSH_OP);
239 my_aggregator.execute(&op_data);
240 if (op_data.status ==
FAILED)
244 #if __TBB_CPP11_RVALUE_REF_PRESENT 248 cpq_operation op_data(elem, PUSH_RVALUE_OP);
249 my_aggregator.execute(&op_data);
250 if (op_data.status ==
FAILED)
254 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 257 template<
typename... Args>
259 push(value_type(std::forward<Args>(args)...));
269 cpq_operation op_data(POP_OP);
270 op_data.elem = &elem;
271 my_aggregator.execute(&op_data);
309 type(t), elem(const_cast<value_type*>(&e)) {}
351 typedef std::vector<value_type, allocator_type>
vector_t;
355 cpq_operation *tmp, *pop_list=NULL;
372 if (tmp->type == POP_OP) {
373 if (mark < data.size() &&
374 compare(data[0], data[data.size()-1])) {
388 __TBB_ASSERT(tmp->type == PUSH_OP || tmp->type == PUSH_RVALUE_OP,
"Unknown operation" );
390 if (tmp->type == PUSH_OP) {
413 if (mark < data.size() &&
414 compare(data[0], data[data.size()-1])) {
433 if (mark<data.size()) heapify();
439 if (!mark && data.size()>0) mark = 1;
440 for (; mark<data.size(); ++mark) {
442 size_type cur_pos = mark;
445 size_type
parent = (cur_pos-1)>>1;
446 if (!compare(data[parent], to_place))
break;
457 size_type cur_pos=0, child=1;
459 while (child < mark) {
460 size_type target = child;
461 if (child+1 < mark && compare(data[child], data[child+1]))
464 if (compare(data[target], data[data.size()-1]))
break;
467 child = (cur_pos<<1)+1;
469 if (cur_pos != data.size()-1)
472 if (mark > data.size()) mark = data.size();
480 __TBB_ASSERT(
false,
"The type is not copy constructible. Copying push operation is impossible." );
484 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT 486 template<
typename InputIterator,
487 typename T =
typename std::iterator_traits<InputIterator>::value_type,
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
T itt_hide_load_word(const T &src)
tbb::internal::aggregator< my_functor_t, cpq_operation > aggregator_t
std::vector< value_type, allocator_type > vector_t
Storage for the heap of elements in queue, plus unheapified elements.
concurrent_priority_queue(concurrent_priority_queue &&src)
Move constructor.
#define __TBB_ALLOCATOR_TRAITS_PRESENT
A allocator_type
Allocator type.
cpq_operation(const_reference e, operation_type t)
void heapify()
Merge unsorted elements into heap.
T __TBB_load_with_acquire(const volatile T &location)
#define __TBB_STATIC_ASSERT(condition, msg)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
void itt_store_word_with_release(tbb::atomic< T > &dst, U src)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
concurrent_priority_queue(concurrent_priority_queue &&src, const allocator_type &a)
Move constructor with specific allocator.
concurrent_priority_queue & operator=(std::initializer_list< T > il)
Assign from std::initializer_list, not thread-safe.
concurrent_priority_queue< T, Compare, A > * cpq
Concurrent priority queue.
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
concurrent_priority_queue & operator=(concurrent_priority_queue &&src)
Move assignment operator.
aggregator_t my_aggregator
size_type size() const
Returns the current number of elements contained in the queue.
concurrent_priority_queue & operator=(const concurrent_priority_queue &src)
Assignment operator.
cpq_operation(operation_type t)
void reheap()
Re-heapify after an extraction.
void swap(atomic< T > &lhs, atomic< T > &rhs)
allocator_type get_allocator() const
Return allocator object.
bool try_pop(reference elem)
Gets a reference to and removes highest priority element.
concurrent_priority_queue(const allocator_type &a=allocator_type())
Constructs a new concurrent_priority_queue with default capacity.
size_t size_type
Integral type for representing size of the queue.
size_type mark
The point at which unsorted elements begin.
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
bool empty() const
Returns true if empty, false otherwise.
__TBB_atomic size_type my_size
void clear()
Clear the queue; not thread-safe.
void push(const_reference elem)
Pushes elem onto the queue, increasing capacity of queue if necessary.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void * data
void swap(concurrent_hash_map< Key, T, HashCompare, A > &a, concurrent_hash_map< Key, T, HashCompare, A > &b)
void push(value_type &&elem)
Pushes elem onto the queue, increasing capacity of queue if necessary.
void push_back_helper(const T &t, tbb::internal::true_type)
tbb::internal::true_type type
void assign(InputIterator begin, InputIterator end)
Assign the queue from [begin,end) range, not thread-safe.
void push_back_helper(const T &, tbb::internal::false_type)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
concurrent_priority_queue(size_type init_capacity, const allocator_type &a=allocator_type())
Constructs a new concurrent_priority_queue with init_sz capacity.
ptrdiff_t difference_type
Difference type for iterator.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id parent
void call_itt_notify(notify_type, void *)
my_functor_t(concurrent_priority_queue< T, Compare, A > *cpq_)
aggregated_operation base class
void move(tbb_thread &t1, tbb_thread &t2)
concurrent_priority_queue(const concurrent_priority_queue &src)
Copy constructor.
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
void itt_hide_store_word(T &dst, T src)
concurrent_priority_queue(InputIterator begin, InputIterator end, const allocator_type &a=allocator_type())
[begin,end) constructor
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
const T & const_reference
Const reference type.
Identifiers declared inside namespace internal should never be used directly by client code...
void emplace(Args &&... args)
Constructs a new element using args as the arguments for its construction and pushes it onto the queu...
T value_type
Element type in the queue.
concurrent_priority_queue(const concurrent_priority_queue &src, const allocator_type &a)
Copy constructor with specific allocator.
void operator()(cpq_operation *op_list)
void handle_operations(cpq_operation *op_list)
void __TBB_store_with_release(volatile T &location, V value)
void swap(concurrent_priority_queue &q)
Swap this queue with another; not thread-safe.
T & reference
Reference type.