bool Cluster::contains(const Point &p) const { if(p.getDims() != __dimensionality) { throw DimensionalityMismatchEx(p.getDims(), __dimensionality); } LNodePtr cursor = __points; if(__size == 0) { assert(__points == nullptr); return false; } if(__points->point == p) { return true; } else { for(cursor; cursor->next != nullptr; cursor = cursor->next) { if(cursor->point == p) { return true; } } } return false; }
bool operator ==( const Point & lhs, const Point & rhs) { if (lhs.__dim != rhs.__dim) throw DimensionalityMismatchEx(lhs.__dim,rhs.__dim); if(lhs.__id != rhs.__id) return false; for (int i = 0; i < lhs.__dim; i++) { if (lhs.getValue(i) != rhs.getValue(i)) return false; } return true; }
bool Cluster::contains(const Point &p) const { if(__dimensionality != p.getDims()) throw DimensionalityMismatchEx(__dimensionality, p.getDims()); LNodePtr curr = __points; while (curr != nullptr) { if (curr->point.getId() == p.getId()) // if Point is in the list. return true else it returns false. return true; else curr= curr->next; } return false; }
bool operator==(const Cluster & C1, const Cluster &C2){ if(C1.__dimensionality != C2.__dimensionality){ throw DimensionalityMismatchEx(C1.__dimensionality, C2.__dimensionality); } if((C1.__points == nullptr && C2.__points == nullptr)){ return true; } if(C1.__points == nullptr || C2.__points == nullptr){ return false; } if(C1.__size != C2.__size){ return false; } for(int i = 0; i < C1.__size; ++i){ if(C1[i] != C2[i]){ return false; } } return true; }
Point & operator+=(Point &lhs, const Point& rhs) { if (lhs.__dim != rhs.__dim) throw DimensionalityMismatchEx(lhs.__dim,rhs.__dim); if (&lhs == &rhs) { for (int count = 0; count < lhs.__dim; count++) lhs.__values[count] += rhs.__values[count]; } else if (lhs.__dim == rhs.__dim) { for (int count = 0; count < lhs.__dim; count++) lhs.__values[count] += rhs.__values[count]; } return lhs; }
void Cluster::add(const Point & pNew) { if (__points == nullptr) { LNode *N = new LNode(pNew, nullptr); __points = N; ++__size; centroid.setValid(false); return; } if(__dimensionality != pNew.getDims()){ throw DimensionalityMismatchEx(__dimensionality, pNew.getDims()); } if (__points->next == nullptr) { LNode *N = new LNode(pNew, nullptr); if(N->point < __points->point){ N->next = __points; __points = N; ++__size; centroid.setValid(false); return; } else { __points->next = N; ++__size; centroid.setValid(false); return; } } LNode *N = new LNode(pNew, nullptr); LNodePtr temp = __points->next; LNodePtr prev = __points; if(N->point < __points->point){ __points = N; N->next = prev; ++__size; centroid.setValid(false); return; } if(N->point < temp->point){ prev->next = N; N->next = temp; ++__size; centroid.setValid(false); return; } while (temp->next != nullptr) { if(N->point < temp->point){ prev->next = N; N->next = temp; ++__size; centroid.setValid(false); return; } temp = temp->next; prev = prev->next; } temp->next = N; ++__size; centroid.setValid(false); }
bool operator!=(const Point & P1, const Point & P2){ if (P1.__dim != P2.__dim) throw DimensionalityMismatchEx(P1.__dim, P2.__dim); return !(P1 == P2); }