18 #ifndef __H__OCULAR_UTILS_PRIORITY_LIST__H__
19 #define __H__OCULAR_UTILS_PRIORITY_LIST__H__
21 #include "Exceptions/Exception.hpp"
22 #include "Priority.hpp"
44 template<
typename T, std::
size_t MAX_ELEMENTS>
73 bool push(T
const element, uint32_t priority)
77 if(m_TrueSize < MAX_ELEMENTS)
79 retVal =
add(element, priority);
112 bool add(T
const element, uint32_t priority)
116 if(m_TrueSize < MAX_ELEMENTS)
135 if(index != MAX_ELEMENTS)
149 if(index >= m_TrueSize)
151 THROW_EXCEPTION(
"Index Out of Bounds");
162 T
const get(std::size_t index)
const
164 if(index >= m_TrueSize)
166 THROW_EXCEPTION(
"Index Out of Bounds");
169 return m_Array[index].first;
193 return (m_TrueSize == 0);
203 return (index != MAX_ELEMENTS);
227 m_Array[index] = std::pair<T, uint32_t>(element, priority);
251 for(std::size_t i = index; i < m_TrueSize - 1; i++)
253 m_Array[i] = m_Array[i + 1];
270 if(m_TrueSize != MAX_ELEMENTS)
272 for(std::size_t i = m_TrueSize; i > index; i--)
274 m_Array[i] = m_Array[i - 1];
287 std::size_t index = MAX_ELEMENTS;
289 for(std::size_t i = 0; i < m_TrueSize; i++)
291 if(m_Array[i].first == element)
314 if(priority < m_Array[0].second)
318 else if(priority > m_Array[m_TrueSize - 1].second)
332 uint32_t upper =
static_cast<uint32_t
>(m_TrueSize);
333 uint32_t index =
static_cast<uint32_t
>(m_TrueSize / 2);
334 uint32_t increment =
static_cast<uint32_t
>(index / 2);
340 for( ; upper > 0; upper--, increment /= 2)
347 if(m_Array[index].second == priority)
351 else if (m_Array[index].second > priority)
364 if((index == m_TrueSize) || (index == MAX_ELEMENTS - 1))
378 std::size_t m_TrueSize;
380 std::pair<T, std::size_t> m_Array[MAX_ELEMENTS] = {};
void insertElement(T const element, uint32_t const priority)
Definition: PriorityList.hpp:222
bool empty() const
Definition: PriorityList.hpp:191
std::size_t findIndex(uint32_t const priority) const
Definition: PriorityList.hpp:304
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
std::size_t size() const
Definition: PriorityList.hpp:175
void deleteElement(std::size_t const index)
Definition: PriorityList.hpp:233
bool add(T const element, uint32_t priority)
Definition: PriorityList.hpp:112
bool pop()
Definition: PriorityList.hpp:90
void removeElement(T const element)
Definition: PriorityList.hpp:129
void clear()
Definition: PriorityList.hpp:209
std::size_t locateIndex(T const element) const
Definition: PriorityList.hpp:285
bool contains(T const element) const
Definition: PriorityList.hpp:200
void shiftLeft(std::size_t const index)
Definition: PriorityList.hpp:243
bool push(T const element, uint32_t priority)
Definition: PriorityList.hpp:73
void removeIndex(uint32_t index)
Definition: PriorityList.hpp:147
Definition: PriorityList.hpp:45
std::size_t maxSize() const
Definition: PriorityList.hpp:183
void shiftRight(std::size_t const index)
Definition: PriorityList.hpp:263
std::size_t binaryFind(uint32_t const priority) const
Definition: PriorityList.hpp:330