LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::range_t< SIZE > Class Template Reference

A range (interval) of integers. More...

#include "sparse_vector.h"

Public Types

typedef SIZE size_type
 type for the indices in the range More...
 
typedef std::ptrdiff_t difference_type
 type for index difference More...
 
typedef bool(* less_int_range) (size_type, const range_t &b)
 Helper type to be used for binary searches. More...
 

Public Member Functions

 range_t ()
 Default constructor: empty range. More...
 
 range_t (size_type from, size_type to)
 Constructor from first and last index. More...
 
void set (size_type from, size_type to)
 Sets the borders of the range. More...
 
size_type begin_index () const
 Returns the first absolute index included in the range. More...
 
size_type end_index () const
 Returns the first absolute index not included in the range. More...
 
size_type relative_index (size_type index) const
 Returns the position within the range of the absolute index specified. More...
 
size_type size () const
 Returns the size of the range. More...
 
void resize (size_type new_size)
 Moves the end of the range to fit the specified size. More...
 
void move_head (difference_type shift)
 Moves the begin of the range by the specified amount. More...
 
void move_tail (difference_type shift)
 Moves the end of the range by the specified amount. More...
 
bool empty () const
 Returns whether the range is empty. More...
 
bool includes (size_type index) const
 Returns whether the specified absolute index is included in this range. More...
 
bool includes (const range_t &r) const
 Returns whether the specified range is completely included in this one. More...
 
bool overlap (const range_t &r) const
 Returns if this and the specified range overlap. More...
 
bool separate (const range_t &r) const
 Returns if there are elements in between this and the specified range. More...
 
bool borders (size_type index) const
 Returns whether an index is within or immediately after this range. More...
 
bool operator== (const range_t &as) const
 Returns whether the specified range has our same offset and size. More...
 
bool is_valid () const
 Returns whether the range is valid (that is, non-negative size) More...
 
bool operator< (const range_t &than) const
 Sort: this range is smaller if its offset is smaller. More...
 

Static Public Member Functions

static bool less (const range_t &a, const range_t &b)
 Returns if a is "less" than b. More...
 
static bool less (const range_t &a, size_type b)
 Returns if a is "less" than b. More...
 
static bool less (size_type a, const range_t &b)
 Returns if a is "less" than b. More...
 

Public Attributes

size_type offset
 offset (absolute index) of the first element More...
 
size_type last
 offset (absolute index) after the last element More...
 

Detailed Description

template<typename SIZE>
class lar::range_t< SIZE >

A range (interval) of integers.

Template Parameters
SIZEtype of the indices (expected integral)

Includes a first and an after-the-last value, and some relation metods.

Definition at line 203 of file sparse_vector.h.

Member Typedef Documentation

template<typename SIZE>
typedef std::ptrdiff_t lar::range_t< SIZE >::difference_type

type for index difference

Definition at line 206 of file sparse_vector.h.

template<typename SIZE>
typedef bool(* lar::range_t< SIZE >::less_int_range) (size_type, const range_t &b)

Helper type to be used for binary searches.

Definition at line 296 of file sparse_vector.h.

template<typename SIZE>
typedef SIZE lar::range_t< SIZE >::size_type

type for the indices in the range

Definition at line 205 of file sparse_vector.h.

Constructor & Destructor Documentation

template<typename SIZE>
lar::range_t< SIZE >::range_t ( )
inline

Default constructor: empty range.

Definition at line 214 of file sparse_vector.h.

214 : offset(0), last(0) {}
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
lar::range_t< SIZE >::range_t ( size_type  from,
size_type  to 
)
inline

Constructor from first and last index.

Definition at line 217 of file sparse_vector.h.

217 : offset(from), last(std::max(from, to)) {}
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element

Member Function Documentation

template<typename SIZE>
size_type lar::range_t< SIZE >::begin_index ( ) const
inline

Returns the first absolute index included in the range.

Definition at line 227 of file sparse_vector.h.

Referenced by lar::range_t< size_type >::includes(), lar::range_t< size_type >::overlap(), hit::HitAnaAlg::ProcessROI(), hit::HitAnaAlg::ROIInfo(), lar::range_t< size_type >::separate(), lar::sparse_vector< T >::should_merge(), and lar::sparse_vector< T >::unset_at().

227 { return offset; }
size_type offset
offset (absolute index) of the first element
template<typename SIZE>
bool lar::range_t< SIZE >::borders ( size_type  index) const
inline

Returns whether an index is within or immediately after this range.

Returns whether the specified absolute index is included in this range or is immediately after it (not before it!)

Definition at line 275 of file sparse_vector.h.

275 { return (index >= offset) && (index <= last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::empty ( ) const
inline

Returns whether the range is empty.

Definition at line 248 of file sparse_vector.h.

248 { return last <= offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
size_type lar::range_t< SIZE >::end_index ( ) const
inline

Returns the first absolute index not included in the range.

Definition at line 230 of file sparse_vector.h.

Referenced by lar::range_t< size_type >::includes(), lar::sparse_vector< T >::operator[](), lar::range_t< size_type >::overlap(), lar::range_t< size_type >::separate(), lar::sparse_vector< T >::set_at(), and lar::sparse_vector< T >::unset_at().

230 { return last; }
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::includes ( size_type  index) const
inline

Returns whether the specified absolute index is included in this range.

Definition at line 251 of file sparse_vector.h.

251 { return (index >= offset) && (index < last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::includes ( const range_t< SIZE > &  r) const
inline

Returns whether the specified range is completely included in this one.

Definition at line 254 of file sparse_vector.h.

255  {
256  return includes(r.begin_index()) && includes(r.end_index());
257  }
TRandom r
Definition: spectrum.C:23
bool includes(size_type index) const
Returns whether the specified absolute index is included in this range.
template<typename SIZE>
bool lar::range_t< SIZE >::is_valid ( ) const
inline

Returns whether the range is valid (that is, non-negative size)

Definition at line 286 of file sparse_vector.h.

286 { return last >= offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
static bool lar::range_t< SIZE >::less ( const range_t< SIZE > &  a,
const range_t< SIZE > &  b 
)
inlinestatic

Returns if a is "less" than b.

Definition at line 290 of file sparse_vector.h.

290 { return a.offset < b.offset; }
template<typename SIZE>
static bool lar::range_t< SIZE >::less ( const range_t< SIZE > &  a,
size_type  b 
)
inlinestatic

Returns if a is "less" than b.

Definition at line 291 of file sparse_vector.h.

291 { return a.offset < b; }
template<typename SIZE>
static bool lar::range_t< SIZE >::less ( size_type  a,
const range_t< SIZE > &  b 
)
inlinestatic

Returns if a is "less" than b.

Definition at line 292 of file sparse_vector.h.

292 { return a < b.offset; }
template<typename SIZE>
void lar::range_t< SIZE >::move_head ( difference_type  shift)
inline

Moves the begin of the range by the specified amount.

Definition at line 242 of file sparse_vector.h.

242 { offset += shift; }
size_type offset
offset (absolute index) of the first element
template<typename SIZE>
void lar::range_t< SIZE >::move_tail ( difference_type  shift)
inline

Moves the end of the range by the specified amount.

Definition at line 245 of file sparse_vector.h.

245 { last += shift; }
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::operator< ( const range_t< SIZE > &  than) const
inline

Sort: this range is smaller if its offset is smaller.

Definition at line 279 of file sparse_vector.h.

279 { return less(*this, than); }
static bool less(const range_t &a, const range_t &b)
Returns if a is "less" than b.
template<typename SIZE>
bool lar::range_t< SIZE >::operator== ( const range_t< SIZE > &  as) const
inline

Returns whether the specified range has our same offset and size.

Definition at line 283 of file sparse_vector.h.

283 { return (offset == as.offset) && (last == as.last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::overlap ( const range_t< SIZE > &  r) const
inline

Returns if this and the specified range overlap.

Definition at line 260 of file sparse_vector.h.

261  {
262  return (begin_index() < r.end_index()) && (end_index() > r.begin_index());
263  }
TRandom r
Definition: spectrum.C:23
size_type begin_index() const
Returns the first absolute index included in the range.
size_type end_index() const
Returns the first absolute index not included in the range.
template<typename SIZE>
size_type lar::range_t< SIZE >::relative_index ( size_type  index) const
inline

Returns the position within the range of the absolute index specified.

Definition at line 233 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::unset_at().

233 { return index - offset; }
size_type offset
offset (absolute index) of the first element
template<typename SIZE>
void lar::range_t< SIZE >::resize ( size_type  new_size)
inline

Moves the end of the range to fit the specified size.

Definition at line 239 of file sparse_vector.h.

239 { last = offset + new_size; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
bool lar::range_t< SIZE >::separate ( const range_t< SIZE > &  r) const
inline

Returns if there are elements in between this and the specified range.

Definition at line 266 of file sparse_vector.h.

267  {
268  return (begin_index() > r.end_index()) || (end_index() < r.begin_index());
269  }
TRandom r
Definition: spectrum.C:23
size_type begin_index() const
Returns the first absolute index included in the range.
size_type end_index() const
Returns the first absolute index not included in the range.
template<typename SIZE>
void lar::range_t< SIZE >::set ( size_type  from,
size_type  to 
)
inline

Sets the borders of the range.

Definition at line 220 of file sparse_vector.h.

221  {
222  offset = from;
223  last = std::max(from, to);
224  }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename SIZE>
size_type lar::range_t< SIZE >::size ( ) const
inline

Returns the size of the range.

Definition at line 236 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::count(), hit::HitAnaAlg::ProcessROI(), lar::sparse_vector< T >::should_merge(), and lar::sparse_vector< T >::unset_at().

236 { return last - offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element

Member Data Documentation

template<typename SIZE>
size_type lar::range_t< SIZE >::last

offset (absolute index) after the last element

Definition at line 211 of file sparse_vector.h.

Referenced by lar::range_t< size_type >::operator==().

template<typename SIZE>
size_type lar::range_t< SIZE >::offset

offset (absolute index) of the first element

Definition at line 208 of file sparse_vector.h.

Referenced by lar::range_t< size_type >::is_valid(), lar::range_t< size_type >::less(), and lar::range_t< size_type >::operator==().


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