ICAROUS
All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Modules Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
larcfm::IntervalSet Class Reference

#include <IntervalSet.h>

Public Member Functions

 IntervalSet ()
 
 IntervalSet (const IntervalSet &l)
 
 IntervalSet (const std::vector< Interval > &v)
 
std::vector< IntervaltoVector () const
 
void clear ()
 
const IntervalgetInterval (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ IntervalSet() [1/3]

IntervalSet::IntervalSet ( )

Construct an empty IntervalSet

◆ IntervalSet() [2/3]

IntervalSet::IntervalSet ( const IntervalSet l)

Copy the IntervalSet into a new set

Parameters
lIntervalSet to copy

◆ IntervalSet() [3/3]

IntervalSet::IntervalSet ( const std::vector< Interval > &  v)
explicit

Build an IntervalSet from the given vector

Member Function Documentation

◆ almost_add() [1/2]

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.

Parameters
llower bound of interval
uupper 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.

◆ almost_add() [2/2]

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.

Parameters
llower bound of interval
uupper bound of interval
maxUlpsunits 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.

◆ almost_intersect() [1/2]

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.

Parameters
nset

Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.

◆ almost_intersect() [2/2]

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.

Parameters
nset
maxUlpsunits of least precision

Intersect the given IntervalSet into the current IntervalSet. Set n is unmodified. This method uses "almost" inequalities to compute the intersection.

◆ almost_unions()

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.

Parameters
nset

◆ clear()

void IntervalSet::clear ( )

Empty this IntervalSet

◆ diff() [1/2]

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().

Parameters
rninterval

◆ diff() [2/2]

void IntervalSet::diff ( const IntervalSet n)

Perform a set difference between these two IntervalSets. The parameter is interpreted as a set of open intervals.

Parameters
nset

◆ getInterval()

const Interval & IntervalSet::getInterval ( int  i) const

Return Interval i from this set. The Intervals are numbered 0..size()-1. If i is invalid, then an empty interval is returned.

Parameters
ithe index of the desired Interval.

◆ in()

bool IntervalSet::in ( double  x) const

Is the given value a member of this set?

Parameters
xvalue
Returns
true, if in set

◆ removeSingle() [1/2]

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.

Parameters
xvalue

◆ removeSingle() [2/2]

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.

Parameters
xvalue
widthspace around value

◆ size()

int IntervalSet::size ( ) const

Return the total number of intervals

Returns
number of intervals

◆ sweepBreaks()

void IntervalSet::sweepBreaks ( double  width)

Remove all breaks of less than width from this IntervalSet

Parameters
widthmax open space to remove

◆ sweepSingle() [1/2]

void IntervalSet::sweepSingle ( )

Remove all the single-valued intervals from this IntervalSet.

◆ sweepSingle() [2/2]

void IntervalSet::sweepSingle ( double  width)

Remove all the single-valued intervals (of width or less) from this IntervalSet.

Parameters
widthspace around single values

◆ toString() [1/2]

std::string IntervalSet::toString ( ) const

Print the contents of this IntervalSet

◆ toString() [2/2]

std::string IntervalSet::toString ( const std::string &  unit) const

Print the contents of this IntervalSet

◆ toVector()

std::vector< Interval > IntervalSet::toVector ( ) const

Return this set as a vector

◆ unions() [1/2]

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.

◆ unions() [2/2]

void IntervalSet::unions ( const IntervalSet n)

Union the given IntervalSet into the current IntervalSet. IntervalSet n is unmodified.

Member Data Documentation

◆ max_intervals

const int larcfm::IntervalSet::max_intervals = 400
static

The maximum number of intervals


The documentation for this class was generated from the following files: