LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::DiscreteRange< T > Class Template Reference

#include <DiscreteRange.h>

Collaboration diagram for swoc::DiscreteRange< T >:
Collaboration graph

Classes

struct  lexicographic_order
 

Public Types

using metric_type = T
 Export metric type.
 
using Relation = DiscreteRangeRelation
 Import type for convenience.
 
using EdgeRelation = DiscreteRangeEdgeRelation
 Import type for convenience.
 

Public Member Functions

constexpr DiscreteRange ()
 
constexpr DiscreteRange (T const &value)
 
constexpr DiscreteRange (T const &min, T const &max)
 
bool empty () const
 
self_typeassign (metric_type const &min, metric_type const &max)
 
self_typeassign (metric_type const &value)
 
self_typeassign_min (metric_type const &min)
 
self_typeassign_max (metric_type const &max)
 
self_typeclip_max ()
 
metric_type const & min () const
 
metric_type const & max () const
 
bool operator== (self_type const &that) const
 Equality.
 
bool operator!= (self_type const &that) const
 Inequality.
 
bool contains (metric_type const &value) const
 
bool has_intersection_with (self_type const &that) const
 
self_type intersection (self_type const &that) const
 
bool is_adjacent_to (self_type const &that) const
 
bool is_left_adjacent_to (self_type const &that) const
 
bool has_union (self_type const &that) const
 
bool is_superset_of (self_type const &that) const
 
bool is_subset_of (self_type const &that) const
 
bool is_strict_superset_of (self_type const &that) const
 
bool is_strict_subset_of (self_type const &that) const
 
Relation relationship (self_type const &that) const
 
EdgeRelation left_edge_relationship (self_type const &that) const
 
self_type hull (self_type const &that) const
 
bool is_singleton () const
 Check if the interval is exactly one element.
 
bool operator! () const
 
 operator bool () const
 
bool is_maximal () const
 
self_typeoperator&= (self_type const &that)
 
self_typeoperator|= (self_type const &that)
 
self_typeclear ()
 Make the range empty.
 

Protected Attributes

_min
 The minimum value in the interval.
 
_max
 the maximum value in the interval
 

Related Symbols

(Note that these are not member symbols.)

template<typename T>
bool operator!= (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 
template<typename T>
bool operator^ (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 
template<typename T>
bool operator< (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 
template<typename T>
bool operator<= (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 
template<typename T>
bool operator> (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 
template<typename T>
bool operator>= (DiscreteRange< T > const &lhs, DiscreteRange< T > const &rhs)
 

Detailed Description

template<typename T>
class swoc::DiscreteRange< T >

A range over a discrete finite value metric.

Template Parameters
TThe type for the range values.

The template argument T is presumed to

  • be completely ordered.
  • have prefix increment and decrement operators
  • equality operator
  • have value semantics
  • have minimum and maximum values either
    • members MIN and MAX that define static instances
    • std::numeric_limits<T> support.

The interval is always an inclusive (closed) contiguous interval, defined by the minimum and maximum values contained in the interval. An interval can be empty and contain no values. This is the state of a default constructed interval.

Definition at line 139 of file DiscreteRange.h.

Member Typedef Documentation

◆ EdgeRelation

template<typename T>
using swoc::DiscreteRange< T >::EdgeRelation = DiscreteRangeEdgeRelation

Import type for convenience.

Definition at line 149 of file DiscreteRange.h.

◆ metric_type

template<typename T>
using swoc::DiscreteRange< T >::metric_type = T

Export metric type.

Definition at line 147 of file DiscreteRange.h.

◆ Relation

template<typename T>
using swoc::DiscreteRange< T >::Relation = DiscreteRangeRelation

Import type for convenience.

Definition at line 148 of file DiscreteRange.h.

Constructor & Destructor Documentation

◆ DiscreteRange() [1/3]

template<typename T>
swoc::DiscreteRange< T >::DiscreteRange ( )
inlineconstexpr

Default constructor. An invalid (empty) range is constructed.

Definition at line 154 of file DiscreteRange.h.

◆ DiscreteRange() [2/3]

template<typename T>
swoc::DiscreteRange< T >::DiscreteRange ( T const & value)
inlineconstexpr

Construct a singleton range.

Parameters
valueSingle value to be contained by the interval.
Note
Not marked explicit and so serves as a conversion from scalar values to an interval.

Definition at line 161 of file DiscreteRange.h.

◆ DiscreteRange() [3/3]

template<typename T>
swoc::DiscreteRange< T >::DiscreteRange ( T const & min,
T const & max )
inlineconstexpr

Constructor.

Parameters
minMinimum value in the interval.
maxMaximum value in the interval.

Definition at line 168 of file DiscreteRange.h.

Member Function Documentation

◆ assign() [1/2]

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::assign ( metric_type const & min,
metric_type const & max )

Update the range.

Parameters
minNew minimum value.
maxNew maximum value.
Returns
this.

Definition at line 443 of file DiscreteRange.h.

◆ assign() [2/2]

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::assign ( metric_type const & value)

Update the range.

Parameters
valueThe new minimum and maximum value.
Returns
this.

The range will contain the single value value.

Definition at line 486 of file DiscreteRange.h.

◆ assign_max()

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::assign_max ( metric_type const & max)

Update the maximum value.

Parameters
maxThe new maximum value.
Returns
this.
Note
No checks are done - this can result in an empty range.

Definition at line 541 of file DiscreteRange.h.

◆ assign_min()

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::assign_min ( metric_type const & min)

Update the minimum value.

Parameters
minThe new minimum value.
Returns
this.
Note
No checks are done - this can result in an empty range.

Definition at line 494 of file DiscreteRange.h.

◆ clear()

template<typename T>
auto swoc::DiscreteRange< T >::clear ( )

Make the range empty.

Definition at line 429 of file DiscreteRange.h.

◆ clip_max()

template<typename T>
auto swoc::DiscreteRange< T >::clip_max ( )

Decrement the maximum value.

Returns
this.
Note
No checks are done, the caller must ensure it is valid to decremented the current maximum.

Definition at line 406 of file DiscreteRange.h.

◆ contains()

template<typename T>
bool swoc::DiscreteRange< T >::contains ( metric_type const & value) const

Check if a value is in this range.

Parameters
valueMetric value to check.
Returns
true if value is in the range, false if not.

Definition at line 423 of file DiscreteRange.h.

◆ empty()

template<typename T>
bool swoc::DiscreteRange< T >::empty ( ) const

Check if there are no values in the range.

Returns
true if the range is empty (contains no values), false if it contains at least one value.

Definition at line 507 of file DiscreteRange.h.

◆ has_intersection_with()

template<typename T>
bool swoc::DiscreteRange< T >::has_intersection_with ( DiscreteRange< T >::self_type const & that) const

Logical intersection.

Returns
true if there is at least one common value in the two intervals, false otherwise.

Definition at line 585 of file DiscreteRange.h.

◆ has_union()

template<typename T>
bool swoc::DiscreteRange< T >::has_union ( DiscreteRange< T >::self_type const & that) const

Valid union.

Parameters
thatRange to compare.
Returns
true if the hull of this and that contains only elements that are also in this or that.

Definition at line 572 of file DiscreteRange.h.

◆ hull()

template<typename T>
DiscreteRange< T > swoc::DiscreteRange< T >::hull ( DiscreteRange< T >::self_type const & that) const

Convex hull.

Returns
The smallest interval that is a superset of this and that.

Definition at line 451 of file DiscreteRange.h.

◆ intersection()

template<typename T>
DiscreteRange< T > swoc::DiscreteRange< T >::intersection ( DiscreteRange< T >::self_type const & that) const

Compute the intersection of two intervals

Returns
The interval consisting of values that are contained by both intervals. The return range is empty if the intervals are disjoint.

Definition at line 616 of file DiscreteRange.h.

◆ is_adjacent_to()

template<typename T>
bool swoc::DiscreteRange< T >::is_adjacent_to ( DiscreteRange< T >::self_type const & that) const

Test for adjacency.

Returns
true if the intervals are adjacent.
Note
Only disjoint intervals can be adjacent.

Definition at line 597 of file DiscreteRange.h.

◆ is_left_adjacent_to()

template<typename T>
bool swoc::DiscreteRange< T >::is_left_adjacent_to ( DiscreteRange< T >::self_type const & that) const

Lower adjacency.

Parameters
thatRange to check for adjacency.
Returns
true if this and @ta that are adjacent and this is less than that.

Definition at line 603 of file DiscreteRange.h.

◆ is_maximal()

template<typename T>
bool swoc::DiscreteRange< T >::is_maximal ( ) const

Maximality.

Returns
true if this range contains every value.

Definition at line 513 of file DiscreteRange.h.

◆ is_singleton()

template<typename T>
bool swoc::DiscreteRange< T >::is_singleton ( ) const

Check if the interval is exactly one element.

Definition at line 501 of file DiscreteRange.h.

◆ is_strict_subset_of()

template<typename T>
bool swoc::DiscreteRange< T >::is_strict_subset_of ( DiscreteRange< T >::self_type const & that) const

Strict subset test.

Returns
true if that contains every value in this and that has at least one value not in this.

Definition at line 548 of file DiscreteRange.h.

◆ is_strict_superset_of()

template<typename T>
bool swoc::DiscreteRange< T >::is_strict_superset_of ( DiscreteRange< T >::self_type const & that) const

Strict superset test.

Returns
true if this contains every value in this and this has at least one value not in that.

Definition at line 519 of file DiscreteRange.h.

◆ is_subset_of()

template<typename T>
bool swoc::DiscreteRange< T >::is_subset_of ( DiscreteRange< T >::self_type const & that) const

Subset test.

Returns
true if every value in this is also in that.

Definition at line 554 of file DiscreteRange.h.

◆ is_superset_of()

template<typename T>
bool swoc::DiscreteRange< T >::is_superset_of ( DiscreteRange< T >::self_type const & that) const

Superset test.

Returns
true if every value in that is also in this.

Definition at line 591 of file DiscreteRange.h.

◆ left_edge_relationship()

template<typename T>
auto swoc::DiscreteRange< T >::left_edge_relationship ( self_type const & that) const

Determine the relationship of the left edge of that with this.

Parameters
thatThe other interval.
Returns
The edge relationship.

This checks the right edge of this against the left edge of that.

  • GAP: that left edge is right of this.
  • ADJ: that left edge is right adjacent to this.
  • OVLP: that left edge is inside this.
  • NONE: that left edge is left of this.

Definition at line 458 of file DiscreteRange.h.

◆ max()

template<typename T>
T const & swoc::DiscreteRange< T >::max ( ) const

Maximum value.

Returns
The maximum value in the range.
Note
The return value is unspecified if the interval is empty.

Definition at line 566 of file DiscreteRange.h.

◆ min()

template<typename T>
T const & swoc::DiscreteRange< T >::min ( ) const

Minimum value.

Returns
the minimum value in the range.
Note
The return value is unspecified if the interval is empty.

Definition at line 560 of file DiscreteRange.h.

◆ operator bool()

template<typename T>
swoc::DiscreteRange< T >::operator bool ( ) const
explicit

Test for non-empty.

Returns
true if there values in the range, false if no values in the range.

Definition at line 417 of file DiscreteRange.h.

◆ operator!()

template<typename T>
bool swoc::DiscreteRange< T >::operator! ( ) const

Test for empty, operator form.

Returns
true if the interval is empty, false otherwise.

Definition at line 413 of file DiscreteRange.h.

◆ operator!=()

template<typename T>
bool swoc::DiscreteRange< T >::operator!= ( DiscreteRange< T >::self_type const & that) const

Inequality.

Definition at line 400 of file DiscreteRange.h.

◆ operator&=()

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::operator&= ( DiscreteRange< T >::self_type const & that)

Clip interval. Remove all element in this interval not in that interval.

Definition at line 578 of file DiscreteRange.h.

◆ operator==()

template<typename T>
bool swoc::DiscreteRange< T >::operator== ( DiscreteRange< T >::self_type const & that) const

Equality.

Definition at line 394 of file DiscreteRange.h.

◆ operator|=()

template<typename T>
DiscreteRange< T > & swoc::DiscreteRange< T >::operator|= ( DiscreteRange< T >::self_type const & that)

Convex hull. Minimally extend this to cover all elements in this and that.

Returns
this.

Definition at line 525 of file DiscreteRange.h.

◆ relationship()

template<typename T>
auto swoc::DiscreteRange< T >::relationship ( self_type const & that) const

Generic relationship.

Returns
The relationship between this and that.

Definition at line 467 of file DiscreteRange.h.

Friends And Related Symbol Documentation

◆ operator!=()

template<typename T>
bool operator!= ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Inequality. Two intervals are equal if their min and max values are equal.

Definition at line 632 of file DiscreteRange.h.

◆ operator<()

template<typename T>
bool operator< ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Containment ordering.

Returns
true if this is a strict subset of rhs.
Note
Equivalent to is_strict_subset.

Definition at line 658 of file DiscreteRange.h.

◆ operator<=()

template<typename T>
bool operator<= ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Containment ordering.

Returns
true if this is a subset of rhs.
Note
Equivalent to is_subset.

Definition at line 669 of file DiscreteRange.h.

◆ operator>()

template<typename T>
bool operator> ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Containment ordering.

Returns
true if this is a strict superset of rhs.
Note
Equivalent to is_strict_superset.

Definition at line 681 of file DiscreteRange.h.

◆ operator>=()

template<typename T>
bool operator>= ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Containment ordering.

Returns
true if this is a superset of rhs.
Note
Equivalent to is_superset.

Definition at line 692 of file DiscreteRange.h.

◆ operator^()

template<typename T>
bool operator^ ( DiscreteRange< T > const & lhs,
DiscreteRange< T > const & rhs )
related

Operator form of logical intersection test for two intervals.

Returns
true if there is at least one common value in the two intervals, false otherwise.
Note
Yeah, a bit ugly, using an operator that is not standardly boolean but
  • There don't seem to be better choices (&&,|| not good)
  • The assymmetry between intersection and union makes for only three natural operators
  • ^ at least looks like "intersects"

Definition at line 648 of file DiscreteRange.h.

Member Data Documentation

◆ _max

template<typename T>
T swoc::DiscreteRange< T >::_max
protected

the maximum value in the interval

Definition at line 144 of file DiscreteRange.h.

◆ _min

template<typename T>
T swoc::DiscreteRange< T >::_min
protected

The minimum value in the interval.

Definition at line 143 of file DiscreteRange.h.


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