ICAROUS
|
#include <IntervalSet.h>
Public Member Functions | |
IntervalSet () | |
IntervalSet (const IntervalSet &l) | |
IntervalSet (const std::vector< Interval > &v) | |
std::vector< Interval > | toVector () const |
void | clear () |
const Interval & | getInterval (int i) const |
int | size () const |
bool | isEmpty () const |
bool | in (double x) const |
void | unions (const Interval &rn) |
void | unions (const IntervalSet &n) |
void | almost_unions (const IntervalSet &n, INT64FM maxUlps) |
void | almost_add (double l, double u) |
void | almost_add (double l, double u, INT64FM maxUlps) |
void | almost_intersect (const IntervalSet &n) |
void | almost_intersect (const IntervalSet &n, INT64FM maxUlps) |
void | diff (const Interval &rn) |
void | diff (const IntervalSet &n) |
void | removeSingle (double x, double width) |
void | removeSingle (double x) |
void | sweepSingle () |
void | sweepSingle (double width) |
void | sweepBreaks (double width) |
std::string | toString () const |
std::string | toString (const std::string &unit) const |
Static Public Attributes | |
static const int | max_intervals = 400 |
Private Member Functions | |
int | order (double x) const |
void | insert (int i, const Interval &r) |
void | remove (int i) |
void | remove (int i, int len) |
Private Attributes | |
Interval | r [max_intervals] |
int | length |
Static Private Attributes | |
static const Interval | empty |
The IntervalSet class represents a set of "double" values. Ranges of doubles are maintained as intervals (Interval). These Intervals are ordered consecutively from lowest to highest. Standard set operations of in
(membership), union
(set union), intersect
(set intersection), and diff
(set difference) are provided.
Within the IntervalSet, intervals are generally considered closed (including end-points), and the results off operations are closed intervals. This implies that the interval difference is between a set of closed intervals and one or more open intervals.
The intervals are numbered 0 to size()-1. To cycle through the intervals one may:
IntervalSet set;
for( int i = 0; i < set.size(); i++) {
Interval r;
r = set.getInterval(i);
... work with r ...
}
The current implementation does not allocate any dynamic (heap) memory.
IntervalSet::IntervalSet | ( | ) |
Construct an empty IntervalSet
IntervalSet::IntervalSet | ( | const IntervalSet & | l | ) |
Copy the IntervalSet into a new set
l | IntervalSet to copy |
|
explicit |
Build an IntervalSet from the given vector
void IntervalSet::almost_add | ( | double | l, |
double | u | ||
) |
Add the given interval into this set. If this interval overlaps any interval in the set, then the intervals are merged. This method uses "almost" inequalities to compute the addition.
l | lower bound of interval |
u | upper bound of interval |
Add the given interval into this set. If this interval overlaps any interval in the set, then the intervals are merged. This method uses "almost" inequalities to compute the addition.
void IntervalSet::almost_add | ( | double | l, |
double | u, | ||
INT64FM | maxUlps | ||
) |
Add the given interval into this set. If this interval overlaps any interval in the set, then the intervals are merged. This method uses "almost" inequalities to compute the addition.
l | lower bound of interval |
u | upper bound of interval |
maxUlps | units of least precision |
Add the given interval into this set. If this interval overlaps any interval in the set, then the intervals are merged. This method uses "almost" inequalities to compute the addition.
void IntervalSet::almost_intersect | ( | const IntervalSet & | n | ) |
Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.
n | set |
Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.
void IntervalSet::almost_intersect | ( | const IntervalSet & | n, |
INT64FM | maxUlps | ||
) |
Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.
n | set |
maxUlps | units of least precision |
Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.
void IntervalSet::almost_unions | ( | const IntervalSet & | n, |
INT64FM | maxUlps | ||
) |
Union the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.
n | set |
void IntervalSet::clear | ( | ) |
Empty this IntervalSet
void IntervalSet::diff | ( | const Interval & | rn | ) |
Remove the given open interval from the given set of closed intervals. Note: the semantics of this method mean that [1,2] - (1,2) = [1,1] and [2,2]. To get rid of the extraneous singletons use methods like removeSingle() or sweepSingle().
rn | interval |
void IntervalSet::diff | ( | const IntervalSet & | n | ) |
Perform a set difference between these two IntervalSets. The parameter is interpreted as a set of open intervals.
n | set |
const Interval & IntervalSet::getInterval | ( | int | i | ) | const |
bool IntervalSet::in | ( | double | x | ) | const |
Is the given value a member of this set?
x | value |
void IntervalSet::removeSingle | ( | double | x | ) |
Remove the single-valued interval x from this IntervalSet. If x is not a single-valued interval, then this method does nothing.
x | value |
void IntervalSet::removeSingle | ( | double | x, |
double | width | ||
) |
Remove the single-valued interval x from this IntervalSet. If x is not a single-valued interval (of width or less), then this method does nothing.
x | value |
width | space around value |
int IntervalSet::size | ( | ) | const |
Return the total number of intervals
void IntervalSet::sweepBreaks | ( | double | width | ) |
Remove all breaks of less than width from this IntervalSet
width | max open space to remove |
void IntervalSet::sweepSingle | ( | ) |
Remove all the single-valued intervals from this IntervalSet.
void IntervalSet::sweepSingle | ( | double | width | ) |
Remove all the single-valued intervals (of width or less) from this IntervalSet.
width | space around single values |
std::string IntervalSet::toString | ( | ) | const |
Print the contents of this IntervalSet
std::string IntervalSet::toString | ( | const std::string & | unit | ) | const |
Print the contents of this IntervalSet
std::vector< Interval > IntervalSet::toVector | ( | ) | const |
Return this set as a vector
void IntervalSet::unions | ( | const Interval & | rn | ) |
Merge the given interval into this set. If this interval overlaps any interval in the set, then the intervals are merged.
void IntervalSet::unions | ( | const IntervalSet & | n | ) |
Union the given IntervalSet into the current IntervalSet. IntervalSet n is unmodified.
|
static |
The maximum number of intervals