Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TArrayHeap.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <utility>
8#include <algorithm>
9
10namespace ph
11{
12
13template<typename T, std::size_t N, typename IsLess>
14inline TArrayHeap<T, N, IsLess>::TArrayHeap() requires std::default_initializable<IsLess>
15 : TArrayHeap(IsLess{})
16{}
17
18template<typename T, std::size_t N, typename IsLess>
20 : m_data{}
21 , m_currentIndex(-1)
22 , m_isLess(std::move(isLess))
23{}
24
25template<typename T, std::size_t N, typename IsLess>
26template<typename U>
27inline void TArrayHeap<T, N, IsLess>::push(U&& item)
28{
29 PH_ASSERT_IN_RANGE(m_currentIndex + 1, Index(0), Index(N));
30
31 m_data[++m_currentIndex] = std::forward<U>(item);
32 std::push_heap(m_data.begin(), m_data.begin() + m_currentIndex + 1, m_isLess);
33}
34
35template<typename T, std::size_t N, typename IsLess>
37{
38 PH_ASSERT_IN_RANGE(m_currentIndex - 1, Index(-1), Index(N - 1));
39
40 std::pop_heap(m_data.begin(), m_data.begin() + m_currentIndex + 1, m_isLess);
41 --m_currentIndex;
42}
43
44template<typename T, std::size_t N, typename IsLess>
46{
47 PH_ASSERT_IN_RANGE(m_currentIndex, Index(0), Index(N));
48
49 return m_data[0];
50}
51
52template<typename T, std::size_t N, typename IsLess>
53inline const T& TArrayHeap<T, N, IsLess>::top() const
54{
55 PH_ASSERT_IN_RANGE(m_currentIndex, Index(0), Index(N));
56
57 return m_data[0];
58}
59
60template<typename T, std::size_t N, typename IsLess>
61inline std::size_t TArrayHeap<T, N, IsLess>::size() const
62{
63 PH_ASSERT_GE(m_currentIndex + 1, Index(0));
64
65 return static_cast<std::size_t>(m_currentIndex + 1);
66}
67
68template<typename T, std::size_t N, typename IsLess>
70{
71 m_currentIndex = -1;
72}
73
74template<typename T, std::size_t N, typename IsLess>
76{
77 return m_currentIndex == -1;
78}
79
80}// end namespace ph
A fixed size heap backed by an array. The container inherits the properties of a fixed size array of ...
Definition TArrayHeap.h:21
TArrayHeap()
Definition TArrayHeap.ipp:14
void pop()
Removes the top item from the heap. The item originally at the target index is still alive after this...
Definition TArrayHeap.ipp:36
bool isEmpty() const
Definition TArrayHeap.ipp:75
void clear()
Definition TArrayHeap.ipp:69
std::size_t size() const
Definition TArrayHeap.ipp:61
void push(U &&item)
Adds an item to the heap. The item originally at the target index will be overwritten.
Definition TArrayHeap.ipp:27
T & top()
Access the top item of the heap. By default, the top item is the maximum item (max heap)....
Definition TArrayHeap.ipp:45
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96