16 #ifndef FIXEDSIZEDEQUE_HPP
17 #define FIXEDSIZEDEQUE_HPP
19 #include "LvArray/src/Array.hpp"
20 #include "LvArray/src/memcpy.hpp"
21 #include "LvArray/src/ChaiBuffer.hpp"
25 #define POSITIVE_MODULO( a, b ) ( ( ( a ) % ( b ) ) + b ) % ( b )
28 template<
typename T,
typename INDEX_TYPE >
33 using IndexType = INDEX_TYPE;
35 using ArraySlice1DLarge = LvArray::ArraySlice< T const, 1, 0, std::ptrdiff_t >;
37 using Array2D = LvArray::Array< T, 2, camp::make_idx_seq_t< 2 >, std::ptrdiff_t, LvArray::ChaiBuffer >;
47 FixedSizeDeque( IndexType maxEntries, IndexType valuesPerEntry, LvArray::MemorySpace space, camp::resources::Resource stream ):
50 GEOS_ERROR_IF( maxEntries < 0,
"Fixed sized queue size must be positive" );
51 GEOS_ERROR_IF( valuesPerEntry < 0,
"Fixed sized queue array size must be positive" );
52 m_storage.resizeWithoutInitializationOrDestruction( space, maxEntries, valuesPerEntry );
58 return m_begin > m_end;
70 return (
size_t)( m_end - m_begin + 1 );
76 return m_storage.size( 0 );
83 return m_storage[ POSITIVE_MODULO( m_begin, m_storage.size( 0 ) ) ];
90 return m_storage[ POSITIVE_MODULO( m_begin-1, m_storage.size( 0 ) ) ];
94 ArraySlice1DLarge
back()
const
97 return m_storage[ POSITIVE_MODULO( m_end, m_storage.size( 0 ) ) ];
104 return m_storage[ POSITIVE_MODULO( m_end+1, m_storage.size( 0 ) ) ];
141 template<
typename INDEX_TYPE2 >
142 camp::resources::Event
emplace_front(
const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > & src )
145 camp::resources::Event e = LvArray::memcpy( m_stream, m_storage[ POSITIVE_MODULO( m_begin-1, m_storage.size( 0 ) ) ], src );
156 template<
typename INDEX_TYPE2 >
157 camp::resources::Event
emplace_back(
const LvArray::ArraySlice< T const, 1, 0, INDEX_TYPE2 > & src )
160 camp::resources::Event e = LvArray::memcpy( m_stream, m_storage[ POSITIVE_MODULO( m_end+1, m_storage.size( 0 ) ) ], src );
179 IndexType m_begin = 0;
180 IndexType m_end = -1;
181 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.