|
dune-istl 2.12-git
|
Loading...
Searching...
No Matches
sparseindexranges.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
72 using size_alloc_type = typename alloc_traits::template rebind_alloc<typename alloc_traits::size_type>;
80 using IndexVariant = std::variant<uint_least64_t *, uint_least32_t *, uint_least16_t *, uint_least8_t *>;
90 static constexpr std::pair<IndexVariant,size_type> initAllocateIndices(const allocator_type &allocator, size_type count, size_type max_size);
92 static constexpr size_type* initAllocateOffsets(const allocator_type &allocator, size_type size);
94 static constexpr void deallocate(const allocator_type& allocator, IndexVariant indices, size_type* offsets, size_type size);
98 static constexpr V compress(std::span<size_type> offsets, IndexVariant indices, const allocator_type& allocator);
102 static constexpr bool addIndex(std::span<index_t> index_set, index_t j, std::invocable auto grow_index_set_fn);
105 static constexpr void growIndices(std::span<size_type> offsets, IndexVariant& indices, size_type new_count, const allocator_type& allocator, auto uninitialized_copy_fn);
108 static constexpr void growLastIndexRange(std::span<size_type> offsets, IndexVariant& indices, double growth_factor, const allocator_type& allocator);
130 static constexpr void growAllIndexRanges(std::span<size_type> offsets, IndexVariant& indices, double growth_factor, const allocator_type& allocator);
140 return std::find_if(std::cbegin(index_set), std::cend(index_set), [j](value_type index){ return index >= j; });
152 return std::find_if(std::cbegin(index_set), std::cend(index_set), [j](value_type index){ return index > j; });
159 static constexpr V makeIndexVariantWithAlternative(std::size_t selected, std::index_sequence<I...>)
162 const bool assigned = ((selected == I ? (result = V{std::in_place_index<I>, nullptr}, true) : false) || ...);
169 static constexpr std::size_t selectSmallestIndexStorage(size_type max_index, std::index_sequence<I...>)
213 const auto selected = selectSmallestIndexStorage<V>(max_index, std::make_index_sequence<variant_size>{});
268 constexpr UnsequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices = 0, allocator_type allocator = allocator_type());
271 constexpr UnsequencedSparseIndexRangeBuilder(const UnsequencedSparseIndexRangeBuilder &) = delete;
273 constexpr UnsequencedSparseIndexRangeBuilder &operator=(const UnsequencedSparseIndexRangeBuilder &) = delete;
274 constexpr UnsequencedSparseIndexRangeBuilder &operator=(UnsequencedSparseIndexRangeBuilder &&) = delete;
352 constexpr SequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices = 2048, allocator_type allocator = allocator_type());
358 constexpr SequencedSparseIndexRangeBuilder &operator=(const SequencedSparseIndexRangeBuilder &) = delete;
359 constexpr SequencedSparseIndexRangeBuilder &operator=(SequencedSparseIndexRangeBuilder &&) = delete;
493 using size_alloc_type = typename alloc_traits::template rebind_alloc<typename alloc_traits::size_type>;
613 : public Dune::IteratorFacade<Iterator, std::random_access_iterator_tag, IndexRangeView, IndexRangeView, Dune::ProxyArrowResult<IndexRangeView>>
615 using Facade = Dune::IteratorFacade<Iterator, std::random_access_iterator_tag, IndexRangeView, IndexRangeView, Dune::ProxyArrowResult<IndexRangeView>>;
645 : public Dune::IteratorFacade<IndexIterator, std::random_access_iterator_tag, index_type, index_type, Dune::ProxyArrowResult<index_type>>
647 using Facade = Dune::IteratorFacade<IndexIterator, std::random_access_iterator_tag, index_type, index_type, Dune::ProxyArrowResult<index_type>>;
747 const std::span<const index_type> index_set(cis_->indices_ + cis_->offset(i_), cis_->indices_ + cis_->offset(i_ + 1));
788 using size_alloc_type = typename alloc_traits::template rebind_alloc<typename alloc_traits::size_type>;
798 constexpr CompressedSparseIndexRanges &operator=(const CompressedSparseIndexRanges &other) = delete;
825 constexpr CompressedSparseIndexRanges(UnsequencedSparseIndexRangeBuilder<OtherAlloc>&& builder);
872 constexpr friend bool operator==(const CompressedSparseIndexRanges &p1, const CompressedSparseIndexRanges &p2)
883 return std::visit([&]<typename index_t_1, typename index_t_2>(index_t_1 *indices1, index_t_2 *indices2) -> bool
911 : public Dune::IteratorFacade<Iterator, std::random_access_iterator_tag, IndexRangeView, IndexRangeView, Dune::ProxyArrowResult<IndexRangeView>>
913 using Facade = Dune::IteratorFacade<Iterator, std::random_access_iterator_tag, IndexRangeView, IndexRangeView, Dune::ProxyArrowResult<IndexRangeView>>;
943 : public Dune::IteratorFacade<IndexIterator, std::random_access_iterator_tag, index_type, index_type, Dune::ProxyArrowResult<index_type>>
945 using Facade = Dune::IteratorFacade<IndexIterator, std::random_access_iterator_tag, index_type, index_type, Dune::ProxyArrowResult<index_type>>;
1071 return static_cast<size_type>(std::distance(std::cbegin(index_set), index_set.lower_bound(value)));
1094 std::cout << (j == std::numeric_limits<index_t>::max() ? "*" : std::to_string(static_cast<size_type>(j))) << " ";
1103 constexpr auto SparseIndexRangeHelper<A>::initAllocateOffsets(const allocator_type &allocator, size_type size) -> size_type* {
1112 constexpr auto SparseIndexRangeHelper<A>::initAllocateIndices(const allocator_type &allocator, size_type count, size_type max_size) -> std::pair<IndexVariant,size_type> {
1116 assert(max_index < std::numeric_limits<uint_least64_t>::max() && "Too many indices for supported index types");
1141 index_alloc_traits::construct(index_alloc, std::addressof(indices_ptr[i]), std::numeric_limits<index_t>::max());
1148 constexpr void SparseIndexRangeHelper<A>::deallocate(const allocator_type& allocator, IndexVariant indices, size_type* offsets, size_type size) {
1167 constexpr V SparseIndexRangeHelper<A>::compress(std::span<size_type> offsets, IndexVariant indices, const allocator_type& alloc)
1177 std::for_each(std::cbegin(old_index_set), std::cend(old_index_set), [&count_invalid, &max_index](old_index_t j) {
1185 // nothing to do if there are no undefined indices and the indices already use the selected index type
1194 // allocate new arrays for offsets and indices. We use scope guards to ensure that the allocated memory is freed in case of exceptions.
1197 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<size_alloc_type> offsetsScopeGuard{size_alloc, new_offsets, offsets.size()};
1199 new_indices = std::visit([offsets, old_indices, index_count, count_invalid, index_defined, &new_offsets, &size_alloc]<typename new_index_t>(new_index_t * new_indices_ptr) -> V {
1203 new_indices_ptr = new_index_alloc_traits::allocate(new_index_alloc, index_count - count_invalid);
1204 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<new_index_alloc_type> newIndicesScopeGuard{new_index_alloc, new_indices_ptr, index_count - count_invalid};
1211 size_type is_count = std::count_if(std::cbegin(old_index_set), std::cend(old_index_set), index_defined);
1213 size_alloc_traits::construct(size_alloc, std::addressof(new_offsets[i + 1]), new_offsets[i] + is_count);
1219 new_index_alloc_traits::construct(new_index_alloc, std::addressof(new_index_set[j++]), static_cast<new_index_t>(old_idx));
1227 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<old_index_alloc_type> oldIndicesScopeGuard{old_index_alloc_type(size_alloc), old_indices, index_count};
1238 constexpr bool SparseIndexRangeHelper<A>::addIndex(std::span<index_t> index_set, index_t j, std::invocable auto grow_index_set_fn)
1256 assert(index_set.size() > dist && "Too many entries in index set but the builder cannot grow the indices");
1257 assert(index_set.back() == invalid_index && "Growth function must initialize new indices with invalid value");
1271 constexpr void SparseIndexRangeHelper<A>::growIndices(std::span<size_type> offsets, IndexVariant& indices, size_type new_count, const allocator_type& allocator, auto uninitialized_copy_fn){
1276 // allocate new arrays for indices. We use scope guards to ensure that the allocated memory is freed in case of exceptions.
1277 std::visit([&indices, &allocator, &uninitialized_copy_fn, offsets, old_count, new_count]<typename index_t>(index_t * old_indices) {
1280 using dealloc_guard_type = typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<index_alloc_type>;
1294 uninitialized_copy_fn(offsets, std::span<const index_t>(old_indices, old_count), std::span(new_indices, allocated_count));
1300 indices = IndexVariant{std::in_place_type<index_t *>, std::exchange(newIndicesScopeGuard.ptr, nullptr)};
1305 constexpr void SparseIndexRangeHelper<A>::growLastIndexRange(std::span<size_type> offsets, IndexVariant& indices, double growth_factor, const allocator_type& allocator){
1308 SparseIndexRangeHelper<A>::growIndices(offsets, indices, new_count, allocator, [allocator]<typename index_t>(std::span<size_type> offsets, std::span<const index_t> old_indices, std::span<index_t> new_indices){
1318 index_alloc_traits::construct(index_alloc, std::addressof(new_indices[j]), std::numeric_limits<index_t>::max());
1326 constexpr void SparseIndexRangeHelper<A>::growAllIndexRanges(std::span<size_type> offsets, IndexVariant& indices, double target_growth_factor, const allocator_type& allocator){
1333 // compute the total number of used indices across all index sets and the maximum number of used indices in any index set to estimate the new count of indices after growth
1334 std::visit([offsets, &max_is_used, &total_used_indices]<class index_t>(index_t const * indices_ptr) {
1335 // grow number of indices for all index sets by target_growth_factor times the current size or by the small index set threshold, whichever is larger
1348 size_type target_extra_per_index_set = std::max(static_cast<size_type>(max_is_used*(target_growth_factor - 1.)), min_extra_indices);
1352 growIndices(offsets, indices, new_count, allocator, [allocator, min_extra_indices, total_used_indices, new_count]<typename index_t>(std::span<size_type> offsets, std::span<const index_t> old_indices, std::span<index_t> new_indices){
1357 // indices may have grown by more than the target extra indices, so we compute an average extra indices per index set
1359 assert(new_count >= new_indices.size() && "Allocated index storage must be at least as large as the new count of indices after growth");
1361 const size_type extra_per_index_set = (new_indices.size() - total_used_indices) / (offsets.size() - 1);
1363 assert(extra_per_index_set >= min_extra_indices && "New index storage must accommodate at least min_extra_indices extra index per used index to ensure progress");
1373 auto it = SparseIndexRangeHelper<A>::lowerBound(old_index_set, std::numeric_limits<index_t>::max());
1377 new_size = std::min(new_size, new_indices.size() - offsets[i]); // ensure that we do not exceed the allocated size
1382 index_alloc_traits::construct(index_alloc, std::addressof(new_index_set[j]), old_index_set[j]);
1385 index_alloc_traits::construct(index_alloc, std::addressof(new_index_set[j]), std::numeric_limits<index_t>::max());
1387 // update offset for next index set by the new size of the current index set and move begin of old row to end of old row
1392 // due to averaging, it may happen that we do not use all the allocated indices, so we initialize the remaining tail of the new indices with invalid value
1394 index_alloc_traits::construct(index_alloc, std::addressof(new_indices[j]), std::numeric_limits<index_t>::max());
1411 constexpr DeallocationGuard(OtherAlloc allocator, typename alloc_traits::pointer ptr, typename alloc_traits::size_type size)
1440 constexpr SparseIndexRanges<I,A>::SparseIndexRanges(SequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1447 assert(builder.stage_ == SequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::Built && "Sparsity pattern is not in correct build mode");
1451 IndexVariant indices_var = Impl::SparseIndexRangeHelper<A>::template compress<IndexVariant>(std::span(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1465 constexpr SparseIndexRanges<I,A>::SparseIndexRanges(UnsequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1472 assert(builder.stage_ == UnsequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::BuildSetIndices && "Sparsity pattern is not in correct build mode");
1476 IndexVariant indices_var = Impl::SparseIndexRangeHelper<A>::template compress<IndexVariant>(std::span(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1610 constexpr SparseIndexRanges<I,A>::IndexIterator::IndexIterator(SparseIndexRanges const *csi, size_type i, size_type j)
1627 constexpr auto SparseIndexRanges<I,A>::IndexIterator::baseIterator() const -> const size_type &
1643 constexpr SparseIndexRanges<I,A>::IndexRangeView::IndexRangeView(const SparseIndexRanges *cis, size_type i)
1666 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::range() const -> IntegralRange<index_type>
1680 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::lower_bound(index_type j) const -> IndexIterator
1689 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::upper_bound(index_type j) const -> IndexIterator
1697 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::find(index_type j) const -> IndexIterator
1714 constexpr CompressedSparseIndexRanges<A>::CompressedSparseIndexRanges(SequencedSparseIndexRangeBuilder<OtherAlloc> &&builder)
1721 assert(builder.stage_ == SequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::Built && "Sparsity pattern is not in correct build mode");
1724 IndexVariant compressed_indices = Impl::SparseIndexRangeHelper<A>::compress(std::span<size_type>(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1738 constexpr CompressedSparseIndexRanges<A>::CompressedSparseIndexRanges(UnsequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1745 assert(builder.stage_ == UnsequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::BuildSetIndices && "Sparsity pattern is not in correct build mode");
1748 IndexVariant compressed_indices = Impl::SparseIndexRangeHelper<A>::compress(std::span<size_type>(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1821 constexpr auto CompressedSparseIndexRanges<A>::range() const noexcept -> IntegralRange<index_type>
1861 constexpr CompressedSparseIndexRanges<A>::Iterator::Iterator(CompressedSparseIndexRanges const *sp, size_type i)
1872 constexpr auto CompressedSparseIndexRanges<A>::Iterator::baseIterator() const -> const size_type &
1888 constexpr CompressedSparseIndexRanges<A>::IndexIterator::IndexIterator(CompressedSparseIndexRanges const *csi, size_type i, size_type j)
1907 constexpr auto CompressedSparseIndexRanges<A>::IndexIterator::baseIterator() const -> const size_type &
1923 constexpr CompressedSparseIndexRanges<A>::IndexRangeView::IndexRangeView(const CompressedSparseIndexRanges *cis, size_type i)
1946 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::range() const -> IntegralRange<index_type>
1952 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::contains(index_type j) const -> bool
1962 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::lower_bound(index_type j) const -> IndexIterator
1972 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::upper_bound(index_type j) const -> IndexIterator
1982 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::find(index_type j) const -> IndexIterator
1999 constexpr UnsequencedSparseIndexRangeBuilder<A>::UnsequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices, allocator_type allocator)
2029 constexpr void UnsequencedSparseIndexRangeBuilder<A>::incrementSize(size_type i, size_type increment)
2046 std::tie(indices_, offsets_[size_]) = Impl::SparseIndexRangeHelper<A>::initAllocateIndices(alloc_, offsets_[size_], is_size_);
2065 Impl::SparseIndexRangeHelper<A>::addIndex(std::span(indices + offsets[i], indices + offsets[i + 1]), jj, [this, i, offsets]() -> std::span<index_t> {
2079 constexpr SequencedSparseIndexRangeBuilder<A>::SequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices, allocator_type allocator)
2085 std::tie(indices_, offsets_[size_]) = Impl::SparseIndexRangeHelper<A>::initAllocateIndices(allocator, avg_indices * size_, is_size_);
2108 constexpr SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::IndexRangeBuilder(SequencedSparseIndexRangeBuilder* builder)
2120 constexpr SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::IndexRangeBuilder(IndexRangeBuilder && other) {
2125 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator=(IndexRangeBuilder && other) -> IndexRangeBuilder& {
2145 bool new_index_added = std::visit([offsets, j, i = i_, builder = builder_]<class index_t>(index_t * indices) {
2147 return Impl::SparseIndexRangeHelper<A>::addIndex(std::span(indices + offsets[i], indices + offsets[i + 1]), jj, [i, offsets, builder]() -> std::span<index_t> {
2150 // check if there is space left in the tail of the indices, if not, grow the indices by expanding the last index set
2152 Impl::SparseIndexRangeHelper<A>::growLastIndexRange(offsets, builder->indices_, growth_factor, builder->alloc_);
2153 // set new size of current index set by growth_factor times the current size or by the small index set threshold, whichever is larger
2154 size_type target_new_size = std::max<size_type>(std::max<size_type>(1, old_size * growth_factor), Impl::SPARSE_SEARCH_THRESHOLD/sizeof(index_type));
2170 constexpr void SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::overrideIndices(It begin,
2189 ? static_cast<double>(offsets.back() + (requested_count - available_count) + 1) / static_cast<double>(offsets.back())
2197 assert(offsets.back() - row_begin >= requested_count && "Growing index set failed to provide enough space for new indices");
2226 constexpr bool SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::contains(index_type j) const {
2249 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::index() const -> size_type {
2254 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator++() -> IndexRangeBuilder& {
2264 const std::size_t index_size = std::visit([]<class index_t>(index_t *) { return sizeof(index_t); }, builder_->indices_);
2267 offsets[i_ + 1] = std::min(offsets[i_] + std::max<size_type>(Impl::SPARSE_SEARCH_THRESHOLD/index_size, 1), offsets[builder_->size_]);
2275 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::size() const -> size_type {
2281 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator*() -> IndexRangeBuilder& {
Traits for sets of indices.
#define DUNE_NO_UNIQUE_ADDRESS
STL namespace.
Definition defaultmatrixvectortraits.hh:14
int size() const
SLList< T, A > & operator=(const SLList< T, A > &other)
bool empty() const
void increment()
void construct(pointer p, const_reference value)
void deallocate(pointer p, std::size_t n)
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
const_iterator find(int proc) const
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Compact storage of multiple sorted sparse index sets sharing a single allocation.
Definition sparseindexranges.hh:489
constexpr SparseIndexRanges(SparseIndexRanges &&other)
Move-construct, transferring ownership of storage from other. other is left in a valid but empty stat...
Definition sparseindexranges.hh:1488
constexpr SparseIndexRanges(SequencedSparseIndexRangeBuilder< OtherAlloc > &&builder)
Construct from a finished SequencedSparseIndexRangeBuilder, taking ownership of its storage and compr...
Definition sparseindexranges.hh:1440
constexpr IntegralRange< index_type > range() const noexcept
Returns the integer range [0, n) that every stored index belongs to.
Definition sparseindexranges.hh:1546
constexpr void swap(SparseIndexRanges &other)
Swap contents with other honoring allocator swap propagation traits.
Definition sparseindexranges.hh:1513
constexpr friend bool operator==(const SparseIndexRanges &p1, const SparseIndexRanges &p2)
Returns true if p1 and p2 contain identical index sets with identical values.
Definition sparseindexranges.hh:575
constexpr Iterator end() const
Returns an iterator past the last index set.
Definition sparseindexranges.hh:569
constexpr Iterator begin() const
Returns an iterator to the first index set (index set 0).
Definition sparseindexranges.hh:566
constexpr size_type size() const noexcept
Returns the number of index sets (e.g., the number of rows in a sparse matrix).
Definition sparseindexranges.hh:1540
constexpr ~SparseIndexRanges()
Destroy the index sets and release all allocated memory.
Definition sparseindexranges.hh:1534
friend constexpr void swap(SparseIndexRanges &lhs, SparseIndexRanges &rhs)
Swap contents of lhs and rhs, honoring allocator swap propagation traits.
Definition sparseindexranges.hh:540
std::ostream & print(std::ostream &os) const
Writes all index sets to os, one per line in the form "[i]: j0 j1 ...". Returns os.
Definition sparseindexranges.hh:1565
constexpr size_type offset(size_type i) const
Definition sparseindexranges.hh:1558
I index_type
Type of the indices.
Definition sparseindexranges.hh:509
typename alloc_traits::size_type size_type
Type to access the index sets.
Definition sparseindexranges.hh:506
constexpr SparseIndexRanges(UnsequencedSparseIndexRangeBuilder< OtherAlloc > &&builder)
Construct from a finished UnsequencedSparseIndexRangeBuilder, taking ownership of its storage and com...
Definition sparseindexranges.hh:1465
constexpr size_type count() const
Returns the total number of indices stored across all index sets (sum of all individual set sizes).
Definition sparseindexranges.hh:1552
A allocator_type
Allocator type used for memory management.
Definition sparseindexranges.hh:512
constexpr SparseIndexRanges & operator=(SparseIndexRanges &&other)
Move-assign, releasing current storage and transferring ownership from other. other is left in a vali...
Definition sparseindexranges.hh:1497
Compact storage of multiple sorted sparse index sets sharing a single allocation.
Definition sparseindexranges.hh:784
constexpr Iterator begin() const
Returns an iterator to the first index set (index set 0).
Definition sparseindexranges.hh:863
constexpr friend bool operator==(const CompressedSparseIndexRanges &p1, const CompressedSparseIndexRanges &p2)
Returns true if p1 and p2 contain identical index sets with identical values.
Definition sparseindexranges.hh:872
constexpr CompressedSparseIndexRanges & operator=(CompressedSparseIndexRanges &&other)
Move-assign, releasing current storage and transferring ownership from other. other is left in a vali...
Definition sparseindexranges.hh:1771
uint_fast64_t index_type
Type of the indices.
Definition sparseindexranges.hh:806
constexpr CompressedSparseIndexRanges(UnsequencedSparseIndexRangeBuilder< OtherAlloc > &&builder)
Construct from a finished UnsequencedSparseIndexRangeBuilder, taking ownership of its storage and com...
Definition sparseindexranges.hh:1738
constexpr CompressedSparseIndexRanges(CompressedSparseIndexRanges &&other)
Move-construct, transferring ownership of storage from other. other is left in a valid but empty stat...
Definition sparseindexranges.hh:1760
std::ostream & print(std::ostream &os) const
Writes all index sets to os, one per line in the form "[i]: j0 j1 ...". Returns os.
Definition sparseindexranges.hh:1841
constexpr size_type size() const noexcept
Returns the number of index sets (e.g., the number of rows in a sparse matrix).
Definition sparseindexranges.hh:1815
constexpr size_type offset(size_type i) const
Definition sparseindexranges.hh:1833
constexpr void swap(CompressedSparseIndexRanges &other)
Swap contents with other honoring allocator swap propagation traits.
Definition sparseindexranges.hh:1788
constexpr IntegralRange< index_type > range() const noexcept
Returns the integer range [0, n) that every stored index belongs to.
Definition sparseindexranges.hh:1821
constexpr size_type count() const
Returns the total number of indices stored across all index sets (sum of all individual set sizes).
Definition sparseindexranges.hh:1827
typename alloc_traits::size_type size_type
Type to access the index sets.
Definition sparseindexranges.hh:803
constexpr CompressedSparseIndexRanges(SequencedSparseIndexRangeBuilder< OtherAlloc > &&builder)
Construct from a finished SequencedSparseIndexRangeBuilder, taking ownership of its storage and compr...
Definition sparseindexranges.hh:1714
constexpr Iterator end() const
Returns an iterator past the last index set.
Definition sparseindexranges.hh:866
constexpr ~CompressedSparseIndexRanges()
Destroy the index sets and release all allocated memory.
Definition sparseindexranges.hh:1809
friend constexpr void swap(CompressedSparseIndexRanges &lhs, CompressedSparseIndexRanges &rhs)
Swap contents of lhs and rhs, honoring allocator swap propagation traits.
Definition sparseindexranges.hh:837
A allocator_type
Allocator type used for memory management.
Definition sparseindexranges.hh:809
Builder that allows inserting indices into any index set in any order.
Definition sparseindexranges.hh:244
constexpr ~UnsequencedSparseIndexRangeBuilder()
Definition sparseindexranges.hh:2016
constexpr void setSize(size_type i, size_type s)
Set the reserved size of the i-th index set to s. Must be called before addIndex().
Definition sparseindexranges.hh:2022
constexpr UnsequencedSparseIndexRangeBuilder(const UnsequencedSparseIndexRangeBuilder &)=delete
constexpr UnsequencedSparseIndexRangeBuilder & operator=(UnsequencedSparseIndexRangeBuilder &&)=delete
uint_fast64_t index_type
Type of the indices.
Definition sparseindexranges.hh:262
constexpr UnsequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices=0, allocator_type allocator=allocator_type())
Construct an unsequenced builder for size index sets with index range [0, is_size).
Definition sparseindexranges.hh:1999
typename std::allocator_traits< allocator_type >::size_type size_type
Type of the size parameters.
Definition sparseindexranges.hh:259
A allocator_type
Definition sparseindexranges.hh:256
constexpr void addIndex(size_type i, index_type j)
Insert index j into index set i. Duplicate insertions are silently ignored.
Definition sparseindexranges.hh:2050
constexpr UnsequencedSparseIndexRangeBuilder(UnsequencedSparseIndexRangeBuilder &&)=delete
constexpr UnsequencedSparseIndexRangeBuilder & operator=(const UnsequencedSparseIndexRangeBuilder &)=delete
constexpr void incrementSize(size_type i, size_type increment=1)
Increment the reserved size of the i-th index set by increment. Must be called before addIndex().
Definition sparseindexranges.hh:2029
Builder that fills index sets one at a time, in sequential order.
Definition sparseindexranges.hh:329
uint_fast64_t index_type
Type of the indices.
Definition sparseindexranges.hh:348
constexpr SequencedSparseIndexRangeBuilder(const SequencedSparseIndexRangeBuilder &)=delete
constexpr EndSentinel end()
Returns the end sentinel used to detect when all index sets have been filled.
Definition sparseindexranges.hh:2102
constexpr SequencedSparseIndexRangeBuilder(SequencedSparseIndexRangeBuilder &&)=delete
constexpr SequencedSparseIndexRangeBuilder & operator=(SequencedSparseIndexRangeBuilder &&)=delete
constexpr IndexRangeBuilder begin()
Returns an IndexRangeBuilder positioned at the first index set.
Definition sparseindexranges.hh:2096
constexpr SequencedSparseIndexRangeBuilder & operator=(const SequencedSparseIndexRangeBuilder &)=delete
constexpr SequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices=2048, allocator_type allocator=allocator_type())
Definition sparseindexranges.hh:2079
typename std::allocator_traits< allocator_type >::size_type size_type
Type of the size parameters.
Definition sparseindexranges.hh:345
A allocator_type
Definition sparseindexranges.hh:342
constexpr ~SequencedSparseIndexRangeBuilder()
Definition sparseindexranges.hh:2090
Definition sparseindexranges.hh:361
Handle for inserting indices into the current index set of a SequencedSparseIndexRangeBuilder.
Definition sparseindexranges.hh:375
constexpr friend bool operator==(const IndexRangeBuilder &is_builder, EndSentinel)
Returns true when all index sets have been filled (used to detect the end sentinel).
Definition sparseindexranges.hh:428
constexpr bool contains(index_type j) const
Returns true if index j has already been inserted into the current index set.
Definition sparseindexranges.hh:2226
constexpr IndexRangeBuilder(const IndexRangeBuilder &)=delete
constexpr size_type index() const
Returns the zero-based number of the index set currently being filled.
Definition sparseindexranges.hh:2249
constexpr IndexRangeBuilder & operator*()
Dereference — returns a reference to this IndexRangeBuilder itself (enables range-for).
Definition sparseindexranges.hh:2281
constexpr void insert(index_type j)
Insert index j into the current index set. Duplicate insertions are silently ignored.
Definition sparseindexranges.hh:2134
constexpr size_type size() const
Returns the number of distinct indices inserted into the current index set so far.
Definition sparseindexranges.hh:2275
constexpr IndexRangeBuilder & operator=(const IndexRangeBuilder &)=delete
constexpr void overrideIndices(It begin, End end, bool do_sort=true, bool do_unique=true)
Replace the current index set with the indices in [begin, end).
Definition sparseindexranges.hh:2170
constexpr ~IndexRangeBuilder()=default
constexpr IndexRangeBuilder & operator++()
Definition sparseindexranges.hh:2254
Random-access iterator over the index sets of a SparseIndexRanges.
Definition sparseindexranges.hh:614
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:621
typename Facade::reference reference
Definition sparseindexranges.hh:620
constexpr Iterator()=default
constexpr reference operator*() const
Definition sparseindexranges.hh:1588
Definition sparseindexranges.hh:646
constexpr size_type offset() const
Definition sparseindexranges.hh:1615
typename Facade::reference reference
Definition sparseindexranges.hh:650
constexpr reference operator*() const
Definition sparseindexranges.hh:1621
constexpr IndexIterator()=default
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:651
Read-only view of a single index set inside a SparseIndexRanges.
Definition sparseindexranges.hh:689
typename SparseIndexRanges< I, A >::index_type index_type
Type of the indices.
Definition sparseindexranges.hh:701
constexpr IndexIterator upper_bound(index_type i) const
Definition sparseindexranges.hh:1689
constexpr IntegralRange< index_type > range() const
Returns an integer range [0, n) usable as a local index range over this set.
Definition sparseindexranges.hh:1666
constexpr index_type back() const
Returns the last index in this index set. Precondition: the set is not empty.
Definition sparseindexranges.hh:723
constexpr void for_each(F &&f) const
Calls f(j) for every index j in this index set, in ascending order.
Definition sparseindexranges.hh:745
constexpr bool contains(index_type j) const
Returns true if index j is contained in this index set. Complexity: O(size()) for small sets,...
Definition sparseindexranges.hh:1672
constexpr IndexIterator lower_bound(index_type i) const
Returns an iterator to the first index >= i in this index set, or end() if none exists.
Definition sparseindexranges.hh:1680
constexpr IndexIterator end() const
Returns an iterator past the last index in this index set.
Definition sparseindexranges.hh:1654
constexpr index_type operator[](size_type i) const
Returns the index at local position i in this index set. Precondition: i < size().
Definition sparseindexranges.hh:726
constexpr index_type front() const
Returns the first index in this index set. Precondition: the set is not empty.
Definition sparseindexranges.hh:720
typename SparseIndexRanges< I, A >::size_type size_type
Definition sparseindexranges.hh:703
constexpr IndexIterator find(index_type i) const
Definition sparseindexranges.hh:1697
IndexRangeView()=default
constexpr IndexIterator begin() const
Returns an iterator to the first index in this index set.
Definition sparseindexranges.hh:1648
constexpr size_type size() const
Returns the number of indices in this index set.
Definition sparseindexranges.hh:1660
Random-access iterator over the index sets of a CompressedSparseIndexRanges.
Definition sparseindexranges.hh:912
typename Facade::reference reference
Definition sparseindexranges.hh:918
constexpr reference operator*() const
Definition sparseindexranges.hh:1866
constexpr Iterator()=default
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:919
Definition sparseindexranges.hh:944
constexpr reference operator*() const
Definition sparseindexranges.hh:1899
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:949
constexpr IndexIterator()=default
constexpr size_type offset() const
Definition sparseindexranges.hh:1893
typename Facade::reference reference
Definition sparseindexranges.hh:948
Read-only view of a single index set inside a CompressedSparseIndexRanges.
Definition sparseindexranges.hh:987
constexpr IndexIterator find(index_type i) const
Definition sparseindexranges.hh:1982
constexpr index_type front() const
Returns the first index in this index set. Precondition: the set is not empty.
Definition sparseindexranges.hh:1018
constexpr index_type operator[](size_type i) const
Returns the index at local position i in this index set. Precondition: i < size().
Definition sparseindexranges.hh:1024
constexpr index_type back() const
Returns the last index in this index set. Precondition: the set is not empty.
Definition sparseindexranges.hh:1021
constexpr void for_each(F &&f) const
Calls f(j) for every index j in this index set, in ascending order.
Definition sparseindexranges.hh:1043
constexpr IntegralRange< index_type > range() const
Returns an integer range [0, n) usable as a local index range over this set.
Definition sparseindexranges.hh:1946
typename CompressedSparseIndexRanges< A >::index_type index_type
Type of the indices.
Definition sparseindexranges.hh:999
constexpr IndexIterator upper_bound(index_type i) const
Definition sparseindexranges.hh:1972
constexpr size_type size() const
Returns the number of indices in this index set.
Definition sparseindexranges.hh:1940
IndexRangeView()=default
constexpr bool contains(index_type j) const
Returns true if index j is contained in this index set. Complexity: O(size()) for small sets,...
Definition sparseindexranges.hh:1952
constexpr IndexIterator end() const
Returns an iterator past the last index in this index set.
Definition sparseindexranges.hh:1934
constexpr IndexIterator lower_bound(index_type i) const
Returns an iterator to the first index >= i in this index set, or end() if none exists.
Definition sparseindexranges.hh:1962
constexpr IndexIterator begin() const
Returns an iterator to the first index in this index set.
Definition sparseindexranges.hh:1928
typename CompressedSparseIndexRanges< A >::size_type size_type
Definition sparseindexranges.hh:1001
static constexpr size_type offset(const index_range_type &index_set, const index_type &value)
Definition sparseindexranges.hh:1069
R index_range_type
Definition sparseindexranges.hh:1060
typename index_range_type::index_type index_type
Definition sparseindexranges.hh:1061
typename index_range_type::size_type size_type
Definition sparseindexranges.hh:1062
static constexpr IntegralRange< index_type > range(const index_range_type &index_set)
Definition sparseindexranges.hh:1064
T addressof(T... args)
T back(T... args)
T cbegin(T... args)
T copy_n(T... args)
T count_if(T... args)
T deallocate(T... args)
T distance(T... args)
T cend(T... args)
T endl(T... args)
T equal(T... args)
T exchange(T... args)
T exclusive_scan(T... args)
T fill(T... args)
T find_if(T... args)
T for_each(T... args)
T invoke(T... args)
T lower_bound(T... args)
T make_pair(T... args)
T max(T... args)
T min(T... args)
T next(T... args)
T size(T... args)
T sort(T... args)
T subspan(T... args)
T swap(T... args)
T tie(T... args)
T unique(T... args)
T upper_bound(T... args)
T visit(T... args)
Legal Statements / Impressum | Hosted by TU Dresden & Uni Heidelberg | Generated by
1.9.8