LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 186 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 189 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 279 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 188 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 198 of file sparse_vector.h.

198 : 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 201 of file sparse_vector.h.

201  :
202  offset(from), last(std::max(from, to)) {}
size_type offset
offset (absolute index) of the first element
Int_t max
Definition: plot.C:27
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 210 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().

210 { 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 253 of file sparse_vector.h.

254  { 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 231 of file sparse_vector.h.

231 { 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 213 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().

213 { 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 234 of file sparse_vector.h.

235  { 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 238 of file sparse_vector.h.

239  { return includes(r.begin_index()) && includes(r.end_index()); }
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 266 of file sparse_vector.h.

266 { 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 270 of file sparse_vector.h.

271  { 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 272 of file sparse_vector.h.

273  { 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 274 of file sparse_vector.h.

275  { 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 225 of file sparse_vector.h.

225 { 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 228 of file sparse_vector.h.

228 { 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 258 of file sparse_vector.h.

258 { 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 262 of file sparse_vector.h.

263  { 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 242 of file sparse_vector.h.

243  { return (begin_index() < r.end_index()) && (end_index() > r.begin_index()); }
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 216 of file sparse_vector.h.

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

216 { 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 222 of file sparse_vector.h.

222 { 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 246 of file sparse_vector.h.

247  { return (begin_index() > r.end_index()) || (end_index() < r.begin_index()); }
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 206 of file sparse_vector.h.

207  { offset = from; last = std::max(from, to); }
size_type offset
offset (absolute index) of the first element
Int_t max
Definition: plot.C:27
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 219 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().

219 { 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 195 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 192 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: