LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
|
A sparse vector. More...
#include "sparse_vector.h"
Classes | |
class | const_iterator |
Iterator to the sparse vector values. More... | |
class | const_reference |
Special little box to allow void elements to be treated as references. More... | |
class | datarange_t |
Range class, with range and data. More... | |
class | iterator |
Iterator to the sparse vector values. More... | |
class | reference |
A class representing a cell in a sparse vector. More... | |
Public Types | |
typedef T | value_type |
type of the stored values More... | |
typedef std::vector< value_type > | vector_t |
type of STL vector holding this data More... | |
typedef vector_t::size_type | size_type |
size type More... | |
typedef vector_t::difference_type | difference_type |
index difference type More... | |
typedef vector_t::pointer | pointer |
typedef vector_t::const_pointer | const_pointer |
typedef std::vector< datarange_t > | range_list_t |
type of sparse vector data More... | |
typedef range_list_t::iterator | range_iterator |
type of iterator over ranges More... | |
typedef range_list_t::const_iterator | range_const_iterator |
type of constant iterator over ranges More... | |
Public Member Functions | |
sparse_vector () | |
Default constructor: an empty vector. More... | |
sparse_vector (size_type new_size) | |
Constructor: a vector with new_size elements in the void. More... | |
sparse_vector (const vector_t &from, size_type offset=0) | |
Constructor: a solid vector from an existing STL vector. More... | |
sparse_vector (sparse_vector const &)=default | |
Copy constructor: default. More... | |
sparse_vector (sparse_vector &&from) | |
Move constructor. More... | |
sparse_vector & | operator= (sparse_vector const &)=default |
Copy assignment: default. More... | |
sparse_vector & | operator= (sparse_vector &&from) |
Move assignment. More... | |
sparse_vector (vector_t &&from, size_type offset=0) | |
Constructor: a solid vector from an existing STL vector. More... | |
~sparse_vector ()=default | |
Destructor: default. More... | |
void | clear () |
Removes all the data, making the vector empty. More... | |
size_type | size () const |
Returns the size of the vector. More... | |
bool | empty () const |
Returns whether the vector is empty. More... | |
size_type | capacity () const |
Returns the capacity of the vector (compatibility only) More... | |
value_type | operator[] (size_type index) const |
Access to an element (read only) More... | |
reference | operator[] (size_type index) |
Access to an element (read/write for non-void elements only!) More... | |
void | make_void_around (size_type index) |
Casts the whole range with the specified item into the void. More... | |
bool | is_valid () const |
Returns if the vector is in a valid state. More... | |
void | make_void (iterator first, iterator last) |
Makes all the elements from first and before last void. More... | |
template<typename ITER > | |
const lar::sparse_vector< T >::datarange_t & | add_range (size_type offset, ITER first, ITER last) |
template<typename ITER , typename OP > | |
auto | combine_range (size_type offset, ITER first, ITER last, OP &&op, value_type void_value) -> const datarange_t & |
void | resize (size_type new_size) |
Resizes the vector to the specified size, adding void. More... | |
void | resize (size_type new_size, value_type def_value) |
Resizes the vector to the specified size, adding def_value. More... | |
iterator | begin () |
Standard iterators interface. More... | |
iterator | end () |
Standard iterators interface. More... | |
const_iterator | begin () const |
Standard iterators interface. More... | |
const_iterator | end () const |
Standard iterators interface. More... | |
const_iterator | cbegin () const |
Standard iterators interface. More... | |
const_iterator | cend () const |
Standard iterators interface. More... | |
Cell test | |
The methods in this group test the single vector cells. | |
bool | is_void (size_type index) const |
Returns whether the specified position is void. More... | |
bool | back_is_void () const |
Returns whether the sparse vector ends with void. More... | |
size_type | count () const |
Returns the number of non-void cells. More... | |
Cell set | |
The methods in this group access and/or change the cell values. | |
value_type & | set_at (size_type index, value_type value) |
Writes into an element (creating or expanding a range if needed) More... | |
void | unset_at (size_type index) |
Casts the element with the specified index into the void. More... | |
void | push_back (value_type value) |
void | push_back (value_type value, value_type thr) |
Adds one element to the end of the vector (if zero, just adds void) More... | |
template<typename ITER > | |
void | assign (ITER first, ITER last) |
Copies data from a sequence between two iterators. More... | |
template<typename CONT > | |
void | assign (const CONT &new_data) |
Copies data from a container. More... | |
void | assign (vector_t &&new_data) |
Moves data from a vector. More... | |
Ranges | |
A range is a region of the sparse vector which contains all non-void values. | |
const range_list_t & | get_ranges () const |
Returns the internal list of non-void ranges. More... | |
size_type | n_ranges () const |
Returns the internal list of non-void ranges. More... | |
const datarange_t & | range (size_t i) const |
Returns the i-th non-void range (zero-based) More... | |
range_const_iterator | begin_range () const |
Returns a constant iterator to the first data range. More... | |
range_const_iterator | end_range () const |
Returns a constant iterator to after the last data range. More... | |
range_const_iterator | find_range_iterator (size_type index) const |
Returns an iterator to the range containing the specified index. More... | |
range_iterator | find_range_iterator (size_type index) |
Returns the internal list of non-void ranges. More... | |
const datarange_t & | find_range (size_type index) const |
Returns the range containing the specified index. More... | |
datarange_t & | find_range (size_type index) |
Returns the range containing the specified index. More... | |
template<typename ITER > | |
const datarange_t & | add_range (size_type offset, ITER first, ITER last) |
Adds a sequence of elements as a range with specified offset. More... | |
template<typename CONT > | |
const datarange_t & | add_range (size_type offset, const CONT &new_data) |
Copies the elements in container to a range with specified offset. More... | |
const datarange_t & | add_range (size_type offset, vector_t &&new_data) |
Adds a sequence of elements as a range with specified offset. More... | |
template<typename ITER , typename OP > | |
const datarange_t & | combine_range (size_type offset, ITER first, ITER last, OP &&op, value_type void_value=value_zero) |
Combines a sequence of elements as a range with data at offset . More... | |
template<typename CONT , typename OP > | |
const datarange_t & | combine_range (size_type offset, const CONT &other, OP &&op, value_type void_value=value_zero) |
Combines the elements in container with the data at offset . More... | |
template<typename ITER > | |
const datarange_t & | append (ITER first, ITER last) |
Adds a sequence of elements as a range at the end of the vector. More... | |
template<typename CONT > | |
const datarange_t & | append (const CONT &range_data) |
Adds a sequence of elements as a range at the end of the vector. More... | |
const datarange_t & | append (vector_t &&range_data) |
Adds a sequence of elements as a range at the end of the vector. More... | |
void | void_range (range_iterator iRange) |
Turns the specified range into void. More... | |
void | void_range (size_t iRange) |
Turns the specified range into void. More... | |
bool | optimize () |
Performs internal optimization, returns whether the object was changed. More... | |
bool | optimize (size_t) |
Performs internal optimization, returns whether the object was changed. More... | |
Static Public Member Functions | |
Static members related to data size and optimization | |
static size_t | expected_vector_size (size_t size) |
Returns the expected size taken by a vector of specified size. More... | |
static size_t | min_gap () |
Minimum optimal gap between ranges (a guess) More... | |
static bool | should_merge (const typename datarange_t::base_t &a, const typename datarange_t::base_t &b) |
Returns if merging the two specified ranges would save memory. More... | |
Protected Member Functions | |
size_type | minimum_size () const |
Returns the size determined by the ranges already present. More... | |
range_iterator | eat_range_head (range_iterator iRange, size_t index) |
Voids the starting elements up to index (excluded) of a given range. More... | |
datarange_t & | merge_ranges (range_iterator iRange) |
Merges all the following ranges. More... | |
size_type | fix_size () |
Extends the vector size according to the last range. More... | |
range_iterator | find_next_range_iter (size_type index) |
Returns an iterator to the range after index , or end() if none. More... | |
range_const_iterator | find_next_range_iter (size_type index) const |
Returns an iterator to the range after index , or end() if none. More... | |
range_iterator | find_next_range_iter (size_type index, range_iterator rbegin) |
Returns an iterator to the range after index , or ranges.end() if none. More... | |
range_const_iterator | find_next_range_iter (size_type index, range_const_iterator rbegin) const |
Returns an iterator to the range after index , or ranges.end() if none. More... | |
range_iterator | find_extending_range_iter (size_type index) |
Returns an iterator to the range no earlier than index , or end() if none. More... | |
range_const_iterator | find_extending_range_iter (size_type index) const |
Returns an iterator to the range no earlier than index , or end() if none. More... | |
range_iterator | find_extending_range_iter (size_type index, range_iterator rbegin) |
Returns an iterator to the range after index , or end() if none. More... | |
range_const_iterator | find_extending_range_iter (size_type index, range_const_iterator rbegin) const |
Returns an iterator to the range after index , or end() if none. More... | |
range_iterator | insert_range (range_iterator iInsert, const datarange_t &data) |
Plug a new data range in the specified position; no check performed. More... | |
range_iterator | insert_range (range_iterator iInsert, datarange_t &&data) |
Plug a new data range in the specified position; no check performed. More... | |
Protected Attributes | |
size_type | nominal_size |
current size More... | |
range_list_t | ranges |
list of ranges More... | |
Private Types | |
typedef sparse_vector< T > | this_t |
Static members for dealing with this type of value | |
static constexpr value_type | value_zero {0} |
a representation of 0 More... | |
static value_type | abs (value_type v) |
Returns the module of the specified value. More... | |
static value_type | is_zero (value_type v) |
Returns whether the value is exactly zero. More... | |
static value_type | is_zero (value_type v, value_type thr) |
Returns whether the value is zero below a given threshold. More... | |
static value_type | is_equal (value_type a, value_type b) |
Returns whether two values are the same. More... | |
static value_type | is_equal (value_type a, value_type b, value_type thr) |
Returns whether two values are the same below a given threshold. More... | |
A sparse vector.
T | type of data stored in the vector |
A sparse_vector is a container of items marked by consecutive indices (that is, a vector like std::vector), where only non-zero elements are actually stored. The implementation is a container of ranges of non-zero consecutive values; the zero elements are effectively not stored in the object, and a zero is returned whenever they are accessed. In the following, the regions of zeros between the non-zero ranges are collectively called "the void".
See sparse_vector_test.cc for examples of usage.
Although some level of dynamic assignment is present, the class is not very flexible and it is best assigned just once, by adding ranges (add_range(); or by push_back(), which is less efficient). While this class mimics a good deal of the STL vector interface, it is not a std::vector and it does not support all the tricks of it.
For the following, let's assume:
Common iteration on all elements. Better to do a constant one. The first two examples print the full content of the sparse vector, void included.
Assign to an existing (not void) element. Assigning to void elements is not supported, and there is no way to make an existing element to become void (assigning 0 will yield to an existing element with value 0).
Assign a value to an element. The element could be in the void; in any case, after this call the element will not be in the void anymore (even if the assigned value is zero; to cast a cell into the void, use unset_at()).
Add the content of buffer starting at the specified position. The last line will attempt to use the buffer directly (only happens if the start of the new range – 20 in the example – is in the void and therefore a new range will be added). The new range is merged with the existing ones when needed, and it overwrites their content in case of overlap. If the specified position is beyond the current end of the sparse vector, the gap will be filled by void.
Add the content of buffer at the end of the sparse vector. The last line will attempt to use the buffer directly (only happens if the end of the sparse vector is in the void and therefore a new range will be added).
Resizes the sparse vector to the specified size. Truncation may occur, in which case the data beyond the new size is removed. If an extension occurs instead, the new area is void.
A sparse vector can be parsed range by range, skipping the void. Each range object itself supports iteration. Neither the content nor the shape of the ranges can be changed this way.
is not supported if the vector is shorter than 11 (similarly to a std::vector too), and not even if the item #10 is currently in the void. This latter could be changed to create a new element/range; this would require to ship the pointer to the container with the reference (the return value of "sv[10]"), just in case an assignment will occur, or to create the element regardless, like for std::map (but this would provoke a disaster if the caller uses the non-constant operator[] for iteration). So far, set_at() is the closest thing to it.
This has no clear meaning. A usage analogous to STL would precede a sequence of push_back's. In that case, we should create a new empty range at the end of the vector, and reserve that. Empty ranges are currently not allowed. A replacement of this pattern is to create a new std::vector
, reserve space for it and fill it, and finally use sparse_vector::append()
. If the end of the vector is void, there will be no performance penalty, otherwise a reserve + copy will happen.
In order to allow for assignment in an item which is currently not void, the non-constant iterators do not dereference directly into a reference to the vector element (which would be non-existent if in the void), but instead into a lightweight object (still called "reference"). These objects are semantically working as references, but they are formally rvalues (i.e., just values, not C++ references), so they can't be assigned to references (like "auto&"). Nevertheless they work as references and assigning to them does change the original value. Currently assigning to void cells is not supported (see above).
Definition at line 457 of file sparse_vector.h.
typedef vector_t::const_pointer lar::sparse_vector< T >::const_pointer |
Definition at line 470 of file sparse_vector.h.
typedef vector_t::difference_type lar::sparse_vector< T >::difference_type |
index difference type
Definition at line 467 of file sparse_vector.h.
typedef vector_t::pointer lar::sparse_vector< T >::pointer |
Definition at line 469 of file sparse_vector.h.
typedef range_list_t::const_iterator lar::sparse_vector< T >::range_const_iterator |
type of constant iterator over ranges
Definition at line 487 of file sparse_vector.h.
typedef range_list_t::iterator lar::sparse_vector< T >::range_iterator |
type of iterator over ranges
Definition at line 485 of file sparse_vector.h.
typedef std::vector<datarange_t> lar::sparse_vector< T >::range_list_t |
type of sparse vector data
Definition at line 480 of file sparse_vector.h.
typedef vector_t::size_type lar::sparse_vector< T >::size_type |
size type
Definition at line 466 of file sparse_vector.h.
|
private |
Definition at line 458 of file sparse_vector.h.
typedef T lar::sparse_vector< T >::value_type |
type of the stored values
Definition at line 463 of file sparse_vector.h.
typedef std::vector<value_type> lar::sparse_vector< T >::vector_t |
type of STL vector holding this data
Definition at line 464 of file sparse_vector.h.
|
inline |
|
inline |
Constructor: a vector with new_size elements in the void.
Definition at line 498 of file sparse_vector.h.
|
inline |
Constructor: a solid vector from an existing STL vector.
from | vector to copy data from |
offset | (default: 0) index the data starts from (preceeded by void) |
Definition at line 506 of file sparse_vector.h.
|
default |
Copy constructor: default.
|
inline |
|
inline |
Constructor: a solid vector from an existing STL vector.
from | vector to move data from |
offset | (default: 0) index the data starts from (preceeded by void) |
Definition at line 536 of file sparse_vector.h.
|
default |
Destructor: default.
|
inlinestatic |
Returns the module of the specified value.
Definition at line 931 of file sparse_vector.h.
const datarange_t& lar::sparse_vector< T >::add_range | ( | size_type | offset, |
ITER | first, | ||
ITER | last | ||
) |
Adds a sequence of elements as a range with specified offset.
ITER | type of iterator |
offset | where to add the elements |
first | iterator to the first element to be added |
last | iterator after the last element to be added |
If the offset is beyond the current end of the sparse vector, void is added before the new range.
Existing ranges can be merged with the new data if they overlap.
Referenced by lar::sparse_vector< T >::add_range(), lar::sparse_vector< T >::make_void_around(), and butcher::EventButcher::produce().
|
inline |
Copies the elements in container to a range with specified offset.
CONT | type of container supporting the standard begin/end interface |
offset | where to add the elements |
new_data | container holding the data to be copied |
If the offset is beyond the current end of the sparse vector, void is added before the new range.
Existing ranges can be merged with the new data if they overlap.
Definition at line 767 of file sparse_vector.h.
const lar::sparse_vector< T >::datarange_t & lar::sparse_vector< T >::add_range | ( | size_type | offset, |
vector_t && | new_data | ||
) |
Adds a sequence of elements as a range with specified offset.
offset | where to add the elements |
new_data | container holding the data to be moved |
If the offset is beyond the current end of the sparse vector, void is added before the new range.
Existing ranges can be merged with the new data if they overlap. If no merging happens, new_data vector is directly used as the new range added; otherwise, it is just copied.
Definition at line 1746 of file sparse_vector.h.
const lar::sparse_vector<T>::datarange_t& lar::sparse_vector< T >::add_range | ( | size_type | offset, |
ITER | first, | ||
ITER | last | ||
) |
Definition at line 1725 of file sparse_vector.h.
References lar::sparse_vector< T >::add_range().
|
inline |
Adds a sequence of elements as a range at the end of the vector.
first | iterator to the first element to be added |
last | iterator after the last element to be added |
The input range is copied at the end of the sparse vector. If the end of the sparse vector was the end of a range, that range is expanded, otherwise a new one is created.
Definition at line 857 of file sparse_vector.h.
|
inline |
Adds a sequence of elements as a range at the end of the vector.
range_data | contained holding the data to be copied or moved |
The input data is copied at the end of the sparse vector. If the end of the sparse vector was the end of a range, that range is expanded, otherwise a new one is created.
Definition at line 870 of file sparse_vector.h.
|
inline |
Adds a sequence of elements as a range at the end of the vector.
range_data | contained holding the data to be copied or moved |
If there is a range at the end of the sparse vector, it will be expanded with the new data. Otherwise, this method will use the data vector directly as a new range added at the end of the sparse vector.
Definition at line 883 of file sparse_vector.h.
|
inline |
Copies data from a sequence between two iterators.
ITER | type of iterator |
first | iterator pointing to the first element to be copied |
last | iterator pointing after the last element to be copied |
The previous content of the sparse vector is lost.
Definition at line 658 of file sparse_vector.h.
|
inline |
Copies data from a container.
CONT | type of container supporting the standard begin/end interface |
new_data | container with the data to be copied |
The previous content of the sparse vector is lost.
Definition at line 668 of file sparse_vector.h.
|
inline |
Moves data from a vector.
new_data | vector with the data to be moved |
The previous content of the sparse vector is lost.
Definition at line 676 of file sparse_vector.h.
|
inline |
Returns whether the sparse vector ends with void.
Definition at line 601 of file sparse_vector.h.
|
inline |
Standard iterators interface.
Definition at line 1529 of file sparse_vector.h.
References evd::details::begin().
Referenced by operator<<(), and recob::Wire::Signal().
|
inline |
Standard iterators interface.
Definition at line 1538 of file sparse_vector.h.
References evd::details::begin().
|
inline |
Returns a constant iterator to the first data range.
Definition at line 699 of file sparse_vector.h.
|
inline |
Returns the capacity of the vector (compatibility only)
Definition at line 557 of file sparse_vector.h.
|
inline |
Standard iterators interface.
Definition at line 572 of file sparse_vector.h.
|
inline |
|
inline |
const datarange_t& lar::sparse_vector< T >::combine_range | ( | size_type | offset, |
ITER | first, | ||
ITER | last, | ||
OP && | op, | ||
value_type | void_value = value_zero |
||
) |
Combines a sequence of elements as a range with data at offset
.
ITER | type of iterator |
OP | combination operation |
offset | where to add the elements |
first | iterator to the first element to be added |
last | iterator after the last element to be added |
op | operation to be executed element by element |
void_value | (default: value_zero ) the value to use for void cells |
This is a more generic version of add_range()
, where instead of replacing the target data with the data in [ first
, last
[, the existing data is combined with the one in that interval. The operation op
is a binary operation with signature equivalent to Data_t op(Data_t, Data_t)
, and the operation is equivalent to v[i + offset] = op(v[i + offset], *(first + offset))
: op
is a binary operation whose first operand is the existing value and the second one is the one being provided. If the cell i + offset
is currently void, it will be created and the value used in the combination will be void_value
.
If the offset is beyond the current end of the sparse vector, void is added before the new range.
Existing ranges can be merged with the new data if they overlap.
|
inline |
Combines the elements in container with the data at offset
.
CONT | type of container supporting the standard begin/end interface |
OP | combination operation |
offset | where to add the elements |
other | container holding the data to be combined |
op | operation to be executed element by element |
void_value | (default: value_zero ) the value to use for void cells |
combine_range()
This is equivalent to combine_range(size_type, ITER, ITER, OP, Data_t)
using as the new data range the full content of other
container.
Definition at line 835 of file sparse_vector.h.
auto lar::sparse_vector< T >::combine_range | ( | size_type | offset, |
ITER | first, | ||
ITER | last, | ||
OP && | op, | ||
value_type | void_value | ||
) | -> const datarange_t& |
Definition at line 1773 of file sparse_vector.h.
References evd::details::end(), and lar::sparse_vector< T >::datarange_t::get_iterator().
|
inline |
Returns the number of non-void cells.
Definition at line 1596 of file sparse_vector.h.
References s, lar::sparse_vector< T >::set_at(), and lar::range_t< SIZE >::size().
|
protected |
Voids the starting elements up to index (excluded) of a given range.
Definition at line 1997 of file sparse_vector.h.
Referenced by lar::sparse_vector< T >::merge_ranges().
|
inline |
Returns whether the vector is empty.
Definition at line 554 of file sparse_vector.h.
|
inline |
Standard iterators interface.
Definition at line 1533 of file sparse_vector.h.
References evd::details::end().
Referenced by operator<<(), and recob::Wire::Signal().
|
inline |
Standard iterators interface.
Definition at line 1543 of file sparse_vector.h.
References evd::details::end().
|
inline |
Returns a constant iterator to after the last data range.
Definition at line 702 of file sparse_vector.h.
|
inlinestatic |
Returns the expected size taken by a vector of specified size.
Definition at line 2017 of file sparse_vector.h.
References max.
|
inlineprotected |
Returns an iterator to the range no earlier than index
, or end()
if none.
index | the absolute index |
The returned iterator points to a range that "borders" the specified index, meaning that teh cell at index
is either within the range, or it is the one immediately after that range. If index
is in the middle of the void, though (i.e. if the previous cell is void), the next range is returned instead. Finally, if there is no next range, end_range()
is returned.
The result may be also interpreted as follow: if the start of the returned range is lower than index
, then the cell at index
belongs to that range. Otherwise, it initiates its own range (but that range might end up being contiguous to the next(.
Definition at line 1015 of file sparse_vector.h.
Referenced by lar::sparse_vector< T >::find_extending_range_iter(), and lar::sparse_vector< T >::find_next_range_iter().
|
inlineprotected |
Returns an iterator to the range no earlier than index
, or end()
if none.
index | the absolute index |
The returned iterator points to a range that "borders" the specified index, meaning that teh cell at index
is either within the range, or it is the one immediately after that range. If index
is in the middle of the void, though (i.e. if the previous cell is void), the next range is returned instead. Finally, if there is no next range, end_range()
is returned.
The result may be also interpreted as follow: if the start of the returned range is lower than index
, then the cell at index
belongs to that range. Otherwise, it initiates its own range (but that range might end up being contiguous to the next(.
Definition at line 1017 of file sparse_vector.h.
|
protected |
Returns an iterator to the range after index
, or end()
if none.
index | the absolute index |
rbegin | consider only from this range on |
ranges.end()
if none Definition at line 1952 of file sparse_vector.h.
References lar::sparse_vector< T >::find_extending_range_iter().
|
protected |
Returns an iterator to the range after index
, or end()
if none.
index | the absolute index |
rbegin | consider only from this range on |
ranges.end()
if none Definition at line 1965 of file sparse_vector.h.
References lar::sparse_vector< T >::merge_ranges().
|
inlineprotected |
Returns an iterator to the range after index
, or end()
if none.
index | the absolute index |
Definition at line 977 of file sparse_vector.h.
Referenced by lar::sparse_vector< T >::find_next_range_iter(), and lar::sparse_vector< T >::is_valid().
|
inlineprotected |
Returns an iterator to the range after index
, or end()
if none.
index | the absolute index |
Definition at line 979 of file sparse_vector.h.
|
protected |
Returns an iterator to the range after index
, or ranges.end()
if none.
index | the absolute index |
rbegin | consider only from this range on |
ranges.end()
if none Definition at line 1927 of file sparse_vector.h.
References lar::sparse_vector< T >::find_next_range_iter().
|
protected |
Returns an iterator to the range after index
, or ranges.end()
if none.
index | the absolute index |
rbegin | consider only from this range on |
ranges.end()
if none Definition at line 1939 of file sparse_vector.h.
References lar::sparse_vector< T >::find_extending_range_iter().
const lar::sparse_vector< T >::datarange_t & lar::sparse_vector< T >::find_range | ( | size_type | index | ) | const |
Returns the range containing the specified index.
index | absolute index of the element to be seeked |
std::out_of_range | if index is in no range (how appropriate!) |
Definition at line 1689 of file sparse_vector.h.
|
inline |
Returns the range containing the specified index.
index | absolute index of the element to be seeked |
std::out_of_range | if index is in no range (how appropriate!) |
Definition at line 1701 of file sparse_vector.h.
lar::sparse_vector< T >::range_const_iterator lar::sparse_vector< T >::find_range_iterator | ( | size_type | index | ) | const |
Returns an iterator to the range containing the specified index.
index | absolute index of the element to be seeked |
std::out_of_range | if index is not in the vector |
Definition at line 1666 of file sparse_vector.h.
|
inline |
Returns the internal list of non-void ranges.
Definition at line 1679 of file sparse_vector.h.
|
protected |
Extends the vector size according to the last range.
Definition at line 2007 of file sparse_vector.h.
References max.
|
inline |
Returns the internal list of non-void ranges.
Definition at line 690 of file sparse_vector.h.
Referenced by hit::HitAnaAlg::FillWireInfo(), hit::GausHitFinder::produce(), and hit::DPRawHitFinder::produce().
|
inlineprotected |
Plug a new data range in the specified position; no check performed.
Definition at line 1041 of file sparse_vector.h.
|
inlineprotected |
Plug a new data range in the specified position; no check performed.
Definition at line 1043 of file sparse_vector.h.
|
inlinestatic |
Returns whether two values are the same.
Definition at line 941 of file sparse_vector.h.
|
inlinestatic |
Returns whether two values are the same below a given threshold.
Definition at line 945 of file sparse_vector.h.
bool lar::sparse_vector< T >::is_valid | ( | ) | const |
Returns if the vector is in a valid state.
The vector is in a valid state if:
Definition at line 1903 of file sparse_vector.h.
References lar::sparse_vector< T >::find_next_range_iter().
bool lar::sparse_vector< T >::is_void | ( | size_type | index | ) | const |
Returns whether the specified position is void.
index | position of the cell to be tested |
out_of_range | if index is not in the vector |
Definition at line 1585 of file sparse_vector.h.
|
inlinestatic |
Returns whether the value is exactly zero.
Definition at line 934 of file sparse_vector.h.
|
inlinestatic |
Returns whether the value is zero below a given threshold.
Definition at line 937 of file sparse_vector.h.
void lar::sparse_vector< T >::make_void | ( | iterator | first, |
iterator | last | ||
) |
Makes all the elements from first and before last void.
Definition at line 1854 of file sparse_vector.h.
References lar::sparse_vector< T >::const_iterator::cont, lar::sparse_vector< T >::const_iterator::get_current_range(), and lar::sparse_vector< T >::const_iterator::index.
void lar::sparse_vector< T >::make_void_around | ( | size_type | index | ) |
Casts the whole range with the specified item into the void.
index | absolute index of the element whose range is cast to void |
std::out_of_range | if index is not in the vector |
Definition at line 1709 of file sparse_vector.h.
References lar::sparse_vector< T >::add_range().
|
protected |
Merges all the following ranges.
Definition at line 1977 of file sparse_vector.h.
References lar::sparse_vector< T >::eat_range_head(), and lar::sparse_vector< T >::datarange_t::extend().
Referenced by lar::sparse_vector< T >::find_extending_range_iter().
|
inlinestatic |
|
inlineprotected |
Returns the size determined by the ranges already present.
Definition at line 1036 of file sparse_vector.h.
|
inline |
|
default |
Copy assignment: default.
|
inline |
lar::sparse_vector< T >::value_type lar::sparse_vector< T >::operator[] | ( | size_type | index | ) | const |
Access to an element (read only)
Definition at line 1548 of file sparse_vector.h.
References lar::range_t< SIZE >::end_index().
lar::sparse_vector< T >::reference lar::sparse_vector< T >::operator[] | ( | size_type | index | ) |
Access to an element (read/write for non-void elements only!)
Definition at line 1567 of file sparse_vector.h.
References lar::range_t< SIZE >::end_index().
|
inline |
Performs internal optimization, returns whether the object was changed.
Definition at line 921 of file sparse_vector.h.
|
inline |
Performs internal optimization, returns whether the object was changed.
Definition at line 922 of file sparse_vector.h.
|
inline |
Adds one element to the end of the vector (zero values too)
value | value to be added |
Definition at line 631 of file sparse_vector.h.
|
inline |
Adds one element to the end of the vector (if zero, just adds void)
value | value to be added |
thr | threshold below which the value is considered zero |
If the threshold is strictly negative, all values are pushed back
Definition at line 640 of file sparse_vector.h.
|
inline |
void lar::sparse_vector< T >::resize | ( | size_type | new_size | ) |
Resizes the vector to the specified size, adding void.
Definition at line 1488 of file sparse_vector.h.
void lar::sparse_vector< T >::resize | ( | size_type | new_size, |
value_type | def_value | ||
) |
Resizes the vector to the specified size, adding def_value.
Definition at line 1511 of file sparse_vector.h.
lar::sparse_vector< T >::value_type & lar::sparse_vector< T >::set_at | ( | size_type | index, |
value_type | value | ||
) |
Writes into an element (creating or expanding a range if needed)
index | the index of the element to set |
value | the value to be set |
Note that setting the value to zero will not cast the element into void. Use unset_at for that.
Definition at line 1607 of file sparse_vector.h.
References lar::range_t< SIZE >::end_index().
Referenced by lar::sparse_vector< T >::count().
|
inlinestatic |
Returns if merging the two specified ranges would save memory.
Definition at line 2037 of file sparse_vector.h.
References lar::range_t< SIZE >::begin_index(), and lar::range_t< SIZE >::size().
|
inline |
Returns the size of the vector.
Definition at line 551 of file sparse_vector.h.
Referenced by operator<<().
void lar::sparse_vector< T >::unset_at | ( | size_type | index | ) |
Casts the element with the specified index into the void.
Definition at line 1628 of file sparse_vector.h.
References lar::sparse_vector< T >::datarange_t::begin(), lar::range_t< SIZE >::begin_index(), lar::sparse_vector< T >::datarange_t::end(), lar::range_t< SIZE >::end_index(), lar::sparse_vector< T >::datarange_t::move_head(), lar::sparse_vector< T >::datarange_t::move_tail(), lar::range_t< SIZE >::relative_index(), and lar::range_t< SIZE >::size().
|
inline |
Turns the specified range into void.
iRange | iterator or index of range to be deleted |
Definition at line 894 of file sparse_vector.h.
|
inline |
Turns the specified range into void.
iRange | iterator or index of range to be deleted |
Definition at line 895 of file sparse_vector.h.
|
protected |
current size
Definition at line 967 of file sparse_vector.h.
|
protected |
list of ranges
Definition at line 968 of file sparse_vector.h.
|
static |
a representation of 0
Definition at line 928 of file sparse_vector.h.