From ebc3b584d0d2d95ce60c6767e44fce46d6304b49 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 8 Jul 2008 11:42:05 +0000 Subject: [PATCH] [MERGE] libi2ncommon: (reinhard) added operator!= to Interval; aded some doc. --- src/timefunc.cpp | 36 +++++++++++++++++++++++++++++++++++- src/timefunc.hxx | 8 +++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/timefunc.cpp b/src/timefunc.cpp index c055aa4..a676a3f 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -464,6 +464,8 @@ bool Intervals::intersects(const Intervals& other) const * @param new_frame the new interval. * * Adds the interval to the list and joins overlapping intervals. + * + * @internal complexity O(n). */ void Intervals::add(const Interval& new_frame) { @@ -555,6 +557,8 @@ void Intervals::add(const Interval& new_frame) * * removes the time interval from the list; cut off parts from or remove existing * intervals if they overlap. + * + * @internal complexity O(n). */ void Intervals::sub(const Interval& del_frame) { @@ -650,6 +654,8 @@ bool Intervals::contains(const Interval& other) const * * @internal we rely on the fact that the lists are sorted and contain * disjoint intervals. + * + * So this method has a complexity of O(n). */ bool Intervals::contains(const Intervals& other) const { @@ -678,9 +684,17 @@ bool Intervals::contains(const Intervals& other) const ++other_it; } return (other_it == other.end()); -} // eo Intervals::comtains(const Intervals&) const +} // eo Intervals::contains(const Intervals&) const +/** + * @brief combines to interval combinates for equality + * @param other the other instance. + * @return @a true if the other is equal to the current. + * + * @internal since the lists are sorted, we compare the interval lists. + * Thus we have a complexity of O(n). + */ bool Intervals::operator==(const Intervals& other) const { // since we keep sorted lists: just compare the lists :-) @@ -702,6 +716,16 @@ Intervals& Intervals::operator-=(const Interval& other) } // eo operator-=(const Interval&) +/** + * @brief adds the intervals of a second instance to us. + * @param other the other instance. + * @return self reference (allow chaining). + * + * @internal since we do simple loops over the other and our intervals + * we have a complexity of O(n^2). + * + * @todo optimize if complexity becomes a problem. + */ Intervals& Intervals::operator+=(const Intervals& other) { for(const_iterator it= other.begin(); @@ -714,6 +738,16 @@ Intervals& Intervals::operator+=(const Intervals& other) } // eo operator+=(const Intervals&) +/** + * @brief subtracts the intervals of a second instance from us. + * @param other the other instance. + * @return self reference (allow chaining). + * + * @internal since we do simple loops over the other and our intervals + * we have a complexity of O(n^2). + * + * @todo optimize if complexity becomes a problem. + */ Intervals& Intervals::operator-=(const Intervals& other) { if (&other == this) diff --git a/src/timefunc.hxx b/src/timefunc.hxx index e4121ff..42b1275 100644 --- a/src/timefunc.hxx +++ b/src/timefunc.hxx @@ -202,6 +202,12 @@ class Interval } // eo operator==(const Interval&) + bool operator!=(const Interval& other) const + { + return not (*this == other); + } // eo operator!=(const Interval&) + + /** * @brief less operator. compares only the start times! * @param other the other interval to compare with. @@ -281,7 +287,7 @@ class Intervals bool contains(const Intervals& other) const; bool operator==(const Intervals& other) const; - bool operator!=(const Intervals& other) const {return not (*this == other) ; } + bool operator!=(const Intervals& other) const { return not (*this == other) ; } Intervals& operator+=(const Interval& other); Intervals& operator-=(const Interval& other); -- 1.7.1