31 #ifndef LSST_AP_CLUSTER_DETAIL_SEEDLIST_CC
32 #define LSST_AP_CLUSTER_DETAIL_SEEDLIST_CC
37 namespace lsst {
namespace ap {
namespace cluster {
namespace detail {
39 template <
int K,
typename DataT>
41 _heap(new int[numPoints]),
47 template <
int K,
typename DataT>
51 template <
int K,
typename DataT>
57 template <
int K,
typename DataT>
63 template <
int K,
typename DataT>
73 template <
int K,
typename DataT>
79 int smallest =
_heap[0];
97 template <
int K,
typename DataT>
99 assert(i >= 0 && i < _numPoints);
100 assert(_size < _numPoints);
105 _points[i].state = 0;
118 template <
int K,
typename DataT>
120 assert(i >= 0 && i < _numPoints);
121 int heapIndex = _points[i].state;
122 if (heapIndex >= 0) {
123 assert(
_heap[heapIndex] == i);
125 if (reach < _points[i].reach) {
126 _points[i].reach = reach;
127 siftUp(heapIndex, i);
131 _points[i].reach = reach;
136 template <
int K,
typename DataT>
138 assert(heapIndex < _size);
139 assert(pointIndex >= 0 && pointIndex < _numPoints);
140 double reach = _points[pointIndex].reach;
141 while (heapIndex > 0) {
142 int parentHeapIndex = (heapIndex - 1) >> 1;
143 int parentPointIndex =
_heap[parentHeapIndex];
144 if (_points[parentPointIndex].reach <= reach) {
147 _heap[heapIndex] = parentPointIndex;
148 _points[parentPointIndex].state = heapIndex;
149 heapIndex = parentHeapIndex;
151 _heap[heapIndex] = pointIndex;
152 _points[pointIndex].state = heapIndex;
155 template <
int K,
typename DataT>
157 assert(pointIndex >= 0 && pointIndex < _numPoints);
158 double reach = _points[pointIndex].reach;
159 int halfSize = _size >> 1;
161 while (heapIndex < halfSize) {
162 int childHeapIndex = (heapIndex << 1) + 1;
163 int siblingHeapIndex = childHeapIndex + 1;
164 int childPointIndex =
_heap[childHeapIndex];
165 double childReach = _points[childPointIndex].reach;
166 if (siblingHeapIndex < _size) {
167 int siblingPointIndex =
_heap[siblingHeapIndex];
168 double siblingReach = _points[siblingPointIndex].reach;
169 if (siblingReach < childReach) {
170 childReach = siblingReach;
171 childPointIndex = siblingPointIndex;
172 childHeapIndex = siblingHeapIndex;
175 if (reach <= childReach) {
178 _heap[heapIndex] = childPointIndex;
179 _points[childPointIndex].state = heapIndex;
180 heapIndex = childHeapIndex;
182 _heap[heapIndex] = pointIndex;
183 _points[pointIndex].state = heapIndex;
189 template <
int K,
typename DataT>
192 for (
int i = 0; i < _numPoints; ++i) {
193 int h = _points[i].state;
205 for (
int i = 0; i < _size; ++i) {
207 if (p < 0 || p >= _numPoints) {
211 if (_points[p].state != i) {
217 for (
int i = 0; i < _size >> 1; ++i) {
218 double reach = _points[
_heap[i]].reach;
219 int h = (i << 1) + 1;
221 if (_points[p].reach < reach) {
227 if (_points[p].reach < reach) {
237 #endif // LSST_AP_CLUSTER_DETAIL_SEEDLIST_CC
Class that maintains the OPTICS seed list.
void siftUp(int heapIndex, int pointIndex)
std::vector< SourceCatalog > const cluster(SourceCatalog const &sources, ClusteringControl const &control)
void update(int i, double reach)
SeedList(Point< K, DataT > *points, int numPoints)
int capacity() const
Returns the capacity of this seed list.
std::vector< std::pair< Angle, Ref * > > _heap
bool checkInvariants() const
int size() const
Returns the number of entries in this seed list.
void siftDown(int pointIndex)
bool empty() const
Returns true if this seed list contains no entries.