11 #ifndef LARDATAOBJ_UTILITIES_SPARSE_VECTOR_H 12 #define LARDATAOBJ_UTILITIES_SPARSE_VECTOR_H 23 #include <type_traits> 59 operator const value_type& ()
const {
return value; }
73 typedef std::iterator<std::random_access_iterator_tag, T>
base_t;
78 using typename base_t::value_type;
79 using typename base_t::difference_type;
89 index(offset),
value(new_value) {}
101 this_t
operator++(
int) { this_t copy(*
this); ++index;
return copy; }
107 this_t
operator--(
int) { this_t copy(*
this); --index;
return copy; }
110 this_t&
operator+= (difference_type ofs) { index += ofs;
return *
this; }
113 this_t& operator-= (difference_type ofs) { index -= ofs;
return *
this; }
126 {
return index - iter.
index; }
140 difference_type index{0};
150 template <
typename T>
185 template <
typename SIZE>
202 offset(from), last(
std::
max(from, to)) {}
206 void set(size_type from, size_type to)
207 { offset = from; last =
std::max(from, to); }
219 size_type
size()
const {
return last - offset; }
222 void resize(size_type new_size) { last = offset + new_size; }
225 void move_head(difference_type shift) { offset += shift; }
228 void move_tail(difference_type shift) { last += shift; }
231 bool empty()
const {
return last <= offset; }
235 {
return (index >= offset) && (index < last); }
254 {
return (index >= offset) && (index <= last); }
263 {
return (offset == as.
offset) && (last == as.
last); }
279 typedef bool (*less_int_range)(size_type,
const range_t& b);
456 template <
typename T>
476 class const_reference;
499 { resize(new_size); }
507 nominal_size(0), ranges()
508 { add_range(offset, from.begin(), from.end()); }
515 : nominal_size(from.nominal_size)
516 , ranges(
std::move(from.ranges))
517 { from.nominal_size = 0; }
525 ranges = std::move(from.ranges);
526 nominal_size = from.nominal_size;
527 from.nominal_size = 0;
537 nominal_size(0), ranges()
538 { add_range(offset, std::move(from)); }
547 void clear() { ranges.clear(); nominal_size = 0; }
551 size_type
size()
const {
return nominal_size; }
554 bool empty()
const {
return size() == 0; }
557 size_type
capacity()
const {
return nominal_size; }
560 void resize(size_type new_size);
563 void resize(size_type new_size, value_type def_value);
577 value_type operator[] (size_type index)
const;
580 reference operator[] (size_type index);
596 bool is_void(size_type index)
const;
602 {
return ranges.empty() || (ranges.back().end_index() < size()); }
606 size_type count()
const;
623 value_type& set_at(size_type index, value_type
value);
626 void unset_at(size_type index);
629 void push_back(value_type value) { resize(size() + 1, value); }
642 if (is_zero(value, thr)) resize(size() + 1);
643 else push_back(value);
657 template <
typename ITER>
658 void assign(ITER first, ITER last) {
clear(); append(first, last); }
667 template <
typename CONT>
676 void assign(vector_t&& new_data) {
clear(); append(std::move(new_data)); }
693 size_type
n_ranges()
const {
return ranges.size(); }
696 const datarange_t&
range(
size_t i)
const {
return ranges[i]; }
699 range_const_iterator
begin_range()
const {
return ranges.begin(); }
702 range_const_iterator
end_range()
const {
return ranges.end(); }
713 range_const_iterator find_range_iterator(size_type index)
const;
714 range_iterator find_range_iterator(size_type index);
725 const datarange_t& find_range(size_type index)
const;
726 datarange_t& find_range(size_type index);
735 void make_void_around(size_type index);
751 template <
typename ITER>
752 const datarange_t& add_range(size_type offset, ITER first, ITER last);
766 template <
typename CONT>
767 const datarange_t&
add_range(size_type offset,
const CONT& new_data)
768 {
return add_range(offset, new_data.begin(), new_data.end()); }
783 const datarange_t& add_range(size_type offset, vector_t&& new_data);
814 template <
typename ITER,
typename OP>
815 const datarange_t& combine_range(
816 size_type offset, ITER first, ITER last, OP&& op,
817 value_type void_value = value_zero
834 template <
typename CONT,
typename OP>
836 size_type offset,
const CONT&
other, OP&& op,
837 value_type void_value = value_zero
840 return combine_range(offset, other.begin(), other.end(),
841 std::forward<OP>(op), void_value);
856 template <
typename ITER>
857 const datarange_t&
append(ITER first, ITER last)
858 {
return add_range(size(), first, last); }
869 template <
typename CONT>
870 const datarange_t&
append(
const CONT& range_data)
871 {
return add_range(size(), range_data); }
883 const datarange_t&
append(vector_t&& range_data)
884 {
return add_range(size(), std::move(range_data)); }
894 void void_range(range_iterator iRange) { ranges.erase(iRange); }
895 void void_range(
size_t iRange) { ranges.erase(ranges.begin() + iRange); }
920 bool optimize() {
return optimize(min_gap()); }
928 static constexpr value_type value_zero{0};
931 static value_type
abs(value_type v) {
return (v < value_zero)? -v: v; }
934 static value_type
is_zero(value_type v) {
return v == value_zero; }
937 static value_type
is_zero(value_type v, value_type thr)
938 {
return abs(v - value_zero) <= thr; }
941 static value_type
is_equal(value_type a, value_type b)
942 {
return is_zero(abs(a - b)); }
945 static value_type
is_equal(value_type a, value_type b, value_type thr)
946 {
return is_zero(abs(a - b), thr); }
952 static size_t expected_vector_size(
size_t size);
955 static size_t min_gap();
958 static bool should_merge(
959 const typename datarange_t::base_t& a,
960 const typename datarange_t::base_t& b
978 {
return find_next_range_iter(index, ranges.begin()); }
980 {
return find_next_range_iter(index, ranges.cbegin()); }
991 range_iterator find_next_range_iter(size_type index, range_iterator rbegin);
992 range_const_iterator find_next_range_iter
993 (size_type index, range_const_iterator rbegin)
const;
1016 {
return find_extending_range_iter(index, ranges.begin()); }
1018 {
return find_extending_range_iter(index, ranges.cbegin()); }
1029 range_iterator find_extending_range_iter
1030 (size_type index, range_iterator rbegin);
1031 range_const_iterator find_extending_range_iter
1032 (size_type index, range_const_iterator rbegin)
const;
1037 {
return ranges.empty()? 0: ranges.back().end_index(); }
1040 range_iterator insert_range(range_iterator iInsert,
const datarange_t& data)
1042 {
return data.empty()? iInsert: ranges.insert(iInsert, data); }
1044 {
return data.empty()? iInsert: ranges.insert(iInsert, std::move(data)); }
1048 range_iterator eat_range_head(range_iterator iRange,
size_t index);
1051 datarange_t& merge_ranges(range_iterator iRange);
1054 size_type fix_size();
1076 template <
typename T>
1077 std::ostream& operator<< (std::ostream& out, const lar::sparse_vector<T>& v);
1086 template <
typename T>
1098 datarange_t(
const base_t& range): base_t(range), values(range.size()) {}
1101 template <
typename ITER>
1103 base_t(offset, offset +
std::distance(first, last)),
1109 base_t(offset, offset + data.size()), values(data)
1116 {
return values.begin() + index - base_t::begin_index(); }
1118 {
return get_const_iterator(index); }
1120 {
return values.begin() + index - base_t::begin_index(); }
1124 iterator
begin() {
return values.begin(); }
1126 iterator
end() {
return values.end(); }
1127 const_iterator
begin()
const {
return values.begin(); }
1128 const_iterator
end()
const {
return values.end(); }
1129 const_iterator
cbegin()
const {
return values.cbegin(); }
1130 const_iterator
cend()
const {
return values.cend(); }
1134 void resize(
size_t new_size)
1136 { values.resize(new_size); fit_size_from_data(); }
1138 { values.resize(new_size, def_value); fit_size_from_data(); }
1144 {
return values[base_t::relative_index(index)]; }
1146 {
return values[base_t::relative_index(index)]; }
1150 const vector_t& data()
const {
return values; }
1163 template <
typename ITER>
1179 { resize(base_t::relative_index(to_index), def_value); }
1196 template <
typename T>
1204 explicit operator value_type()
const {
return ptr? *ptr: value_zero; }
1206 {
return ptr? *ptr: value_zero; }
1217 template <
typename T>
1231 {
return const_cast<value_type&
>(*const_reference::ptr) = v; }
1236 {
return const_cast<value_type&
>(*const_reference::ptr); }
1246 template <
typename T>
1286 cont(&c), index(
std::
min(offset, c.size())), currentRange()
1287 { refresh_state(); }
1291 cont(&c), index(0), currentRange(c.get_ranges().
begin())
1296 cont(&c), index(c.size()), currentRange(c.get_ranges().
end())
1300 const_reference operator[] (size_type offset)
const 1301 {
return (*cont)[index + offset]; }
1328 {
return (cont == as.
cont) && (index == as.
index); }
1330 {
return (cont != as.
cont) || (index != as.
index); }
1332 {
return (cont == than.
cont) && (index < than.
index); }
1334 {
return (cont == than.
cont) && (index > than.
index); }
1336 {
return (cont == than.
cont) && (index <= than.
index); }
1338 {
return (cont == than.
cont) && (index >= than.
index); }
1380 void refresh_state();
1395 template <
typename T>
1398 friend typename const_iterator::container_t;
1422 {
return (*const_iterator::cont)[const_iterator::index + offset]; }
1445 {
return reference(const_iterator::operator*()); }
1466 template <
typename BITER,
typename EITER>
1473 auto const&
end()
const {
return e; }
1482 template <
typename T>
1487 template <
typename T>
1489 if (new_size >= size()) {
1490 nominal_size = new_size;
1496 ranges.erase(iLastRange, ranges.end());
1497 if (!ranges.empty()) {
1499 if (new_size == iLastRange->begin_index())
1500 ranges.erase(iLastRange);
1501 else if (new_size < iLastRange->end_index())
1502 iLastRange->resize(new_size - iLastRange->begin_index());
1506 nominal_size = new_size;
1510 template <
typename T>
1512 if (new_size == size())
return;
1513 if (new_size > size()) {
1516 append(
vector_t(new_size - size(), def_value));
1518 ranges.back().resize(new_size - ranges.back().begin_index(), def_value);
1520 nominal_size = new_size;
1528 template <
typename T>
1532 template <
typename T>
1536 template <
typename T>
1541 template <
typename T>
1546 template <
typename T>
1555 if (iNextRange == ranges.begin())
return value_zero;
1561 return (index < range.
end_index())? range[index]: value_zero;
1565 template <
typename T>
1574 if (iNextRange == ranges.begin())
return reference();
1584 template <
typename T>
1586 if (ranges.empty() || (index >= size()))
1587 throw std::out_of_range(
"empty sparse vector");
1590 return ((iNextRange == ranges.begin())
1591 || ((--iNextRange)->end_index() <= index));
1595 template <
typename T>
1599 return std::accumulate(begin_range(), end_range(),
size_type(0),
1605 template <
typename T>
1614 if (iNextRange != ranges.begin()) {
1620 if (index < range.
end_index())
return range[index] = value;
1623 return const_cast<datarange_t&
>(add_range(index, { value }))[index];
1627 template <
typename T>
1634 if (iNextRange == ranges.begin())
return;
1643 if (range.
size() == 1) ranges.erase(iNextRange);
1647 else if (index == range.
end_index() - 1)
1654 ranges.emplace(++iNextRange, index + 1,
1664 template <
typename T>
1668 if (ranges.empty())
throw std::out_of_range(
"empty sparse vector");
1671 return ((iNextRange == ranges.begin())
1672 || (index >= (--iNextRange)->end_index()))?
1673 ranges.end(): iNextRange;
1677 template <
typename T>
1681 return ranges.begin() + (
1682 (
const_cast<const this_t*
>(
this)->find_range_iterator(index))
1687 template <
typename T>
1691 if (ranges.empty())
throw std::out_of_range(
"empty sparse vector");
1694 if (iNextRange == ranges.end())
1695 throw std::out_of_range(
"index in no range of the sparse vector");
1699 template <
typename T>
1704 (
const_cast<const this_t*
>(
this)->find_range(index));
1708 template <
typename T>
1710 if (ranges.empty() || (index >= size()))
1711 throw std::out_of_range(
"empty sparse vector");
1714 if ((iNextRange == ranges.begin())
1715 || ((--iNextRange)->end_index() <= index))
1719 ranges.erase(iNextRange);
1723 template <
typename T>
template <
typename ITER>
1731 if ((iInsert != ranges.begin()) && (iInsert-1)->borders(offset)) {
1733 (--iInsert)->extend(offset, first, last);
1738 iInsert = insert_range(iInsert, { offset, first, last });
1740 return merge_ranges(iInsert);
1744 template <
typename T>
1750 ranges.begin(), ranges.end(), offset,
1751 typename datarange_t::less_int_range(datarange_t::less)
1755 if ((iInsert != ranges.begin()) && (iInsert-1)->borders(offset)) {
1757 (--iInsert)->extend(offset, new_data.begin(), new_data.end());
1765 iInsert = insert_range(iInsert, { offset, std::move(new_data) });
1767 return merge_ranges(iInsert);
1771 template <
typename T>
1772 template <
typename ITER,
typename OP>
1774 size_type offset, ITER first, ITER last, OP&& op,
1793 auto const insertionPoint = offset;
1794 auto destRange = find_extending_range_iter(offset, ranges.begin());
1795 while (src != last) {
1800 if ((destRange != end_range()) && (offset < destRange->end_index())) {
1805 auto const end = destRange->end();
1806 while (src != last) {
1807 *dest = op(*dest, *src);
1810 if (++dest ==
end)
break;
1812 if (src == last)
break;
1813 offset = destRange->end_index();
1823 size_type const newRangeSize = (destRange == end_range())
1824 ? std::distance(src, last): (destRange->begin_index() - offset);
1828 combinedData.reserve(newRangeSize);
1830 while (i++ < newRangeSize) {
1831 combinedData.push_back(op(void_value, *src));
1832 if (++src == last)
break;
1836 destRange = insert_range(destRange, { offset, std::move(combinedData) });
1841 offset = destRange->end_index();
1848 return merge_ranges(find_extending_range_iter(insertionPoint));
1853 template <
typename T>
1858 if ((first.
cont !=
this) || (last.
cont !=
this)) {
1859 throw std::runtime_error
1860 (
"lar::sparse_vector::make_void(): iterators from alien container");
1863 if (first >= last)
return;
1872 if (first_range == ranges.end())
return;
1875 if (first.
index > first_range->begin_index()) {
1876 if (first_range == last_range) {
1880 last_range = ranges.emplace(++last_range, last.
index,
1881 first_range->begin() + first_range->relative_index(last.
index),
1885 first_range->move_tail(first.
index);
1888 first_range->move_tail(first.
index);
1894 if ((last_range != ranges.end()) && (last.
index > last_range->begin_index()))
1895 eat_range_head(last_range, last.
index);
1898 ranges.erase(first_range, last_range);
1902 template <
typename T>
1905 if (ranges.empty())
return true;
1908 while (iNext != rend) {
1910 if (iRange->empty())
return false;
1911 if (iNext != rend) {
1912 if (!(*iRange < *iNext))
return false;
1913 if (!iRange->separate(*iNext))
return false;
1916 if (nominal_size < ranges.back().end_index())
return false;
1924 template <
typename T>
1930 return std::upper_bound(
1931 rbegin, ranges.end(), index,
1932 typename datarange_t::less_int_range(datarange_t::less)
1936 template <
typename T>
1942 return std::upper_bound(
1943 rbegin, ranges.end(), index,
1944 typename datarange_t::less_int_range(datarange_t::less)
1949 template <
typename T>
1955 auto it = find_next_range_iter(index, rbegin);
1958 return ((it != rbegin) && std::prev(it)->borders(index))? std::prev(it): it;
1962 template <
typename T>
1968 auto it = find_next_range_iter(index, rbegin);
1971 return ((it != rbegin) && std::prev(it)->borders(index))? std::prev(it): it;
1975 template <
typename T>
1980 while (iNext != ranges.end()) {
1981 if (!iRange->borders(iNext->begin_index()))
break;
1984 if (iNext->end_index() > iRange->end_index()) {
1986 (iRange->end_index(), iNext->get_iterator(iRange->end_index()), iNext->end());
1988 iNext = ranges.erase(iNext);
1995 template <
typename T>
1999 if (index <= iRange->begin_index())
return iRange;
2000 if (index >= iRange->end_index())
return ranges.erase(iRange);
2001 iRange->move_head(index);
2006 template <
typename T>
2008 if (!ranges.empty())
2009 nominal_size =
std::max(nominal_size, ranges.back().end_index());
2010 return nominal_size;
2016 template <
typename T>
2026 template <
typename T>
2036 template <
typename T>
2045 return expected_vector_size(a.
size() + b.
size() + gap_size)
2046 <= expected_vector_size(a.
size()) + expected_vector_size(b.
size());
2052 template <
typename T>
2053 std::ostream& operator<< (std::ostream& out, const lar::sparse_vector<T>& v) {
2055 out <<
"Sparse vector of size " << v.size() <<
" with " 2056 << v.get_ranges().size() <<
" ranges:";
2058 iRange = v.begin_range(), rend = v.end_range();
2059 while (iRange != rend) {
2060 out <<
"\n [" << iRange->begin_index() <<
" - " << iRange->end_index()
2061 <<
"] (" << iRange->
size() <<
"):";
2063 iValue = iRange->
begin(), vend = iRange->
end();
2064 while (iValue != vend) out <<
" " << (*(iValue++));
2067 return out << std::endl;
2075 template <
typename T>
template <
typename ITER>
2080 base_t::relative_index(index) + std::distance(first, last),
2082 base_t::resize(new_size);
2083 values.resize(new_size);
2084 std::copy(first, last, get_iterator(index));
2089 template <
typename T>
2094 if (delta == 0)
return;
2095 base_t::move_head(delta);
2097 values.erase(values.begin(), values.begin() + delta);
2099 values.insert(values.begin(),
2110 template <
typename T>
2115 if (!cont || (index >= cont->size()))
return *
this;
2121 if (currentRange != cont->ranges.end()) {
2123 if (currentRange->end_index() <= index) ++currentRange;
2130 template <
typename T>
2134 if (!cont)
throw std::out_of_range(
"iterator to no sparse vector");
2137 if (index >= cont->size())
return value_zero;
2140 if (currentRange == cont->ranges.end())
return value_zero;
2143 if (index < currentRange->begin_index())
return value_zero;
2145 return (*currentRange)[index];
2149 template <
typename T>
2153 if (delta == 1)
return this->operator++();
2155 if ((currentRange == cont->ranges.end())
2156 || !currentRange->includes(index)
2162 template <
typename T>
2168 template <
typename T>
2172 if ((currentRange == cont->ranges.end())
2173 || !currentRange->includes(index + delta)
2177 iter.
index += delta;
2181 template <
typename T>
2188 template <
typename T>
2193 if (cont != iter.cont) {
2194 throw std::runtime_error(
"lar::sparse_vector::const_iterator:" 2195 " difference with alien iterator");
2197 return index -iter.index;
2201 template <
typename T>
2207 currentRange = cont->find_next_range_iter(index);
2209 if (currentRange != cont->ranges.begin()) {
2210 if ((currentRange - 1)->end_index() > index) --currentRange;
2227 #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)
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.
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.
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.
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.
range_iterator find_extending_range_iter(size_type index)
Returns an iterator to the range no earlier than index, or end() if none.
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)
iterator get_iterator(size_type index)
Returns an iterator to the specified absolute value (no check!)
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.
const_iterator get_const_iterator(size_type index) const
Returns an iterator to the specified absolute value (no check!)
iterator end()
Standard iterators interface.
datarange_t & extend(size_type index, ITER first, ITER last)
Appends the specified elements to this range.
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.
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.
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)
iteratorRange(BITER const &b, EITER const &e)
this_t & operator=(value_type)
Assignment: the assigned value is ignored.
vector_t::const_iterator const_iterator
Namespace hiding implementation details.
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.
Enclosure to use two iterators representing a range in a range-for loop.
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.
auto const & begin() const
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.