24#ifndef CONTAINER_ATOMIC_INTEGRALS_ARRAY
25#define CONTAINER_ATOMIC_INTEGRALS_ARRAY
82template <
typename T,
typename I = container::Padded_indexing<T>,
83 typename A = std::
nullptr_t>
155 typename D = T,
typename J = I,
typename B = A,
156 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> * =
nullptr>
166 typename D = T,
typename J = I,
typename B = A,
167 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> * =
nullptr>
227 template <
typename Pred>
228 std::tuple<T, size_t>
find_if(Pred predicate,
size_t start_from = 0)
const;
238 size_t find(T to_find,
size_t start_from = 0)
const;
279template <
typename T,
typename I,
typename A>
282 : m_current{position}, m_parent{&parent} {}
284template <
typename T,
typename I,
typename A>
286 : m_current{rhs.m_current}, m_parent{rhs.m_parent} {}
288template <
typename T,
typename I,
typename A>
290 : m_current{rhs.m_current}, m_parent{rhs.m_parent} {
292 rhs.m_parent =
nullptr;
295template <
typename T,
typename I,
typename A>
303template <
typename T,
typename I,
typename A>
307 this->m_parent = rhs.m_parent;
309 rhs.m_parent =
nullptr;
313template <
typename T,
typename I,
typename A>
316 if (this->m_current < this->m_parent->m_index.size()) {
322template <
typename T,
typename I,
typename A>
325 return (*this->m_parent)[this->m_current];
328template <
typename T,
typename I,
typename A>
331 auto to_return = (*this);
336template <
typename T,
typename I,
typename A>
339 return &((*this->m_parent)[this->m_current]);
342template <
typename T,
typename I,
typename A>
348template <
typename T,
typename I,
typename A>
351 return !((*this) == rhs);
354template <
typename T,
typename I,
typename A>
355template <
typename D,
typename J,
typename B,
356 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> *>
361 this->
init(init_value);
364template <
typename T,
typename I,
typename A>
365template <
typename D,
typename J,
typename B,
366 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> *>
370 static_cast<size_t>(m_index.
size()) * I::element_size())} {
371 this->
init(init_value);
374template <
typename T,
typename I,
typename A>
378 this->m_array[this->m_index.translate(index)]);
381template <
typename T,
typename I,
typename A>
387template <
typename T,
typename I,
typename A>
390 return Iterator{*
this, this->m_index.size()};
393template <
typename T,
typename I,
typename A>
394template <
typename Pred>
396 Pred predicate,
size_t start_from)
const {
397 for (
size_t idx = start_from; idx != this->m_index.size(); ++idx) {
398 auto ¤t = (*this)[idx];
399 T value = current.load(std::memory_order_relaxed);
400 if (predicate(value, idx)) {
401 return std::make_tuple(value, idx);
404 return std::make_tuple(std::numeric_limits<T>::max(), this->m_index.size());
407template <
typename T,
typename I,
typename A>
409 size_t start_from)
const {
410 for (
size_t idx = start_from; idx != this->m_index.size(); ++idx) {
411 auto ¤t = (*this)[idx];
412 T value = current.load(std::memory_order_relaxed);
413 if (value == to_find) {
417 return this->m_index.size();
420template <
typename T,
typename I,
typename A>
422 return this->m_index.size();
425template <
typename T,
typename I,
typename A>
427 return this->m_index.size() * I::element_size();
430template <
typename T,
typename I,
typename A>
433 for (
auto value : (*
this)) {
440template <
typename T,
typename I,
typename A>
443 for (
size_t idx = 0; idx != this->m_index.size(); ++idx) {
444 ::new (&this->m_array[this->m_index.translate(idx)])
Iterator helper class to iterate over the array, from 0 to the array size.
Definition: atomics_array.h:101
bool operator!=(Iterator const &rhs) const
Definition: atomics_array.h:349
std::forward_iterator_tag iterator_category
Definition: atomics_array.h:107
size_t m_current
The position of the element this iterator is pointing to.
Definition: atomics_array.h:141
Iterator & operator=(const Iterator &rhs)
Definition: atomics_array.h:297
T reference
Definition: atomics_array.h:106
reference operator*() const
Definition: atomics_array.h:324
Iterator(Atomics_array< T, I, A > const &parent, size_t position)
Definition: atomics_array.h:280
T * pointer
Definition: atomics_array.h:105
T value_type
Definition: atomics_array.h:104
pointer operator->() const
Definition: atomics_array.h:338
virtual ~Iterator()=default
Iterator & operator++()
Definition: atomics_array.h:315
std::ptrdiff_t difference_type
Definition: atomics_array.h:103
Atomics_array< T, I, A > const * m_parent
The reference to the queue holding the elements.
Definition: atomics_array.h:143
bool operator==(Iterator const &rhs) const
Definition: atomics_array.h:343
Array of std::atomic elements of type T.
Definition: atomics_array.h:84
T const const_value_type
Definition: atomics_array.h:91
T const & const_reference_type
Definition: atomics_array.h:89
size_t find(T to_find, size_t start_from=0) const
First the first occurrence of to_find, starting at start_from index.
Definition: atomics_array.h:408
T value_type
Definition: atomics_array.h:90
T * pointer_type
Definition: atomics_array.h:86
size_t size() const
Returns the size of the array.
Definition: atomics_array.h:421
container::Atomics_array< T, I, A > & init(T init_value)
Initializes the array.
Definition: atomics_array.h:441
Atomics_array< T, I, A > & operator=(Atomics_array< T, I, A > &&rhs)=delete
std::string to_string() const
Return this queue textual representation.
Definition: atomics_array.h:431
Atomics_array(Atomics_array< T, I, A > const &rhs)=delete
I m_index
The index translation object to be used.
Definition: atomics_array.h:266
std::tuple< T, size_t > find_if(Pred predicate, size_t start_from=0) const
Finds a value in the queue according to the evaluation of predicate by traversing the array from star...
Definition: atomics_array.h:395
T const * const_pointer_type
Definition: atomics_array.h:87
Atomics_array< T, I, A > & operator=(Atomics_array< T, I, A > const &rhs)=delete
Iterator end() const
Retrieves an iterator instance that points to the end of the underlying array.
Definition: atomics_array.h:389
Atomics_array(A &alloc, size_t size, T init_value)
Constructor allowing a specific memory allocator, a specific queue size and the instance of T to init...
Definition: atomics_array.h:357
std::atomic< T > element_type
Definition: atomics_array.h:92
memory::Unique_ptr< unsigned char[], A > m_array
The byte array in which the elements will be stored.
Definition: atomics_array.h:268
size_t allocated_size() const
Returns the number of bytes used to allocate the array.
Definition: atomics_array.h:426
Atomics_array(size_t size, T init_value)
Constructor allowing a specific queue size and the instance of T to initialize the array with.
Definition: atomics_array.h:367
T & reference_type
Definition: atomics_array.h:88
Iterator begin() const
Retrieves an iterator instance that points to the beginning of the array.
Definition: atomics_array.h:383
virtual ~Atomics_array()=default
Destructor for the class.
Atomics_array(Atomics_array< T, I, A > &&rhs)=delete
friend std::ostream & operator<<(std::ostream &out, Atomics_array< T, I, A > &in)
Definition: atomics_array.h:258
element_type & operator[](size_t index) const
Retrieves the value stored in a specific index of the array.
Definition: atomics_array.h:376
Smart pointer to hold a unique pointer to a heap allocated memory of type T, constructed using a spec...
Definition: unique_ptr.h:152
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
Definition: atomics_array.h:39
Definition: aligned_atomic.h:44
Unique_ptr< T, std::nullptr_t > make_unique(size_t size)
In-place constructs a new unique pointer with no specific allocator and with array type T.
size_t size(const char *const c)
Definition: base64.h:46
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:114
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2872