length,and represents the set of
lengthunsigned integers beginning with
origin.It also has a pointer that can point to another Interval. The constructor
Interval(unsigned origin=0, unsigned length=0,permits all these members to be set. The copy constructor copies the origin and length values but always sets the next pointer to null. A third constructor
Interval* nxt = 0);
Interval(const Interval& i1,Interval* nxt);permits a combination of a copy and a next-pointer initialization. The members
unsigned origin() const;return the origin and length values.
unsigned length() const;
unsigned end() const;The
endfunction returns the last unsigned integer that is a member of the Interval; 0 is returned for empty Intervals. There are a number of queries that are valuable for building a set class out of Intervals:
int isAfter(const Interval &i1) const;
isAfterreturns true if this Interval begins after the end of interval
int endsBefore(const Interval &i1) const;
endsBeforereturns true if this Interval ends strictly before the origin of interval i1.
int completelyBefore(const Interval &i1) const;
completelyBeforereturns true if
endsBeforeis true and there is space between the intervals (they cannot be merged).
int mergeableWith(const Interval& i1) const;
mergeableWithreturns true if two intervals overlap or are adjacent, so that their union is also an interval.
int intersects(const Interval& i1) const;
intersectsreturns true if two intervals have a non-null intersection.
int subsetOf(const Interval& i1) const;
subsetOfreturns true if the argument is a subset of this interval.
void merge(const Interval& i1);
mergealters the interval to the result of merging it with
i1.It is assumed that
Interval& operator&=(const Interval& i1);This Interval is changed to the intersection of itself and of
IntervalList();The default constructor produces the empty IntervalList.
IntervalList(unsigned origin,unsigned length);This constructor creates an IntervalList containing
lengthintegers starting with
IntervalList(const char* definition);This constructor takes a definition of the IntervalList from the string in
definition,parses it, and creates the list of intervals accordingly. There is also a copy constructor, an assignment operator, and a destructor.
int contains(const Interval& i1) const;The
containsmethod returns 0 if no part of
i1is in the IntervalList, 1 if
i1is completely contained in the IntervalList, and -1 if
i1is partially contained (has a non-null intersection).
IntervalList& operator|=(const Interval& src);Add a new interval to the interval list.
IntervalList& operator|=(const IntervalList& src);Sets the IntervalList to the union of itself and
IntervalList operator&(const IntervalList& arg) const;The binary
&operator returns the intersection of its arguments, which are not changed.
IntervalList& subtract(const Interval& i1);Subtract the Interval
IntervalList& operator-=(const Interval& i1);
i1from the list. That is, any intersection is removed from the set. Both the
-=forms are equivalent.
IntervalList& operator-=(const IntervalList &arg);This one subtracts the argument
argfrom the list (removes any intersection).
int empty() const;Return
TRUE(1) for an empty IntervalList, otherwise
++function returns a pointer to the next contained Interval;
resetgoes back to the beginning.