ROSE 0.11.145.147
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Range< T > Class Template Reference

Description

template<class T>
class Range< T >

A contiguous range of values.

Represents a contiguous range of size values beginning at begin, and defines relationships between two ranges. The ranges are designed such that they can represent unsigned values up to and including the maximum possible values for the data type. However, this means that a range that represents all possible values will have a size() of zero due to overflow.

Floating point ranges are also possible (types "float" or "double") but the behavior of some methods differs slightly from integers. For instance, an integer range containing a single value has size 1, but a floating point range with one value has size zero. The differences are noted in the documentation for the particular methods affected.

Definition at line 50 of file rangemap.h.

#include <roseSupport/rangemap.h>

Collaboration diagram for Range< T >:
Collaboration graph
[legend]

Public Types

typedef T Value
 
typedef std::pair< Range, RangePair
 A pair of ranges.
 

Public Member Functions

 Range ()
 Create an empty range.
 
 Range (const Value &first)
 Create a new range of unit size.
 
 Range (const Value &first, const Value &size)
 Create a new range of specified size.
 
template<class Other >
 Range (const Other &other)
 Create a new range from a different range.
 
Value size () const
 Returns the number of values represented by the range.
 
Pair split_range_at (const Value &at) const
 Split a range into two parts.
 
Range join (const Range &right) const
 Joins two adjacent ranges.
 
std::vector< Rangeerase (const Range &to_erase) const
 Erase part of a range to return zero, one, or two new ranges.
 
Range intersect (const Range &other) const
 Intersection of two ranges.
 
bool empty () const
 Returns true if this range is empty.
 
void clear ()
 Make a range empty.
 
bool begins_with (const Range &x) const
 Do both ranges begin at the same place?
 
bool ends_with (const Range &x) const
 Do both ranges end at the same place?
 
bool begins_after (const Range &x, bool strict=true) const
 Does this range begin (strictly) after the beginning of another range?
 
bool begins_before (const Range &x, bool strict=true) const
 Does this range begin (strictly) before the beginning of another range?
 
bool ends_after (const Range &x, bool strict=true) const
 Does this range end (strictly) after the end of another range?
 
bool ends_before (const Range &x, bool strict=true) const
 Does this range end (strictly) before the end of another range?
 
bool contains (const Range &x, bool strict=false) const
 Does this range contain the argument range?
 
bool contained_in (const Range &x, bool strict=false) const
 Is this range contained in the argument range?
 
bool congruent (const Range &x) const
 Are two ranges equal?
 
bool left_of (const Range &x) const
 Is this range left of the argument range?
 
bool right_of (const Range &x) const
 Is this range right of the argument range?
 
bool overlaps (const Range &x) const
 Does this range overlap with the argument range?
 
bool distinct (const Range &x) const
 Is this range non-overlapping with the argument range?
 
bool abuts_lt (const Range &x) const
 Is this range immediately left of the argument range?
 
bool abuts_gt (const Range &x) const
 Is this range immediately right of the argument range?
 
bool operator== (const Range &x) const
 
bool operator!= (const Range &x) const
 
void print (std::ostream &o) const
 
bool empty () const
 
void clear ()
 
double relaxed_first () const
 
double size () const
 
void resize (const double &new_size)
 
void relaxed_resize (const double &new_size)
 
Range< double >::Pair split_range_at (const double &at) const
 
double minimum ()
 
double maximum ()
 
bool empty () const
 
void clear ()
 
float relaxed_first () const
 
float size () const
 
void resize (const float &new_size)
 
void relaxed_resize (const float &new_size)
 
Range< float >::Pair split_range_at (const float &at) const
 
float minimum ()
 
float maximum ()
 
void first (const Value &first)
 Accessor for the first value of a range.
 
const Value first () const
 Accessor for the first value of a range.
 
Value relaxed_first () const
 Accessor for the first value of a range.
 
void last (const Value &last)
 Accessor for the last value of a range.
 
const Value last () const
 Accessor for the last value of a range.
 
const Value relaxed_last () const
 Accessor for the last value of a range.
 
void resize (const Value &new_size)
 Sets the range size by adjusting the maximum value.
 
void relaxed_resize (const Value &new_size)
 Sets the range size by adjusting the maximum value.
 

Static Public Member Functions

static Range inin (const Value &v1, const Value &v2)
 Create a new range by giving the first (inclusive) and last value (inclusive).
 
static Value minimum ()
 Return the minimum possible value represented by this range.
 
static Value maximum ()
 Return the maximum possible value represented by this range.
 
static Range all ()
 Return a range that covers all possible values.
 

Protected Attributes

Value r_first
 First value in range.
 
Value r_last
 Last value in range.
 

Member Typedef Documentation

◆ Value

template<class T >
typedef T Range< T >::Value

Definition at line 52 of file rangemap.h.

◆ Pair

template<class T >
typedef std::pair<Range, Range> Range< T >::Pair

A pair of ranges.

Definition at line 53 of file rangemap.h.

Constructor & Destructor Documentation

◆ Range() [1/4]

template<class T >
Range< T >::Range ( )
inline

Create an empty range.

Ranges may have an empty size, but empty ranges will never appear inside a RangeMap object. The begin value of an empty range is meaningless.

Definition at line 62 of file rangemap.h.

Referenced by Range< T >::intersect().

◆ Range() [2/4]

template<class T >
Range< T >::Range ( const Value &  first)
inlineexplicit

Create a new range of unit size.

The new range contains only the specified value.

Definition at line 66 of file rangemap.h.

◆ Range() [3/4]

template<class T >
Range< T >::Range ( const Value &  first,
const Value &  size 
)
inline

Create a new range of specified size.

If size is zero then an empty range is created. Note that a zero size is also returned for a range that contains all values, but this is due to overflow. Whether this is an integer range or a floating point range, if size is zero then the range is considered to be empty (but the first value is remembered). To create a floating point range with a single value, use the single-argument constructor.

Definition at line 73 of file rangemap.h.

References Range< T >::clear(), Range< T >::empty(), Range< T >::first(), Range< T >::r_last, and Range< T >::size().

◆ Range() [4/4]

template<class T >
template<class Other >
Range< T >::Range ( const Other &  other)
inlineexplicit

Create a new range from a different range.

Definition at line 85 of file rangemap.h.

Member Function Documentation

◆ inin()

template<class T >
static Range Range< T >::inin ( const Value &  v1,
const Value &  v2 
)
inlinestatic

Create a new range by giving the first (inclusive) and last value (inclusive).

This is the only way to create a range that contains all values since the size of such a range overflows the range's Value type. If the two values are equal then the created range contains only that value; if the first value is larger than the second then the range is considered to be empty.

Definition at line 92 of file rangemap.h.

References Range< T >::first(), and Range< T >::last().

Referenced by Range< T >::all(), Range< T >::erase(), RangeMap< R, T >::erase_ranges(), Range< T >::intersect(), RangeMap< R, T >::invert_within(), Range< T >::join(), and RangeMap< R, T >::minmax().

◆ first() [1/2]

template<class T >
void Range< T >::first ( const Value &  first)
inline

◆ first() [2/2]

template<class T >
const Value Range< T >::first ( ) const
inline

Accessor for the first value of a range.

It does not make sense to ask for the first value of an empty range, and an assertion will fail if such a request is made. However, relaxed_first() will return a value anyway.

Definition at line 106 of file rangemap.h.

References Range< T >::empty(), and Range< T >::r_first.

Referenced by Range< T >::Range(), Range< T >::abuts_gt(), Range< T >::begins_after(), Range< T >::begins_before(), Range< T >::begins_with(), Range< T >::congruent(), Range< T >::contained_in(), Range< T >::contains(), Range< T >::erase(), Range< T >::first(), Range< T >::intersect(), Range< T >::join(), Range< T >::relaxed_first(), Range< T >::right_of(), and Range< T >::split_range_at().

◆ relaxed_first()

template<class T >
Value Range< T >::relaxed_first ( ) const
inline

Accessor for the first value of a range.

It does not make sense to ask for the first value of an empty range, and an assertion will fail if such a request is made. However, relaxed_first() will return a value anyway.

Definition at line 115 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), Range< T >::r_first, and Range< T >::r_last.

Referenced by Range< T >::relaxed_last(), and Range< T >::relaxed_resize().

◆ last() [1/2]

template<class T >
void Range< T >::last ( const Value &  last)
inline

◆ last() [2/2]

template<class T >
const Value Range< T >::last ( ) const
inline

Accessor for the last value of a range.

It does not make sense to ask for the last value of an empty range, and an assertion will fail if such a request is made. However, relaxed_last() will return a value anyway.

Definition at line 130 of file rangemap.h.

References Range< T >::empty(), and Range< T >::r_last.

Referenced by Range< T >::abuts_lt(), Range< T >::congruent(), Range< T >::contained_in(), Range< T >::contains(), Range< T >::ends_after(), Range< T >::ends_before(), Range< T >::ends_with(), Range< T >::erase(), Range< T >::intersect(), Range< T >::last(), Range< T >::left_of(), Range< T >::relaxed_last(), and Range< T >::split_range_at().

◆ relaxed_last()

template<class T >
const Value Range< T >::relaxed_last ( ) const
inline

Accessor for the last value of a range.

It does not make sense to ask for the last value of an empty range, and an assertion will fail if such a request is made. However, relaxed_last() will return a value anyway.

Definition at line 134 of file rangemap.h.

References Range< T >::empty(), Range< T >::last(), and Range< T >::relaxed_first().

◆ size()

template<class T >
Value Range< T >::size ( ) const
inline

Returns the number of values represented by the range.

Note that if the range contains all possible values then the returned size may be zero due to overflow, in which case the empty() method should also be called to make the determination.

Floating point range sizes are simply the last value minus the first value. Therefore, a singleton floating point range will return a size of zero, while a singleton integer range will return a size of one. This is actualy consistent behavior if you think of an integer value N as the floating point range [N,N+1), where N is included in the range but N+1 is not.

Definition at line 147 of file rangemap.h.

References Range< T >::empty(), Range< T >::r_first, and Range< T >::r_last.

Referenced by Range< T >::Range(), and Rose::BinaryAnalysis::RegisterDictionary::filterNonoverlapping().

◆ resize()

template<class T >
void Range< T >::resize ( const Value &  new_size)
inline

Sets the range size by adjusting the maximum value.

It is an error to change the size of a range from zero to non-zero, but the relaxed_resize() is available for that purpose.

Setting the size to zero causes different behavior for integer ranges than it does for floating point ranges. For integer ranges, setting the size to zero clears the range (makes it empty); for floating point ranges, setting the size to zero causes the range to contain only the starting value. Floating point ranges can be cleared by setting the new size to a negative value. The clear() method should be favored over resize() for making a range empty.

Definition at line 162 of file rangemap.h.

References Range< T >::clear(), Range< T >::empty(), Range< T >::r_first, and Range< T >::r_last.

◆ relaxed_resize()

template<class T >
void Range< T >::relaxed_resize ( const Value &  new_size)
inline

Sets the range size by adjusting the maximum value.

It is an error to change the size of a range from zero to non-zero, but the relaxed_resize() is available for that purpose.

Setting the size to zero causes different behavior for integer ranges than it does for floating point ranges. For integer ranges, setting the size to zero clears the range (makes it empty); for floating point ranges, setting the size to zero causes the range to contain only the starting value. Floating point ranges can be cleared by setting the new size to a negative value. The clear() method should be favored over resize() for making a range empty.

Definition at line 171 of file rangemap.h.

References Range< T >::clear(), Range< T >::empty(), Range< T >::r_first, Range< T >::r_last, and Range< T >::relaxed_first().

◆ split_range_at()

template<class T >
Pair Range< T >::split_range_at ( const Value &  at) const
inline

Split a range into two parts.

Returns a pair of adjacent ranges such that at is the first value of the second returned range. The split point must be such that neither range is empty.

Definition at line 184 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::last().

Referenced by RangeMap< R, T >::contains(), and RangeMap< R, T >::erase().

◆ join()

template<class T >
Range Range< T >::join ( const Range< T > &  right) const
inline

Joins two adjacent ranges.

This range must be the left range, and the argument is the right range. They must be adjacent without overlapping. If one of the ranges is empty, then the return value is the other range (which might also be empty).

Definition at line 195 of file rangemap.h.

References Range< T >::abuts_lt(), Range< T >::empty(), Range< T >::first(), Range< T >::inin(), and Range< T >::last().

Referenced by RangeMap< R, T >::insert().

◆ erase()

template<class T >
std::vector< Range > Range< T >::erase ( const Range< T > &  to_erase) const
inline

Erase part of a range to return zero, one, or two new ranges.

The possible situations are:

  1. The range to erase can be a superset of this range, in which case this entire range is erased and nothing is returned.
  2. The range to erase can be empty, in which case this range is returned.
  3. The range to erase does not intersect this range, in which case this range is returned.
  4. The range to erase can overlap the low end of this range, in which case only the non-overlapping high end of this range is returned.
  5. The range to erase can overlap the high end of this range, in which case only the non-overlapping low end of this range is returned.
  6. The range to erase overlaps only the middle part of this range, in which case two ranges are returned: the non-overlapping low end of this range, and the non-overlapping high end of this range.

Definition at line 218 of file rangemap.h.

References Range< T >::begins_before(), Range< T >::contained_in(), Range< T >::distinct(), Range< T >::empty(), Range< T >::ends_after(), Range< T >::first(), Range< T >::first(), Range< T >::inin(), Range< T >::last(), and Range< T >::last().

Referenced by RangeMap< R, T >::insert().

◆ intersect()

template<class T >
Range Range< T >::intersect ( const Range< T > &  other) const
inline

◆ empty()

template<class T >
bool Range< T >::empty ( ) const
inline

◆ clear()

template<class T >
void Range< T >::clear ( )
inline

Make a range empty.

An empty range is one in which r_first is greater than r_last. We make special provisions here so that relaxed_first() will continue to return the same value as it did before the range was set to empty.

Definition at line 255 of file rangemap.h.

References Range< T >::empty(), Range< T >::maximum(), Range< T >::r_first, and Range< T >::r_last.

Referenced by Range< T >::Range(), Range< T >::relaxed_resize(), and Range< T >::resize().

◆ begins_with()

template<class T >
bool Range< T >::begins_with ( const Range< T > &  x) const
inline

Do both ranges begin at the same place?

An empty range never begins with any other range, including other empty ranges.

Definition at line 270 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::first().

◆ ends_with()

template<class T >
bool Range< T >::ends_with ( const Range< T > &  x) const
inline

Do both ranges end at the same place?

An empty range never ends with any other range, including other empty ranges.

Definition at line 279 of file rangemap.h.

References Range< T >::empty(), Range< T >::last(), and Range< T >::last().

◆ begins_after()

template<class T >
bool Range< T >::begins_after ( const Range< T > &  x,
bool  strict = true 
) const
inline

Does this range begin (strictly) after the beginning of another range?

An empty range never begins after any other range, including other empty ranges.

Definition at line 288 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::first().

Referenced by RangeMap< R, T >::erase().

◆ begins_before()

template<class T >
bool Range< T >::begins_before ( const Range< T > &  x,
bool  strict = true 
) const
inline

Does this range begin (strictly) before the beginning of another range?

An empty range never begins before any other range, including other empty ranges.

Definition at line 297 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::first().

Referenced by RangeMap< R, T >::contains(), and Range< T >::erase().

◆ ends_after()

template<class T >
bool Range< T >::ends_after ( const Range< T > &  x,
bool  strict = true 
) const
inline

Does this range end (strictly) after the end of another range?

An empty range never ends after any other range, including other empty ranges.

Definition at line 306 of file rangemap.h.

References Range< T >::empty(), Range< T >::last(), and Range< T >::last().

Referenced by Range< T >::erase().

◆ ends_before()

template<class T >
bool Range< T >::ends_before ( const Range< T > &  x,
bool  strict = true 
) const
inline

Does this range end (strictly) before the end of another range?

An empty range never ends before any other range, including other empty ranges.

Definition at line 315 of file rangemap.h.

References Range< T >::empty(), Range< T >::last(), and Range< T >::last().

Referenced by RangeMap< R, T >::contains(), and RangeMap< R, T >::erase().

◆ contains()

template<class T >
bool Range< T >::contains ( const Range< T > &  x,
bool  strict = false 
) const
inline

Does this range contain the argument range?

The argument is contained in this range if the argument starts at or after the start of this range and ends at or before the end of this range. If strict is true, then the comparisons do not include equality. An empty range does not contain any other range, including other empty ranges.

Definition at line 326 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), Range< T >::first(), Range< T >::last(), and Range< T >::last().

Referenced by RangeMap< R, T >::erase(), Range< T >::intersect(), and RangeMapNumeric< R, T >::split().

◆ contained_in()

template<class T >
bool Range< T >::contained_in ( const Range< T > &  x,
bool  strict = false 
) const
inline

Is this range contained in the argument range?

This range is contained in the argument range if this range starts at or after the start of the argument and ends at or before the end of the argument. If strict is true, then the comparisons do not include equality. An empty range does not contain any other range, including other empty ranges.

Definition at line 337 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), Range< T >::first(), Range< T >::last(), and Range< T >::last().

Referenced by RangeMap< R, T >::erase(), and Range< T >::erase().

◆ congruent()

template<class T >
bool Range< T >::congruent ( const Range< T > &  x) const
inline

Are two ranges equal?

They are equal if the start and end at the same place or if they are both empty.

Definition at line 346 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), Range< T >::first(), Range< T >::last(), and Range< T >::last().

◆ left_of()

template<class T >
bool Range< T >::left_of ( const Range< T > &  x) const
inline

Is this range left of the argument range?

This range is left of the argument range if this range ends before the start of the argument. They may adjoin, but must not overlap. An empty range is never left of any other range, including other empty ranges.

Definition at line 356 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::last().

Referenced by RangeMap< R, T >::erase(), RangeMap< R, T >::invert_within(), Range< T >::overlaps(), and RangeMap< R, T >::select_overlapping_ranges().

◆ right_of()

template<class T >
bool Range< T >::right_of ( const Range< T > &  x) const
inline

Is this range right of the argument range?

This range is right of the argument range if this range starts after the end of the argument range. They may adjoin, but must not overlap. An empty range is never right of any other range, including other empty ranges.

Definition at line 366 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::last().

Referenced by Range< T >::overlaps().

◆ overlaps()

template<class T >
bool Range< T >::overlaps ( const Range< T > &  x) const
inline

Does this range overlap with the argument range?

An empty range does not overlap with any other rance, including other empty ranges.

Definition at line 375 of file rangemap.h.

References Range< T >::empty(), Range< T >::left_of(), and Range< T >::right_of().

Referenced by RangeMap< R, T >::contains(), Range< T >::distinct(), RangeMap< R, T >::insert(), Range< T >::intersect(), RangeMap< R, T >::overlaps(), and RangeMap< R, T >::select_overlapping_ranges().

◆ distinct()

template<class T >
bool Range< T >::distinct ( const Range< T > &  x) const
inline

Is this range non-overlapping with the argument range?

In other words, do the two ranges represent distinct sets of values? An empty range is always distinct from all other ranges (including other empty ranges).

Definition at line 385 of file rangemap.h.

References Range< T >::empty(), and Range< T >::overlaps().

Referenced by Range< T >::erase().

◆ abuts_lt()

template<class T >
bool Range< T >::abuts_lt ( const Range< T > &  x) const
inline

Is this range immediately left of the argument range?

Returns true if this range ends at the beginning of the argument, with no overlap and no space between them. An empty range does not abut any other range, including other empty ranges.

Definition at line 395 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::last().

Referenced by RangeMap< R, T >::insert(), and Range< T >::join().

◆ abuts_gt()

template<class T >
bool Range< T >::abuts_gt ( const Range< T > &  x) const
inline

Is this range immediately right of the argument range?

Returns true if this range begins at the end of the argument, with no overlap and no space between them. An empty range does not abut any other range, including other empty ranges.

Definition at line 405 of file rangemap.h.

References Range< T >::empty(), Range< T >::first(), and Range< T >::last().

Referenced by RangeMap< R, T >::insert().

◆ minimum()

template<class T >
static Value Range< T >::minimum ( )
inlinestatic

Return the minimum possible value represented by this range.

Definition at line 412 of file rangemap.h.

Referenced by Range< T >::all(), and RangeMap< R, T >::insert().

◆ maximum()

template<class T >
static Value Range< T >::maximum ( )
inlinestatic

Return the maximum possible value represented by this range.

Definition at line 417 of file rangemap.h.

Referenced by Range< T >::all(), Range< T >::clear(), and RangeMap< R, T >::insert().

◆ all()

template<class T >
static Range Range< T >::all ( )
inlinestatic

Return a range that covers all possible values.

Definition at line 422 of file rangemap.h.

References Range< T >::inin(), Range< T >::maximum(), and Range< T >::minimum().

Referenced by RangeMap< R, T >::invert().

◆ operator==()

template<class T >
bool Range< T >::operator== ( const Range< T > &  x) const
inline

Definition at line 426 of file rangemap.h.

◆ operator!=()

template<class T >
bool Range< T >::operator!= ( const Range< T > &  x) const
inline

Definition at line 429 of file rangemap.h.

◆ print()

template<class T >
void Range< T >::print ( std::ostream &  o) const
inline

Definition at line 433 of file rangemap.h.

Member Data Documentation

◆ r_first

template<class T >
Value Range< T >::r_first
protected

◆ r_last

template<class T >
Value Range< T >::r_last
protected

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