14 #ifndef FIXEDSIZEDEQUE_HPP
15 #define FIXEDSIZEDEQUE_HPP
17 #include "LvArray/src/Array.hpp"
18 #include "LvArray/src/memcpy.hpp"
19 #include "LvArray/src/ChaiBuffer.hpp"
23 #define POSITIVE_MODULO( a, b ) ( ( ( a ) % ( b ) ) + b ) % ( b )
26 template<
typename T,
typename INDEX_TYPE >
31 using IndexType = INDEX_TYPE;
33 using ArraySlice1DLarge = LvArray::ArraySlice< T const, 1, 0, std::ptrdiff_t >;
35 using Array2D = LvArray::Array< T, 2, camp::make_idx_seq_t< 2 >, std::ptrdiff_t, LvArray::ChaiBuffer >;
45 FixedSizeDeque( IndexType maxEntries, IndexType valuesPerEntry, LvArray::MemorySpace space, camp::resources::Resource stream ):
48 GEOS_ERROR_IF( maxEntries < 0,
"Fixed sized queue size must be positive" );
49 GEOS_ERROR_IF( valuesPerEntry < 0,
"Fixed sized queue array size must be positive" );
50 m_storage.resizeWithoutInitializationOrDestruction( space, maxEntries, valuesPerEntry );
56 return m_begin > m_end;
68 return (
size_t)( m_end - m_begin + 1 );
74 return m_storage.size( 0 );
81 return m_storage[ POSITIVE_MODULO( m_begin, m_storage.size( 0 ) ) ];
88 return m_storage[ POSITIVE_MODULO( m_begin-1, m_storage.size( 0 ) ) ];
92 ArraySlice1DLarge
back()
const
95 return m_storage[ POSITIVE_MODULO( m_end, m_storage.size( 0 ) ) ];
102 return m_storage[ POSITIVE_MODULO( m_end+1, m_storage.size( 0 ) ) ];
139 template<
typename INDEX_TYPE2 >
140 camp::resources::Event
emplace_front(
const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > & src )
143 camp::resources::Event e = LvArray::memcpy( m_stream, m_storage[ POSITIVE_MODULO( m_begin-1, m_storage.size( 0 ) ) ], src );
154 template<
typename INDEX_TYPE2 >
155 camp::resources::Event
emplace_back(
const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > & src )
158 camp::resources::Event e = LvArray::memcpy( m_stream, m_storage[ POSITIVE_MODULO( m_end+1, m_storage.size( 0 ) ) ], src );
177 IndexType m_begin = 0;
178 IndexType m_end = -1;
179 camp::resources::Resource m_stream;
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Implement a double ended queue with fixed number of fixed size buffer to be stored.
camp::resources::Resource getStream()
void inc_front()
Add one array (uninitialized) at the front of the queue.
camp::resources::Event emplace_back(const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > &src)
ArraySlice1DLarge back() const
ArraySlice1DLarge next_back() const
void inc_back()
Add one array (uninitialized) at the end of the queue.
camp::resources::Event emplace_front(const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > &src)
ArraySlice1DLarge next_front() const
void pop_back()
Removes last array of the queue.
void pop_front()
Removes first array of the queue.
ArraySlice1DLarge front() const
FixedSizeDeque(IndexType maxEntries, IndexType valuesPerEntry, LvArray::MemorySpace space, camp::resources::Resource stream)
std::size_t size_t
Unsigned size type.