22 #ifndef __TBB__flow_graph_hash_buffer_impl_H 23 #define __TBB__flow_graph_hash_buffer_impl_H 25 #ifndef __TBB_flow_graph_H 26 #error Do not #include this internal file directly; use public TBB headers instead. 33 template<
typename ValueType>
50 static const size_t INITIAL_SIZE = 8;
68 size_t mask() {
return my_size - 1; }
71 for(
size_t i=0; i < sz - 1; ++i ) {
72 la[i].second = &(la[i+1]);
74 la[sz-1].second = NULL;
75 *p_free_list = (element_type *)&(la[0]);
84 DoCleanup(pointer_array_type &pa, list_array_type &my_els,
size_t sz) :
85 my_pa(&pa), my_elements(&my_els), my_size(sz) { }
89 internal_free_buffer(*my_pa, *my_elements, my_size, dont_care);
97 size_t new_nelements = nelements;
98 list_array_type new_elements_array = NULL;
99 pointer_array_type new_pointer_array = NULL;
100 list_array_type new_free_list = NULL;
102 DoCleanup my_cleanup(new_pointer_array, new_elements_array, new_size);
103 new_elements_array = elements_array_allocator().allocate(my_size);
104 new_pointer_array = pointer_array_allocator_type().allocate(new_size);
105 for(
size_t i=0; i <
new_size; ++i) new_pointer_array[i] = NULL;
106 set_up_free_list(&new_free_list, new_elements_array, my_size );
108 for(
size_t i=0; i < my_size; ++i) {
109 for( element_type* op = pointer_array[i]; op; op = (element_type *)(op->second)) {
110 value_type *ov =
reinterpret_cast<value_type *
>(&(op->first));
112 internal_insert_with_key(new_pointer_array, new_size, new_free_list, *ov);
115 my_cleanup.my_pa = NULL;
116 my_cleanup.my_elements = NULL;
119 internal_free_buffer(pointer_array, elements_array, my_size, nelements);
120 free_list = new_free_list;
121 pointer_array = new_pointer_array;
122 elements_array = new_elements_array;
124 nelements = new_nelements;
130 const value_type &v) {
131 size_t l_mask = p_sz-1;
132 __TBB_ASSERT(my_key,
"Error: value-to-key functor not provided");
133 size_t h = this->hash((*my_key)(v)) & l_mask;
134 __TBB_ASSERT(p_free_list,
"Error: free list not set up.");
135 element_type* my_elem = p_free_list; p_free_list = (element_type *)(p_free_list->second);
136 (
void)
new(&(my_elem->first)) value_type(v);
137 my_elem->second = p_pointer_array[
h];
138 p_pointer_array[
h] = my_elem;
142 pointer_array = pointer_array_allocator_type().allocate(my_size);
143 for(
size_t i = 0; i < my_size; ++i) pointer_array[i] = NULL;
144 elements_array = elements_array_allocator().allocate(my_size / 2);
145 set_up_free_list(&free_list, elements_array, my_size / 2);
151 for(
size_t i = 0; i < sz; ++i ) {
152 element_type *p_next;
153 for( element_type *
p = pa[i];
p;
p = p_next) {
154 p_next = (element_type *)
p->second;
155 internal::punned_cast<value_type *>(&(
p->first))->~value_type();
158 pointer_array_allocator_type().deallocate(pa, sz);
164 elements_array_allocator().deallocate(el, sz / 2);
172 hash_buffer() : my_key(NULL), my_size(INITIAL_SIZE), nelements(0) {
173 internal_initialize_buffer();
177 internal_free_buffer(pointer_array, elements_array, my_size, nelements);
178 if(my_key)
delete my_key;
182 internal_free_buffer(pointer_array, elements_array, my_size, nelements);
183 internal_initialize_buffer();
193 pointer_type
p = NULL;
194 __TBB_ASSERT(my_key,
"Error: value-to-key functor not provided");
195 if(find_ref_with_key((*my_key)(v), p)) {
197 (
void)
new(p) value_type(v);
201 if(nelements*2 > my_size) grow_array();
202 internal_insert_with_key(pointer_array, my_size, free_list, v);
208 size_t i = this->hash(k) &
mask();
209 for(element_type*
p = pointer_array[i];
p;
p = (element_type *)(
p->second)) {
210 pointer_type pv =
reinterpret_cast<pointer_type
>(&(
p->first));
211 __TBB_ASSERT(my_key,
"Error: value-to-key functor not provided");
212 if(this->equal((*my_key)(*pv), k)) {
222 if(find_ref_with_key(k, p)) {
231 size_t h = this->hash(k) &
mask();
232 element_type* prev = NULL;
233 for(element_type*
p = pointer_array[h];
p; prev =
p,
p = (element_type *)(p->second)) {
234 value_type *vp =
reinterpret_cast<value_type *
>(&(p->first));
235 __TBB_ASSERT(my_key,
"Error: value-to-key functor not provided");
236 if(this->equal((*my_key)(*vp), k)) {
238 if(prev) prev->second = p->second;
239 else pointer_array[
h] = (element_type *)(p->second);
240 p->second = free_list;
249 #endif // __TBB__flow_graph_hash_buffer_impl_H 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 mask
void delete_with_key(const Knoref &k)
DoCleanup(pointer_array_type &pa, list_array_type &my_els, size_t sz)
pointer_array_type * my_pa
list_array_type elements_array
value_type * pointer_type
bool insert_with_key(const value_type &v)
tbb::internal::strip< Key >::type Knoref
static void internal_free_buffer(pointer_array_type &pa, list_array_type &el, size_t &sz, size_t &ne)
Allocator::template rebind< list_array_type >::other pointer_array_allocator_type
aligned_pair< ValueType, void * >::type type
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
void internal_insert_with_key(element_type **p_pointer_array, size_t p_sz, list_array_type &p_free_list, const value_type &v)
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 h
ValueToKey * get_key_func()
bool find_ref_with_key(const Knoref &k, pointer_type &v)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
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 new_size
buffer_element_type< value_type >::type element_type
Allocator::template rebind< element_type >::other elements_array_allocator
list_array_type * my_elements
void const char const char int ITT_FORMAT __itt_group_sync p
void set_up_free_list(element_type **p_free_list, list_array_type la, size_t sz)
element_type * list_array_type
list_array_type * pointer_array_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 ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
void internal_initialize_buffer()
void set_key_func(ValueToKey *vtk)
bool find_with_key(const Knoref &k, value_type &v)
pointer_array_type pointer_array