NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
NeMinHeap.h
1
11#pragma once
12
13#include <NeCoreLib.h>
14#include <vector>
15
16namespace NeuralEngine
17{
18
19 template <typename KeyType, typename ValueType>
20
88
89 class MinHeap
90 {
91 public:
92 struct Record
93 {
94 KeyType key;
95 ValueType value;
96 int index;
97 };
98
112 MinHeap(MinHeap const& minHeap);
113
127 MinHeap(int maxElements = 0);
128
129 // Assignment.
130 MinHeap& operator=(MinHeap const& minHeap);
131
132
146 void Reset(int maxElements);
147
148 //
149 //
150
161 inline int GetNumElements() const;
162
177 inline bool GetMinimum(KeyType& key, ValueType& value) const;
178
179
200 Record* Insert(KeyType const& key, ValueType const& value);
201
218 bool Remove(KeyType& key, ValueType& value);
219
220
235 void Update(Record* record, ValueType const& value);
236
237 //
238 //
239
250 bool IsValid() const;
251
252 private:
253 // A 2-level storage system is used. The pointers have two roles.
254 // Firstly, they are unique to each inserted value in order to support
255 // the Update() capability of the min-heap. Secondly, they avoid
256 // potentially expensive copying of Record objects as sorting occurs in
257 // the heap.
258 int mNumElements;
259 std::vector<Record> mRecords;
260 std::vector<Record*> mPointers;
261 };
262#include "NeMinHeap.inl"
263}
Minimum heap binary tree.
Definition: NeMinHeap.h:90
Record * Insert(KeyType const &key, ValueType const &value)
Insert into the min-heap the 'value' that corresponds to the 'key'.
Definition: NeMinHeap.inl:80
int GetNumElements() const
Get the remaining number of elements in the min-heap. This number is in the range {0....
Definition: NeMinHeap.inl:58
bool IsValid() const
Support for debugging. The functions test whether the data structure is a valid min-heap.
Definition: NeMinHeap.inl:283
bool Remove(KeyType &key, ValueType &value)
Remove the root of the heap and return its 'key' and 'value members.
Definition: NeMinHeap.inl:125
bool GetMinimum(KeyType &key, ValueType &value) const
Get the root of the min-heap. The return value is 'true' whenever the min-heap is not empty....
Definition: NeMinHeap.inl:64
void Update(Record *record, ValueType const &value)
The value of a heap record must be modified through this function call.
Definition: NeMinHeap.inl:185
void Reset(int maxElements)
Resets the given maxElements.
Definition: NeMinHeap.inl:37
MinHeap(MinHeap const &minHeap)
Copy constructor.
Definition: NeMinHeap.inl:18