59 _initialize(positions, left_corner, right_corner, positions.size());
66 const unsigned int max_size) {
67 _initialize(positions, left_corner, right_corner, max_size);
72 void closest_pair(
unsigned int & ID1,
unsigned int & ID2,
73 double & distance2)
const;
76 void remove(
unsigned int ID);
80 unsigned int insert(
const Coord2D &);
84 virtual unsigned int replace(
unsigned int ID1,
unsigned int ID2,
89 virtual void replace_many(
const std::vector<unsigned int> & IDs_to_remove,
90 const std::vector<Coord2D> & new_positions,
91 std::vector<unsigned int> & new_IDs);
94 inline void print_tree_depths(std::ostream & outdev)
const {
95 outdev << _trees[0]->max_depth() <<
" "
96 << _trees[1]->max_depth() <<
" "
97 << _trees[2]->max_depth() <<
"\n";
104 void _initialize(
const std::vector<Coord2D> & positions,
105 const Coord2D & left_corner,
const Coord2D & right_corner,
106 const unsigned int max_size);
108 static const unsigned int _nshift = 3;
113 template<
class T>
class triplet {
115 inline const T & operator[](
unsigned int i)
const {
return _contents[i];};
116 inline T & operator[](
unsigned int i) {
return _contents[i];};
118 T _contents[_nshift];
130 void operator+=(
unsigned int shift) {x += shift; y+= shift;};
133 typedef SearchTree<Shuffle> Tree;
134 typedef Tree::circulator circulator;
135 typedef Tree::const_circulator const_circulator;
150 double neighbour_dist2;
152 triplet<circulator> circ;
155 unsigned int review_flag;
158 double distance2(
const Point & other)
const {
159 return coord.distance2(other.coord);
166 triplet<SharedPtr<Tree> > _trees;
167 SharedPtr<MinHeap> _heap;
168 std::vector<Point> _points;
169 std::stack<Point *> _available_points;
172 std::vector<Point *> _points_under_review;
175 static const unsigned int _remove_heap_entry = 1;
176 static const unsigned int _review_heap_entry = 2;
177 static const unsigned int _review_neighbour = 4;
182 void _add_label(Point * point,
unsigned int review_flag);
187 void _set_label(Point * point,
unsigned int review_flag);
193 void _deal_with_points_to_review();
196 void _remove_from_search_tree(Point * point_to_remove);
199 void _insert_into_search_tree(Point * new_point);
202 void _point2shuffle(Point & , Shuffle & ,
unsigned int shift);
205 Coord2D _left_corner;
208 int _ID(
const Point *)
const;
210 triplet<unsigned int> _shifts;
211 triplet<unsigned int> _rel_shifts;
213 unsigned int _cp_search_range;
ClosestPair2D(const std::vector< Coord2D > &positions, const Coord2D &left_corner, const Coord2D &right_corner)
constructor from a vector of 2D positions – number of objects after insertion and deletion must never...
ClosestPair2D(const std::vector< Coord2D > &positions, const Coord2D &left_corner, const Coord2D &right_corner, const unsigned int max_size)
constructor which allows structure to grow beyond positions.size(), up to max_size