32 #ifndef __INDEX_HEAP_H 33 #define __INDEX_HEAP_H 51 template<
typename IT,
typename VT>
66 Entry(
const IT index,
const VT value): index(index), value(value) {}
73 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
75 typedef typename Eigen::Matrix<Value, Eigen::Dynamic, 1>
ValueVector;
96 data.push_back(
Entry(invalidIndex<IT>(), invalidValue<VT>()));
101 inline const VT&
headValue()
const {
return data.front().value; }
111 pop_heap(data.begin(), data.end());
112 data.back() =
Entry(index, value);
116 data.push_back(
Entry(index, value));
119 push_heap(data.begin(), data.end());
125 sort_heap (data.begin(), data.end());
131 template<
typename DI,
typename DV>
132 inline void getData(
const Eigen::MatrixBase<DI>& indices,
const Eigen::MatrixBase<DV> & values)
const 139 for (; i < data.size(); ++i)
141 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) = data[i].index;
142 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) = data[i].value;
146 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) = invalidIndex<IT>();
147 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) = invalidValue<VT>();
154 inline IndexVector getIndexes()
const 156 IndexVector indexes(data.capacity());
158 for (; i < data.size(); ++i)
159 indexes.coeffRef(i) = data[i].index;
160 for (; i < data.capacity(); ++i)
161 indexes.coeffRef(i) = 0;
171 template<
typename IT,
typename VT>
191 typedef std::vector<Entry>
Entries;
193 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
198 const VT& headValueRef;
200 const size_t sizeMinusOne;
205 data(size,
Entry(0, std::numeric_limits<VT>::infinity())),
206 headValueRef((data.end() - 1)->
value),
207 sizeMinusOne(data.size() - 1)
214 for (
typename Entries::iterator it(data.begin()); it != data.end(); ++it)
216 it->value = std::numeric_limits<VT>::infinity();
223 inline const VT&
headValue()
const {
return data[0].value; }
231 for (; i < sizeMinusOne; ++i)
233 if (data[i + 1].value > value)
234 data[i] = data[i + 1];
238 data[i].value =
value;
239 data[i].index =
index;
250 inline IndexVector getIndexes()
const 252 IndexVector indexes(data.size());
253 for (
size_t i = 0; i < data.size(); ++i)
254 indexes.coeffRef(i) = data[sizeMinusOne-i].index;
263 template<
typename IT,
typename VT>
278 Entry(
const IT index,
const VT value): index(index), value(value) {}
285 typedef typename Eigen::Matrix<Index, Eigen::Dynamic, 1>
IndexVector;
287 typedef typename Eigen::Matrix<Value, Eigen::Dynamic, 1>
ValueVector;
300 headValueRef((data.end() - 1)->
value),
301 sizeMinusOne(data.size() - 1)
308 for (
typename Entries::iterator it(data.begin()); it != data.end(); ++it)
310 it->value = invalidValue<VT>();
311 it->index = invalidIndex<IT>();
317 inline const VT&
headValue()
const {
return headValueRef; }
325 for (i = sizeMinusOne; i > 0; --i)
327 if (data[i-1].value > value)
332 data[i].value =
value;
333 data[i].index =
index;
345 template<
typename DI,
typename DV>
346 inline void getData(
const Eigen::MatrixBase<DI>& indices,
const Eigen::MatrixBase<DV> & values)
const 352 for (
size_t i = 0; i < data.size(); ++i)
354 const_cast<Eigen::MatrixBase<DI>&
>(indices).coeffRef(i) = data[i].index;
355 const_cast<Eigen::MatrixBase<DV>&
>(values).coeffRef(i) = data[i].value;
361 inline IndexVector getIndexes()
const 363 IndexVector indexes(data.size());
364 for (
size_t i = 0; i < data.size(); ++i)
365 indexes.coeffRef(i) = data[i].index;
372 #endif // __INDEX_HEAP_H IndexHeapBruteForceVector(const size_t size)
Constructor.
friend bool operator<(const Entry &e0, const Entry &e1)
return true if e0 is smaller than e1, false otherwise
void replaceHead(const Index index, const Value value)
replace the largest value of the heap
void sort()
sort the entries, from the smallest to the largest
void sort()
sort the entries, from the smallest to the largest
an entry of the heap vector
Eigen::Matrix< Value, Eigen::Dynamic, 1 > ValueVector
vector of values
std::vector< Entry > Entries
vector of entry, type for the storage of the tree
void getData(const Eigen::MatrixBase< DI > &indices, const Eigen::MatrixBase< DV > &values) const
get the data from the heap
const VT & headValue() const
get the largest value of the heap
constexpr ValueType invalidValue()
const VT & headValueRef
reference to the largest value in the tree, to optimise access speed
VT value
distance for this point
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
vector of indices
std::vector< Entry > Entries
vector of entry, type for the storage of the tree
Entries data
storage for the tree
Entry(const IT index, const VT value)
create a new entry
const VT & headValue() const
get the largest value of the heap
Eigen::Matrix< Value, Eigen::Dynamic, 1 > ValueVector
vector of values
const size_t nbNeighbours
number of neighbours requested
const size_t sizeMinusOne
pre-competed size minus one, to optimise access speed
Entries data
storage for the tree
void reset()
reset to the empty heap
an entry of the heap tree
void replaceHead(const Index index, const Value value)
put value into heap, replace the largest value if full
balanced-tree implementation of heap
IndexHeapSTL(const size_t size)
Constructor.
void reset()
reset to the empty heap
constexpr IndexType invalidIndex()
void getData(const Eigen::MatrixBase< DI > &indices, const Eigen::MatrixBase< DV > &values) const
get the data from the heap
Entry(const IT index, const VT value)
create a new entry
brute-force implementation of heap
VT value
distance for this point
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
vector of indices
friend bool operator<(const Entry &e0, const Entry &e1)
return true if e0 is of lower value than e1, false otherwise