23#ifndef CONTAINER_ATOMIC_INTEGRALS_ARRAY
24#define CONTAINER_ATOMIC_INTEGRALS_ARRAY
81template <
typename T,
typename I = container::Padded_indexing<T>,
82 typename A = std::
nullptr_t>
154 typename D = T,
typename J = I,
typename B = A,
155 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> * =
nullptr>
165 typename D = T,
typename J = I,
typename B = A,
166 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> * =
nullptr>
226 template <
typename Pred>
227 std::tuple<T, size_t>
find_if(Pred predicate,
size_t start_from = 0)
const;
237 size_t find(T to_find,
size_t start_from = 0)
const;
278template <
typename T,
typename I,
typename A>
281 : m_current{position}, m_parent{&parent} {}
283template <
typename T,
typename I,
typename A>
285 : m_current{rhs.m_current}, m_parent{rhs.m_parent} {}
287template <
typename T,
typename I,
typename A>
289 : m_current{rhs.m_current}, m_parent{rhs.m_parent} {
291 rhs.m_parent =
nullptr;
294template <
typename T,
typename I,
typename A>
302template <
typename T,
typename I,
typename A>
306 this->m_parent = rhs.m_parent;
308 rhs.m_parent =
nullptr;
312template <
typename T,
typename I,
typename A>
315 if (this->m_current < this->m_parent->m_index.size()) {
321template <
typename T,
typename I,
typename A>
324 return (*this->m_parent)[this->m_current];
327template <
typename T,
typename I,
typename A>
330 auto to_return = (*this);
335template <
typename T,
typename I,
typename A>
338 return &((*this->m_parent)[this->m_current]);
341template <
typename T,
typename I,
typename A>
347template <
typename T,
typename I,
typename A>
350 return !((*this) == rhs);
353template <
typename T,
typename I,
typename A>
354template <
typename D,
typename J,
typename B,
355 std::enable_if_t<!std::is_same<B, std::nullptr_t>::value> *>
360 this->
init(init_value);
363template <
typename T,
typename I,
typename A>
364template <
typename D,
typename J,
typename B,
365 std::enable_if_t<std::is_same<B, std::nullptr_t>::value> *>
369 static_cast<size_t>(m_index.size()) * I::element_size())} {
370 this->
init(init_value);
373template <
typename T,
typename I,
typename A>
377 this->m_array[this->m_index.translate(index)]);
380template <
typename T,
typename I,
typename A>
386template <
typename T,
typename I,
typename A>
389 return Iterator{*
this, this->m_index.size()};
392template <
typename T,
typename I,
typename A>
393template <
typename Pred>
395 Pred predicate,
size_t start_from)
const {
396 for (
size_t idx = start_from; idx != this->m_index.size(); ++idx) {
397 auto ¤t = (*this)[idx];
398 T value = current.load(std::memory_order_relaxed);
399 if (predicate(value, idx)) {
400 return std::make_tuple(value, idx);
403 return std::make_tuple(std::numeric_limits<T>::max(), this->m_index.size());
406template <
typename T,
typename I,
typename A>
408 size_t start_from)
const {
409 for (
size_t idx = start_from; idx != this->m_index.size(); ++idx) {
410 auto ¤t = (*this)[idx];
411 T value = current.load(std::memory_order_relaxed);
412 if (value == to_find) {
416 return this->m_index.size();
419template <
typename T,
typename I,
typename A>
421 return this->m_index.size();
424template <
typename T,
typename I,
typename A>
426 return this->m_index.size() * I::element_size();
429template <
typename T,
typename I,
typename A>
432 for (
auto value : (*
this)) {
439template <
typename T,
typename I,
typename A>
442 for (
size_t idx = 0; idx != this->m_index.size(); ++idx) {
443 ::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:100
bool operator!=(Iterator const &rhs) const
Definition: atomics_array.h:348
std::forward_iterator_tag iterator_category
Definition: atomics_array.h:106
size_t m_current
The position of the element this iterator is pointing to.
Definition: atomics_array.h:140
Iterator & operator=(const Iterator &rhs)
Definition: atomics_array.h:296
T reference
Definition: atomics_array.h:105
reference operator*() const
Definition: atomics_array.h:323
Iterator(Atomics_array< T, I, A > const &parent, size_t position)
Definition: atomics_array.h:279
T * pointer
Definition: atomics_array.h:104
T value_type
Definition: atomics_array.h:103
pointer operator->() const
Definition: atomics_array.h:337
virtual ~Iterator()=default
Iterator & operator++()
Definition: atomics_array.h:314
std::ptrdiff_t difference_type
Definition: atomics_array.h:102
Atomics_array< T, I, A > const * m_parent
The reference to the queue holding the elements.
Definition: atomics_array.h:142
bool operator==(Iterator const &rhs) const
Definition: atomics_array.h:342
Array of std::atomic elements of type T.
Definition: atomics_array.h:83
T const const_value_type
Definition: atomics_array.h:90
T const & const_reference_type
Definition: atomics_array.h:88
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:407
T value_type
Definition: atomics_array.h:89
T * pointer_type
Definition: atomics_array.h:85
size_t size() const
Returns the size of the array.
Definition: atomics_array.h:420
container::Atomics_array< T, I, A > & init(T init_value)
Initializes the array.
Definition: atomics_array.h:440
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:430
Atomics_array(Atomics_array< T, I, A > const &rhs)=delete
I m_index
The index translation object to be used.
Definition: atomics_array.h:265
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:394
T const * const_pointer_type
Definition: atomics_array.h:86
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:388
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:356
std::atomic< T > element_type
Definition: atomics_array.h:91
memory::Unique_ptr< unsigned char[], A > m_array
The byte array in which the elements will be stored.
Definition: atomics_array.h:267
size_t allocated_size() const
Returns the number of bytes used to allocate the array.
Definition: atomics_array.h:425
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:366
T & reference_type
Definition: atomics_array.h:87
Iterator begin() const
Retrieves an iterator instance that points to the beginning of the array.
Definition: atomics_array.h:382
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:257
element_type & operator[](size_t index) const
Retrieves the value stored in a specific index of the array.
Definition: atomics_array.h:375
Smart pointer to hold a unique pointer to a heap allocated memory of type T, constructed using a spec...
Definition: unique_ptr.h:151
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:49
Definition: atomics_array.h:38
Definition: aligned_atomic.h:43
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.
static mysql_service_status_t flush(reference_caching_cache cache) noexcept
Definition: component.cc:121
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2868