diff --git a/fastlib/u/nvasil/dataset/binary_dataset.h b/fastlib/u/nvasil/dataset/binary_dataset.h index 64074b9af9..483f32c0ca 100644 --- a/fastlib/u/nvasil/dataset/binary_dataset.h +++ b/fastlib/u/nvasil/dataset/binary_dataset.h @@ -43,6 +43,11 @@ class BinaryDataset { friend class Iterator; class Iterator { public: + typedef random_access_iterator_tag iterator_category; + typedef CompletePoint value_type; + typedef index_t difference_type; + typedef CompletePoint* pointer; + typedef CompletePoint& reference; Iterator(){ } Iterator(BinaryDataset *dataset) { @@ -52,28 +57,69 @@ class BinaryDataset { Iterator &operator=(const Iterator &other) { this->set_=other.set_; this->current_pos_=other.current_pos_; + return *this; } Iterator operator++() { current_pos_++; - DEBUG_ASSERT_MSG(current_pos_>set_->get_num_of_points(), - "Iterator out of bounds "LI">"LI"", - current_pos_, set_->get_num_of_points()); + DEBUG_ASSERT_MSG(current_pos_>(signed long long)set_->get_num_of_points(), + "Iterator out of bounds %lli>%lli", + (signed long long)current_pos_, + (signed long long)set_->get_num_of_points()); } Iterator operator+(index_t i) { Iterator it(*this); it.current_pos_+=i; - DEBUG_ASSERT_MSG(it.current_pos_="LI"\n", - it.current_pos_, set_->get_num_of_points()); + DEBUG_ASSERT_MSG(it.current_pos_<(signed long long)set_->get_num_of_points() + && it.current_pos_>=0, + "iterator out of bounds %lli>=%lli\n", + (signed long long)it.current_pos_, + (signed long long)set_->get_num_of_points()); return it; } + Iterator operator+(const Iterator &other) { + Iterator it(*this); + it.current_pos_+=other.current_pos_; + DEBUG_ASSERT_MSG(it.current_pos_<(signed long long)set_->get_num_of_points() + && it.current_pos_>=0, + "iterator out of bounds %lli>=%lli\n", + (signed long long)it.current_pos_, + (signed long long)set_->get_num_of_points()); + return it; + + } Iterator operator--() { current_pos_--; DEBUG_ASSERT_MSG(current_pos_<0, - "Iterator out of bounds "LI"<0", - current_pos_ ); + "Iterator out of bounds %lli <0", + (signed long long)current_pos_ ); } + Iterator operator-(index_t i) { + Iterator it(*this); + it.current_pos_-=i; + DEBUG_ASSERT_MSG(it.current_pos_<(signed long long)set_->get_num_of_points() + && it.current_pos_>=0, + "iterator out of bounds %lli>=%lli\n", + (unsigned long long)it.current_pos_, + (unsigned long long)set_->get_num_of_points()); + return it; + + } + index_t operator-(const Iterator &other) { + index_t diff = current_pos_-other.current_pos_; + DEBUG_ASSERT_MSG(current_pos_<(signed long long)set_->get_num_of_points() + && current_pos_>=0, + "iterator out of bounds %lli>=%lli\n", + (unsigned long long)current_pos_, + (unsigned long long)set_->get_num_of_points()); + return diff; + + } + Iterator operator/(const int divider) { + Iterator it(*this); + it.current_pos_/=divider; + return it; + } bool operator==(const Iterator &other) { if (likely(other.set_==set_)) { return current_pos_==other.current_pos_; @@ -88,14 +134,35 @@ class BinaryDataset { return true; } } - CompletePoint operator*() { + bool operator<=(const Iterator &other) { + if (likely(other.set_==set_)) { + return current_pos_<=other.current_pos_; + } else { + return false; + } + } + bool operator>(const Iterator &other) { + if (likely(other.set_==set_)) { + return current_pos_>other.current_pos_; + } else { + return false; + } + } + bool operator<(const Iterator &other) { + if (likely(other.set_==set_)) { + return current_pos_ &operator*() { CompletePoint point; point.Alias(set_->At(current_pos_), set_->get_id(current_pos_), set_->get_dimension()); return point; } - CompletePoint operator->() { + CompletePoint &operator->() { CompletePoint point; point.Alias(set_->At(current_pos_), set_->get_id(current_pos_), @@ -226,12 +293,13 @@ class BinaryDataset { // returns a reference on the i,j element inline Precision_t &At(uint64 i, int32 j) { DEBUG_ASSERT_MSG(i"LI"" - , i, num_of_points_); + "Attempt to acces data out of range %lli>%lli", + (unsigned long long)i, + (unsigned long long)num_of_points_); DEBUG_ASSERT_MSG(j"L32"" - , j, dimension_); + "Attempt to access element greater that the dimension %lli>%lli", + (unsigned long long)j, + (unsigned long long)dimension_); return data_[i*dimension_+j]; } // get the index at i point diff --git a/fastlib/u/nvasil/tree/binary_tree_unit.cc b/fastlib/u/nvasil/tree/binary_tree_unit.cc index 0b21422614..0ebcbd1903 100644 --- a/fastlib/u/nvasil/tree/binary_tree_unit.cc +++ b/fastlib/u/nvasil/tree/binary_tree_unit.cc @@ -318,7 +318,7 @@ struct TreeParameters2 { typedef Node Node_t; typedef KdPivoter1 Pivot_t; }; -/* + struct TreeParameters3 { typedef Node Node_t; typedef KdPivoter2 Pivot_t; @@ -328,20 +328,20 @@ struct TreeParameters4 { typedef Node Node_t; typedef KdPivoter2 Pivot_t; }; -*/ + typedef BinaryTreeTest BinaryTreeTest1_t; typedef BinaryTreeTest BinaryTreeTest2_t; -//typedef BinaryTreeTest BinaryTreeTest3_t; -//typedef BinaryTreeTest BinaryTreeTest4_t; +typedef BinaryTreeTest BinaryTreeTest3_t; +typedef BinaryTreeTest BinaryTreeTest4_t; int main(int argc, char *argv[]) { BinaryTreeTest1_t test1; test1.TestAll(); BinaryTreeTest2_t test2; test2.TestAll(); - /* BinaryTreeTest3_t test3; + BinaryTreeTest3_t test3; test3.TestAll(); BinaryTreeTest4_t test4; test4.TestAll(); - */ + } diff --git a/fastlib/u/nvasil/tree/kd_pivoter2.h b/fastlib/u/nvasil/tree/kd_pivoter2.h index ce6d7b755b..a7b47ac59a 100644 --- a/fastlib/u/nvasil/tree/kd_pivoter2.h +++ b/fastlib/u/nvasil/tree/kd_pivoter2.h @@ -49,8 +49,8 @@ class KdPivoter2 { pivot_dimension_=pivot_dimension; } bool operator()(const CompletePoint &p1, - const CompletePoint &p2) const { - return p1[pivot_dimension_] &p2) const { + return p1.At(pivot_dimension_)dimension_==other.dimension_, - "Points have different dimensions "LI"!="LI"", - this->dimension_, other.dimension_); + "Points have different dimensions %lli !=%lli", + (signed long long)this->dimension_, + (signed long long)other.dimension_); memcpy(this->p_, other.p_, dimension_*sizeof(Precision_t)); this->id_=other.id_; } @@ -164,6 +165,12 @@ class CompletePoint { id_=id; dimension_=dimension; } + Precision_t &operator[](index_t i) { + return p_[i]; + } + Precision_t At(index_t i) const { + return p_[i]; + } private: Precision_t *p_; index_t id_;