11 #ifndef LARDATAOBJ_UTILITIES_SPARSE_VECTOR_H 12 #define LARDATAOBJ_UTILITIES_SPARSE_VECTOR_H 24 # include <type_traits> 60 operator const value_type& ()
const {
return value; }
74 typedef std::iterator<std::random_access_iterator_tag, T>
base_t;
79 using typename base_t::value_type;
80 using typename base_t::difference_type;
90 index(offset),
value(new_value) {}
102 this_t
operator++(
int) { this_t copy(*
this); ++index;
return copy; }
108 this_t
operator--(
int) { this_t copy(*
this); --index;
return copy; }
111 this_t&
operator+= (difference_type ofs) { index += ofs;
return *
this; }
114 this_t& operator-= (difference_type ofs) { index -= ofs;
return *
this; }
127 {
return index - iter.
index; }
141 difference_type index{0};
151 template <
typename T>
186 template <
typename SIZE>
203 offset(from), last(
std::
max(from, to)) {}
207 void set(size_type from, size_type to)
208 { offset = from; last =
std::max(from, to); }
220 size_type
size()
const {
return last - offset; }
223 void resize(size_type new_size) { last = offset + new_size; }
226 void move_head(difference_type shift) { offset += shift; }
229 void move_tail(difference_type shift) { last += shift; }
232 bool empty()
const {
return last <= offset; }
236 {
return (index >= offset) && (index < last); }
255 {
return (index >= offset) && (index <= last); }
264 {
return (offset == as.
offset) && (last == as.
last); }
280 typedef bool (*less_int_range)(size_type,
const range_t& b);
457 template <
typename T>
477 class const_reference;
500 { resize(new_size); }
508 nominal_size(0), ranges()
509 { add_range(offset, from.begin(), from.end()); }
516 : nominal_size(from.nominal_size)
517 , ranges(
std::move(from.ranges))
518 { from.nominal_size = 0; }
526 ranges = std::move(from.ranges);
527 nominal_size = from.nominal_size;
528 from.nominal_size = 0;
538 nominal_size(0), ranges()
539 { add_range(offset, std::move(from)); }
548 void clear() { ranges.clear(); nominal_size = 0; }
552 size_type
size()
const {
return nominal_size; }
555 bool empty()
const {
return size() == 0; }
558 size_type
capacity()
const {
return nominal_size; }
561 void resize(size_type new_size);
564 void resize(size_type new_size, value_type def_value);
578 value_type operator[] (size_type index)
const;
581 reference operator[] (size_type index);
597 bool is_void(size_type index)
const;
603 {
return ranges.empty() || (ranges.back().end_index() < size()); }
607 size_type count()
const;
624 value_type& set_at(size_type index, value_type
value);
627 void unset_at(size_type index);
630 void push_back(value_type value) { resize(size() + 1, value); }
643 if (is_zero(value, thr)) resize(size() + 1);
644 else push_back(value);
658 template <
typename ITER>
659 void assign(ITER first, ITER last) {
clear(); append(first, last); }
668 template <
typename CONT>
677 void assign(vector_t&& new_data) {
clear(); append(std::move(new_data)); }
694 size_type
n_ranges()
const {
return ranges.size(); }
697 const datarange_t&
range(
size_t i)
const {
return ranges[i]; }
700 range_const_iterator
begin_range()
const {
return ranges.begin(); }
703 range_const_iterator
end_range()
const {
return ranges.end(); }
714 range_const_iterator find_range_iterator(size_type index)
const;
715 range_iterator find_range_iterator(size_type index);
726 const datarange_t& find_range(size_type index)
const;
727 datarange_t& find_range(size_type index);
736 void make_void_around(size_type index);
752 template <
typename ITER>
753 const datarange_t& add_range(size_type offset, ITER first, ITER last);
767 template <
typename CONT>
768 const datarange_t&
add_range(size_type offset,
const CONT& new_data)
769 {
return add_range(offset, new_data.begin(), new_data.end()); }
784 const datarange_t& add_range(size_type offset, vector_t&& new_data);
798 template <
typename ITER>
799 const datarange_t&
append(ITER first, ITER last)
800 {
return add_range(size(), first, last); }
811 template <
typename CONT>
812 const datarange_t&
append(
const CONT& range_data)
813 {
return add_range(size(), range_data); }
825 const datarange_t&
append(vector_t&& range_data)
826 {
return add_range(size(), std::move(range_data)); }
836 void void_range(range_iterator iRange) { ranges.erase(iRange); }
837 void void_range(
size_t iRange) { ranges.erase(ranges.begin() + iRange); }
862 bool optimize() {
return optimize(min_gap()); }
870 static constexpr value_type value_zero{0};
873 static value_type
abs(value_type v) {
return (v < value_zero)? -v: v; }
876 static value_type
is_zero(value_type v) {
return v == value_zero; }
879 static value_type
is_zero(value_type v, value_type thr)
880 {
return abs(v - value_zero) <= thr; }
883 static value_type
is_equal(value_type a, value_type b)
884 {
return is_zero(abs(a - b)); }
887 static value_type
is_equal(value_type a, value_type b, value_type thr)
888 {
return is_zero(abs(a - b), thr); }
894 static size_t expected_vector_size(
size_t size);
897 static size_t min_gap();
900 static bool should_merge(
901 const typename datarange_t::base_t& a,
902 const typename datarange_t::base_t& b
920 {
return find_next_range_iter(index, ranges.begin()); }
922 {
return find_next_range_iter(index, ranges.begin()); }
932 range_iterator find_next_range_iter(size_type index, range_iterator rbegin);
933 range_const_iterator find_next_range_iter
934 (size_type index, range_const_iterator rbegin)
const;
939 {
return ranges.empty()? 0: ranges.back().end_index(); }
942 range_iterator insert_range(range_iterator iInsert,
const datarange_t& data)
944 {
return data.empty()? iInsert: ranges.insert(iInsert, data); }
945 range_iterator
insert_range(range_iterator iInsert, datarange_t&& data)
946 {
return data.empty()? iInsert: ranges.insert(iInsert, std::move(data)); }
950 range_iterator eat_range_head(range_iterator iRange,
size_t index);
953 datarange_t& merge_ranges(range_iterator iRange);
956 size_type fix_size();
978 template <
typename T>
979 std::ostream& operator<< (std::ostream& out, const lar::sparse_vector<T>& v);
988 template <
typename T>
1000 datarange_t(
const base_t& range): base_t(range), values(range.size()) {}
1003 template <
typename ITER>
1005 base_t(offset, offset +
std::distance(first, last)),
1011 base_t(offset, offset + data.size()), values(data)
1018 {
return values.begin() + index - base_t::begin_index(); }
1020 {
return values.begin() + index - base_t::begin_index(); }
1024 iterator
begin() {
return values.begin(); }
1026 iterator
end() {
return values.end(); }
1027 const_iterator
begin()
const {
return values.begin(); }
1028 const_iterator
end()
const {
return values.end(); }
1029 const_iterator
cbegin()
const {
return values.cbegin(); }
1030 const_iterator
cend()
const {
return values.cend(); }
1034 void resize(
size_t new_size)
1036 { values.resize(new_size); fit_size_from_data(); }
1038 { values.resize(new_size, def_value); fit_size_from_data(); }
1044 {
return values[base_t::relative_index(index)]; }
1046 {
return values[base_t::relative_index(index)]; }
1050 const vector_t& data()
const {
return values; }
1059 template <
typename ITER>
1076 { resize(base_t::relative_index(to_index), def_value); }
1093 template <
typename T>
1101 explicit operator value_type()
const {
return ptr? *ptr: value_zero; }
1103 {
return ptr? *ptr: value_zero; }
1114 template <
typename T>
1128 {
return const_cast<value_type&
>(*const_reference::ptr) = v; }
1133 {
return const_cast<value_type&
>(*const_reference::ptr); }
1143 template <
typename T>
1183 cont(&c), index(
std::
min(offset, c.size())), currentRange()
1184 { refresh_state(); }
1188 cont(&c), index(0), currentRange(c.get_ranges().
begin())
1193 cont(&c), index(c.size()), currentRange(c.get_ranges().
end())
1197 const_reference operator[] (size_type offset)
const 1198 {
return (*cont)[index + offset]; }
1225 {
return (cont == as.
cont) && (index == as.
index); }
1227 {
return (cont != as.
cont) || (index != as.
index); }
1229 {
return (cont == than.
cont) && (index < than.
index); }
1231 {
return (cont == than.
cont) && (index > than.
index); }
1233 {
return (cont == than.
cont) && (index <= than.
index); }
1235 {
return (cont == than.
cont) && (index >= than.
index); }
1277 void refresh_state();
1292 template <
typename T>
1295 friend typename const_iterator::container_t;
1319 {
return (*const_iterator::cont)[const_iterator::index + offset]; }
1342 {
return reference(const_iterator::operator*()); }
1364 template <
typename T>
1369 template <
typename T>
1371 if (new_size >= size()) {
1372 nominal_size = new_size;
1378 ranges.erase(iLastRange, ranges.end());
1379 if (!ranges.empty()) {
1381 if (new_size == iLastRange->begin_index())
1382 ranges.erase(iLastRange);
1383 else if (new_size < iLastRange->end_index())
1384 iLastRange->resize(new_size - iLastRange->begin_index());
1388 nominal_size = new_size;
1392 template <
typename T>
1394 if (new_size == size())
return;
1395 if (new_size > size()) {
1398 append(
vector_t(new_size - size(), def_value));
1400 ranges.back().resize(new_size - ranges.back().begin_index(), def_value);
1402 nominal_size = new_size;
1410 template <
typename T>
1414 template <
typename T>
1418 template <
typename T>
1423 template <
typename T>
1428 template <
typename T>
1437 if (iNextRange == ranges.begin())
return value_zero;
1443 return (index < range.
end_index())? range[index]: value_zero;
1447 template <
typename T>
1456 if (iNextRange == ranges.begin())
return reference();
1466 template <
typename T>
1468 if (ranges.empty() || (index >= size()))
1469 throw std::out_of_range(
"empty sparse vector");
1472 return ((iNextRange == ranges.begin())
1473 || ((--iNextRange)->end_index() <= index));
1477 template <
typename T>
1481 return std::accumulate(begin_range(), end_range(),
size_type(0),
1487 template <
typename T>
1496 if (iNextRange != ranges.begin()) {
1502 if (index < range.
end_index())
return range[index] = value;
1505 return const_cast<datarange_t&
>(add_range(index, { value }))[index];
1509 template <
typename T>
1516 if (iNextRange == ranges.begin())
return;
1525 if (range.
size() == 1) ranges.erase(iNextRange);
1529 else if (index == range.
end_index() - 1)
1536 ranges.emplace(++iNextRange, index + 1,
1546 template <
typename T>
1550 if (ranges.empty())
throw std::out_of_range(
"empty sparse vector");
1553 return ((iNextRange == ranges.begin())
1554 || (index >= (--iNextRange)->end_index()))?
1555 ranges.end(): iNextRange;
1559 template <
typename T>
1563 return ranges.begin() + (
1564 (
const_cast<const this_t*
>(
this)->find_range_iterator(index))
1569 template <
typename T>
1573 if (ranges.empty())
throw std::out_of_range(
"empty sparse vector");
1576 if (iNextRange == ranges.end())
1577 throw std::out_of_range(
"index in no range of the sparse vector");
1581 template <
typename T>
1586 (
const_cast<const this_t*
>(
this)->find_range(index));
1590 template <
typename T>
1592 if (ranges.empty() || (index >= size()))
1593 throw std::out_of_range(
"empty sparse vector");
1596 if ((iNextRange == ranges.begin())
1597 || ((--iNextRange)->end_index() <= index))
1601 ranges.erase(iNextRange);
1605 template <
typename T>
template <
typename ITER>
1611 ranges.begin(), ranges.end(), offset,
1612 typename datarange_t::less_int_range(datarange_t::less)
1616 if ((iInsert != ranges.begin()) && (iInsert-1)->borders(offset)) {
1618 (--iInsert)->extend(offset, first, last);
1623 iInsert = insert_range(iInsert, { offset, first, last });
1625 return merge_ranges(iInsert);
1629 template <
typename T>
1635 ranges.begin(), ranges.end(), offset,
1636 typename datarange_t::less_int_range(datarange_t::less)
1640 if ((iInsert != ranges.begin()) && (iInsert-1)->borders(offset)) {
1642 (--iInsert)->extend(offset, new_data.begin(), new_data.end());
1650 iInsert = insert_range(iInsert, { offset, std::move(new_data) });
1652 return merge_ranges(iInsert);
1656 template <
typename T>
1661 if ((first.
cont !=
this) || (last.
cont !=
this)) {
1662 throw std::runtime_error
1663 (
"lar::sparse_vector::make_void(): iterators from alien container");
1666 if (first >= last)
return;
1675 if (first_range == ranges.end())
return;
1678 if (first.
index > first_range->begin_index()) {
1679 if (first_range == last_range) {
1683 last_range = ranges.emplace(++last_range, last.
index,
1684 first_range->begin() + first_range->relative_index(last.
index),
1688 first_range->move_tail(first.
index);
1691 first_range->move_tail(first.
index);
1697 if ((last_range != ranges.end()) && (last.
index > last_range->begin_index()))
1698 eat_range_head(last_range, last.
index);
1701 ranges.erase(first_range, last_range);
1705 template <
typename T>
1708 if (ranges.empty())
return true;
1711 while (iNext != rend) {
1713 if (iRange->empty())
return false;
1714 if (iNext != rend) {
1715 if (!(*iRange < *iNext))
return false;
1716 if (!iRange->separate(*iNext))
return false;
1719 if (nominal_size < ranges.back().end_index())
return false;
1727 template <
typename T>
1733 return std::upper_bound(
1734 rbegin, ranges.end(), index,
1735 typename datarange_t::less_int_range(datarange_t::less)
1739 template <
typename T>
1745 return std::upper_bound(
1746 rbegin, ranges.end(), index,
1747 typename datarange_t::less_int_range(datarange_t::less)
1752 template <
typename T>
1757 while (iNext != ranges.end()) {
1758 if (!iRange->borders(iNext->begin_index()))
break;
1761 if (iNext->end_index() > iRange->end_index()) {
1763 (iRange->end_index(), iNext->get_iterator(iRange->end_index()), iNext->end());
1765 iNext = ranges.erase(iNext);
1772 template <
typename T>
1776 if (index <= iRange->begin_index())
return iRange;
1777 if (index >= iRange->end_index())
return ranges.erase(iRange);
1778 iRange->move_head(index);
1783 template <
typename T>
1785 if (!ranges.empty())
1786 nominal_size =
std::max(nominal_size, ranges.back().end_index());
1787 return nominal_size;
1793 template <
typename T>
1803 template <
typename T>
1813 template <
typename T>
1822 return expected_vector_size(a.
size() + b.
size() + gap_size)
1823 <= expected_vector_size(a.
size()) + expected_vector_size(b.
size());
1829 template <
typename T>
1830 std::ostream& operator<< (std::ostream& out, const lar::sparse_vector<T>& v) {
1832 out <<
"Sparse vector of size " << v.size() <<
" with " 1833 << v.get_ranges().size() <<
" ranges:";
1835 iRange = v.begin_range(), rend = v.end_range();
1836 while (iRange != rend) {
1837 out <<
"\n [" << iRange->begin_index() <<
" - " << iRange->end_index()
1838 <<
"] (" << iRange->
size() <<
"):";
1840 iValue = iRange->
begin(), vend = iRange->
end();
1841 while (iValue != vend) out <<
" " << (*(iValue++));
1844 return out << std::endl;
1852 template <
typename T>
template <
typename ITER>
1857 base_t::relative_index(index) + std::distance(first, last),
1859 base_t::resize(new_size);
1860 values.resize(new_size);
1861 std::copy(first, last, get_iterator(index));
1866 template <
typename T>
1871 if (delta == 0)
return;
1872 base_t::move_head(delta);
1874 values.erase(values.begin(), values.begin() + delta);
1876 values.insert(values.begin(),
1887 template <
typename T>
1892 if (!cont || (index >= cont->size()))
return *
this;
1898 if (currentRange != cont->ranges.end()) {
1900 if (currentRange->end_index() <= index) ++currentRange;
1907 template <
typename T>
1911 if (!cont)
throw std::out_of_range(
"iterator to no sparse vector");
1914 if (index >= cont->size())
return value_zero;
1917 if (currentRange == cont->ranges.end())
return value_zero;
1920 if (index < currentRange->begin_index())
return value_zero;
1922 return (*currentRange)[index];
1926 template <
typename T>
1930 if (delta == 1)
return this->operator++();
1932 if ((currentRange == cont->ranges.end())
1933 || !currentRange->includes(index)
1939 template <
typename T>
1945 template <
typename T>
1949 if ((currentRange == cont->ranges.end())
1950 || !currentRange->includes(index + delta)
1954 iter.
index += delta;
1958 template <
typename T>
1965 template <
typename T>
1970 if (cont != iter.cont) {
1971 throw std::runtime_error(
"lar::sparse_vector::const_iterator:" 1972 " difference with alien iterator");
1974 return index -iter.index;
1978 template <
typename T>
1984 currentRange = cont->find_next_range_iter(index);
1986 if (currentRange != cont->ranges.begin()) {
1987 if ((currentRange - 1)->end_index() > index) --currentRange;
2004 #endif // LARDATAOBJ_UTILITIES_SPARSE_VECTOR_H void clear()
Removes all the data, making the vector empty.
iterator(const container_t &c, const typename special::begin _)
Special constructor: initializes at the beginning of the container.
bool includes(const range_t &r) const
Returns whether the specified range is completely included in this one.
std::vector< value_type > vector_t
type of STL vector holding this data
sparse_vector(const vector_t &from, size_type offset=0)
Constructor: a solid vector from an existing STL vector.
sparse_vector()
Default constructor: an empty vector.
void refresh_state()
Reassigns the internal state according to the index.
const datarange_t & range(size_t i) const
Returns the i-th non-void range (zero-based)
const datarange_t & add_range(size_type offset, const CONT &new_data)
Copies the elements in container to a range with specified offset.
Iterator to the sparse vector values.
vector_t::const_pointer const_pointer
size_type n_ranges() const
Returns the internal list of non-void ranges.
reference(value_type &value)
container_t::pointer pointer
static size_t expected_vector_size(size_t size)
Returns the expected size taken by a vector of specified size.
const_reference(const value_type *pValue=0)
size_type fix_size()
Extends the vector size according to the last range.
void resize(size_type new_size)
Resizes the vector to the specified size, adding void.
const datarange_t & append(const CONT &range_data)
Adds a sequence of elements as a range at the end of the vector.
const_reference operator*() const
Constant dereferenciation operator.
static value_type abs(value_type v)
Returns the module of the specified value.
vector_t values
data in the range
const_value_box< T > this_t
bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
reference(const const_reference &from)
size_type size() const
Returns the size of the vector.
this_t operator++(int)
Increments the position of the iterator, returns the old position.
A class representing a cell in a sparse vector.
vector_t::pointer pointer
iterator(container_t &c, size_type offset=0)
Constructor from a container and an offset.
constexpr bool operator>(Index_t left, Flag_t< Storage > right)
size_type offset
offset (absolute index) of the first element
range_iterator eat_range_head(range_iterator iRange, size_t index)
Voids the starting elements up to index (excluded) of a given range.
constexpr bool operator<=(Index_t left, Flag_t< Storage > right)
std::iterator< std::random_access_iterator_tag, T > base_t
base type
const_iterator & operator+=(difference_type delta)
Increment and decrement operators.
value_type value
value to be returned when dereferencing
size_type minimum_size() const
Returns the size determined by the ranges already present.
range_t< size_type > base_t
base class
const_iterator::const_reference const_reference
const container_t * cont
pointer to the container
const datarange_t & add_range(size_type offset, ITER first, ITER last)
Adds a sequence of elements as a range with specified offset.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
void void_range(range_iterator iRange)
Turns the specified range into void.
reference(value_type *pValue=0)
value_type & operator=(value_type v)
const_iterator cend() const
Standard iterators interface.
range_const_iterator find_next_range_iter(size_type index) const
Returns an iterator to the range after index, or end() if none.
constexpr bool is_valid(IDNumber_t< L > const id)
value_const_iterator< T > operator+(typename value_const_iterator< T >::difference_type ofs, value_const_iterator< T > &iter)
Returns an iterator pointing ahead of this one by the specified steps.
size_type begin_index() const
Returns the first absolute index included in the range.
this_t operator--(int)
Decrements the position of the iterator, returns the old position.
const_reference(const value_type &value)
container_t::difference_type difference_type
const_iterator(const container_t &c, const typename special::end)
Special constructor: initializes at the end of the container.
value_type & set_at(size_type index, value_type value)
Writes into an element (creating or expanding a range if needed)
T value_type
type of the stored values
bool is_void(size_type index) const
Returns whether the specified position is void.
bool separate(const range_t &r) const
Returns if there are elements in between this and the specified range.
const_iterator get_iterator(size_type index) const
Returns an iterator to the specified absolute value (no check!)
constexpr bool operator>=(Index_t left, Flag_t< Storage > right)
Iterator to the sparse vector values.
bool overlap(const range_t &r) const
Returns if this and the specified range overlap.
datarange_t(size_type offset, ITER first, ITER last)
Constructor: offset and data.
void move_tail(size_type to_index, value_type def_value=value_zero)
Moves the end of this range.
ranges_const_iterator currentRange
pointer to the current (or next) range
bool is_valid() const
Returns if the vector is in a valid state.
void fit_size_from_data()
size_type end_index() const
Returns the first absolute index not included in the range.
QuadExpr operator-(double v, const QuadExpr &e)
void move_head(difference_type shift)
Moves the begin of the range by the specified amount.
sparse_vector(sparse_vector &&from)
Move constructor.
container_t::size_type size_type
range_t(size_type from, size_type to)
Constructor from first and last index.
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.
void move_tail(difference_type shift)
Moves the end of the range by the specified amount.
const_iterator cbegin() const
begin and end iterators
bool empty() const
Returns whether the range is empty.
const_iterator(const container_t &c, const typename special::begin)
Special constructor: initializes at the beginning of the container.
datarange_t(const base_t &range)
Constructor: range initialized with 0.
const_value_box(value_type new_value)
Constructor: stores the specified value.
const_iterator cend() const
begin and end iterators
range_list_t ranges
list of ranges
bool back_is_void() const
Returns whether the sparse vector ends with void.
vector_t::difference_type difference_type
index difference type
iterator(const_iterator from)
sparse_vector(size_type new_size)
Constructor: a vector with new_size elements in the void.
A range (interval) of integers.
this_t & operator--()
Decrements the position of the iterator, returns the new position.
vector_t::iterator iterator
static size_t min_gap()
Minimum optimal gap between ranges (a guess)
range_iterator find_next_range_iter(size_type index)
Returns an iterator to the range after index, or end() if none.
sparse_vector & operator=(sparse_vector &&from)
Move assignment.
Namespace for special initialization.
datarange_t()
Default constructor: an empty range.
iterator end()
Standard iterators interface.
datarange_t & extend(size_type index, ITER first, ITER last)
value_const_iterator(value_type new_value, difference_type offset)
Constructor: value to be returned and current iterator "position".
vector_t::size_type size_type
size type
void assign(const CONT &new_data)
Copies data from a container.
const_iterator operator-(difference_type delta) const
Increment and decrement operators.
this_t & operator++()
Increments the position of the iterator, returns the new position.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
value_const_iterator()
Default constructor: use the default value.
std::vector< datarange_t > range_list_t
type of sparse vector data
Little class storing a value.
void make_void(iterator first, iterator last)
Makes all the elements from first and before last void.
vector_t::const_reference const_reference
const_iterator & operator++()
Increment and decrement operators.
container_t::range_list_t::const_iterator ranges_const_iterator
datarange_t & merge_ranges(range_iterator iRange)
Merges all the following ranges.
void move_head(size_type to_index, value_type def_value=value_zero)
Moves the begin of this range.
String & operator+=(String &s, VectorDumper< Vector > const &manip)
Appends a string rendering of a vector to the specified string.
container_t::reference reference
range_const_iterator begin_range() const
Returns a constant iterator to the first data range.
range_t()
Default constructor: empty range.
const datarange_t & append(ITER first, ITER last)
Adds a sequence of elements as a range at the end of the vector.
void push_back(value_type value, value_type thr)
Adds one element to the end of the vector (if zero, just adds void)
sparse_vector(vector_t &&from, size_type offset=0)
Constructor: a solid vector from an existing STL vector.
bool is_valid() const
Returns whether the range is valid (that is, non-negative size)
size_type index
pointer to the current value, as absolute index
sparse_vector< T > this_t
bool optimize(size_t)
Performs internal optimization, returns whether the object was changed.
range_list_t::const_iterator range_const_iterator
type of constant iterator over ranges
const_iterator operator++(int)
Increment and decrement operators.
const_iterator & operator-=(difference_type delta)
Increment and decrement operators.
static value_type is_zero(value_type v)
Returns whether the value is exactly zero.
iterator operator++(int _)
Increment and decrement operators.
difference_type index
(arbitrary) position pointed by the iterator
const_iterator()
Default constructor, does not iterate anywhere.
void resize(size_t new_size, value_type def_value)
Resizes the range (optionally filling the new elements with def_value)
const datarange_t & append(vector_t &&range_data)
Adds a sequence of elements as a range at the end of the vector.
value_const_iterator< T > this_t
alias for this type
iterator()
Default constructor, does not iterate anywhere.
bool operator!=(geometry_element_iterator< GEOIDITER > const &iter, GEOIDITER const &id_iter)
Comparison operator: geometry ID and element point to different IDs.
size_type size() const
Returns the size of the range.
void make_void_around(size_type index)
Casts the whole range with the specified item into the void.
std::string value(boost::any const &)
static bool less(const range_t &a, size_type b)
Returns if a is "less" than b.
static bool less(size_type a, const range_t &b)
Returns if a is "less" than b.
range_const_iterator find_range_iterator(size_type index) const
Returns an iterator to the range containing the specified index.
void void_range(size_t iRange)
Turns the specified range into void.
SIZE size_type
type for the indices in the range
sparse_vector< T > container_t
LArSoft-specific namespace.
size_type nominal_size
current size
const datarange_t & find_range(size_type index) const
Returns the range containing the specified index.
QuadExpr operator+(double v, const QuadExpr &e)
this_t & operator=(value_type)
Assignment: the assigned value is ignored.
vector_t::const_iterator const_iterator
bool empty() const
Returns whether the vector is empty.
const_iterator(const container_t &c, size_type offset)
Constructor from a container and a offset.
Special little box to allow void elements to be treated as references.
void unset_at(size_type index)
Casts the element with the specified index into the void.
void assign(vector_t &&new_data)
Moves data from a vector.
range_const_iterator get_current_range() const
Returns the current range internal value; use it at your own risk!!
const_value_box()
Default constructor: stores default value.
reference operator*() const
Dereferenciation operator (can't write non-empty elements!)
const_iterator::special special
iterator begin()
Standard iterators interface.
Range class, with range and data.
value_type value
the value stored for delivery
void resize(size_type new_size)
Moves the end of the range to fit the specified size.
datarange_t(size_type offset, vector_t &&data)
Constructor: offset and data as a vector (which will be used directly)
const_iterator end() const
begin and end iterators
static value_type is_zero(value_type v, value_type thr)
Returns whether the value is zero below a given threshold.
range_iterator insert_range(range_iterator iInsert, datarange_t &&data)
Plug a new data range in the specified position; no check performed.
std::forward_iterator_tag iterator_category
range_const_iterator end_range() const
Returns a constant iterator to after the last data range.
bool includes(size_type index) const
Returns whether the specified absolute index is included in this range.
static value_type is_equal(value_type a, value_type b)
Returns whether two values are the same.
range_list_t::iterator range_iterator
type of iterator over ranges
const_iterator begin() const
begin and end iterators
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
value_const_iterator(value_type new_value)
Constructor: value that will be returned.
iterator(const container_t &c, const typename special::end _)
Special constructor: initializes at the end of the container.
container_t::value_type value_type
const_iterator cbegin() const
Standard iterators interface.
iterator begin()
begin and end iterators
iterator end()
begin and end iterators
const_iterator::reference reference
size_type last
offset (absolute index) after the last element
const_iterator::container_t container_t
QuadExpr operator*(double v, const QuadExpr &e)
const_iterator operator+(difference_type delta) const
Increment and decrement operators.
void assign(ITER first, ITER last)
Copies data from a sequence between two iterators.
A constant iterator returning always the same value.
bool operator==(geometry_element_iterator< GEOIDITER > const &iter, GEOIDITER const &id_iter)
Comparison operator: geometry ID and element point to the same ID.
T value_type
type of the value stored
std::ptrdiff_t difference_type
type for index difference
size_type capacity() const
Returns the capacity of the vector (compatibility only)
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.
size_type relative_index(size_type index) const
Returns the position within the range of the absolute index specified.
bool borders(size_type index) const
Returns whether an index is within or immediately after this range.
size_type count() const
Returns the number of non-void cells.