|
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");
1139 index_alloc_traits::construct(index_alloc, std::addressof(indices_ptr[i]), std::numeric_limits<index_t>::max());
1146 constexpr void SparseIndexRangeHelper<A>::deallocate(const allocator_type& allocator, IndexVariant indices, size_type* offsets, size_type size) {
1165 constexpr V SparseIndexRangeHelper<A>::compress(std::span<size_type> offsets, IndexVariant indices, const allocator_type& alloc)
1175 std::for_each(std::cbegin(old_index_set), std::cend(old_index_set), [&count_invalid, &max_index](old_index_t j) {
1183 // nothing to do if there are no undefined indices and the indices already use the selected index type
1192 // allocate new arrays for offsets and indices. We use scope guards to ensure that the allocated memory is freed in case of exceptions.
1195 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<size_alloc_type> offsetsScopeGuard{size_alloc, new_offsets, offsets.size()};
1197 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 {
1201 new_indices_ptr = new_index_alloc_traits::allocate(new_index_alloc, index_count - count_invalid);
1202 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<new_index_alloc_type> newIndicesScopeGuard{new_index_alloc, new_indices_ptr, index_count - count_invalid};
1209 size_type is_count = std::count_if(std::cbegin(old_index_set), std::cend(old_index_set), index_defined);
1211 size_alloc_traits::construct(size_alloc, std::addressof(new_offsets[i + 1]), new_offsets[i] + is_count);
1217 new_index_alloc_traits::construct(new_index_alloc, std::addressof(new_index_set[j++]), static_cast<new_index_t>(old_idx));
1225 typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<old_index_alloc_type> oldIndicesScopeGuard{old_index_alloc_type(size_alloc), old_indices, index_count};
1236 constexpr bool SparseIndexRangeHelper<A>::addIndex(std::span<index_t> index_set, index_t j, std::invocable auto grow_index_set_fn)
1254 assert(index_set.size() > dist && "Too many entries in index set but the builder cannot grow the indices");
1255 assert(index_set.back() == invalid_index && "Growth function must initialize new indices with invalid value");
1269 constexpr void SparseIndexRangeHelper<A>::growIndices(std::span<size_type> offsets, IndexVariant& indices, size_type new_count, const allocator_type& allocator, auto uninitialized_copy_fn){
1274 // allocate new arrays for indices. We use scope guards to ensure that the allocated memory is freed in case of exceptions.
1275 std::visit([&indices, &allocator, &uninitialized_copy_fn, offsets, old_count, new_count]<typename index_t>(index_t * old_indices) {
1278 using dealloc_guard_type = typename Impl::SparseIndexRangeHelper<A>::template DeallocationGuard<index_alloc_type>;
1283 std::tie(new_indices, allocated_count) = index_alloc_traits::allocate_at_least(index_alloc, allocated_count);
1290 uninitialized_copy_fn(offsets, std::span<const index_t>(old_indices, old_count), std::span(new_indices, allocated_count));
1296 indices = IndexVariant{std::in_place_type<index_t *>, std::exchange(newIndicesScopeGuard.ptr, nullptr)};
1301 constexpr void SparseIndexRangeHelper<A>::growLastIndexRange(std::span<size_type> offsets, IndexVariant& indices, double growth_factor, const allocator_type& allocator){
1304 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){
1314 index_alloc_traits::construct(index_alloc, std::addressof(new_indices[j]), std::numeric_limits<index_t>::max());
1322 constexpr void SparseIndexRangeHelper<A>::growAllIndexRanges(std::span<size_type> offsets, IndexVariant& indices, double target_growth_factor, const allocator_type& allocator){
1329 // 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
1330 std::visit([offsets, &max_is_used, &total_used_indices]<class index_t>(index_t const * indices_ptr) {
1331 // 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
1344 size_type target_extra_per_index_set = std::max(static_cast<size_type>(max_is_used*(target_growth_factor - 1.)), min_extra_indices);
1348 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){
1353 // indices may have grown by more than the target extra indices, so we compute an average extra indices per index set
1355 assert(new_count >= new_indices.size() && "Allocated index storage must be at least as large as the new count of indices after growth");
1357 const size_type extra_per_index_set = (new_indices.size() - total_used_indices) / (offsets.size() - 1);
1359 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");
1369 auto it = SparseIndexRangeHelper<A>::lowerBound(old_index_set, std::numeric_limits<index_t>::max());
1373 new_size = std::min(new_size, new_indices.size() - offsets[i]); // ensure that we do not exceed the allocated size
1378 index_alloc_traits::construct(index_alloc, std::addressof(new_index_set[j]), old_index_set[j]);
1381 index_alloc_traits::construct(index_alloc, std::addressof(new_index_set[j]), std::numeric_limits<index_t>::max());
1383 // 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
1388 // 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
1390 index_alloc_traits::construct(index_alloc, std::addressof(new_indices[j]), std::numeric_limits<index_t>::max());
1407 constexpr DeallocationGuard(OtherAlloc allocator, typename alloc_traits::pointer ptr, typename alloc_traits::size_type size)
1436 constexpr SparseIndexRanges<I,A>::SparseIndexRanges(SequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1443 assert(builder.stage_ == SequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::Built && "Sparsity pattern is not in correct build mode");
1447 IndexVariant indices_var = Impl::SparseIndexRangeHelper<A>::template compress<IndexVariant>(std::span(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1461 constexpr SparseIndexRanges<I,A>::SparseIndexRanges(UnsequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1468 assert(builder.stage_ == UnsequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::BuildSetIndices && "Sparsity pattern is not in correct build mode");
1472 IndexVariant indices_var = Impl::SparseIndexRangeHelper<A>::template compress<IndexVariant>(std::span(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1606 constexpr SparseIndexRanges<I,A>::IndexIterator::IndexIterator(SparseIndexRanges const *csi, size_type i, size_type j)
1623 constexpr auto SparseIndexRanges<I,A>::IndexIterator::baseIterator() const -> const size_type &
1639 constexpr SparseIndexRanges<I,A>::IndexRangeView::IndexRangeView(const SparseIndexRanges *cis, size_type i)
1662 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::range() const -> IntegralRange<index_type>
1676 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::lower_bound(index_type j) const -> IndexIterator
1685 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::upper_bound(index_type j) const -> IndexIterator
1693 constexpr auto SparseIndexRanges<I,A>::IndexRangeView::find(index_type j) const -> IndexIterator
1710 constexpr CompressedSparseIndexRanges<A>::CompressedSparseIndexRanges(SequencedSparseIndexRangeBuilder<OtherAlloc> &&builder)
1717 assert(builder.stage_ == SequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::Built && "Sparsity pattern is not in correct build mode");
1720 IndexVariant compressed_indices = Impl::SparseIndexRangeHelper<A>::compress(std::span<size_type>(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1734 constexpr CompressedSparseIndexRanges<A>::CompressedSparseIndexRanges(UnsequencedSparseIndexRangeBuilder<OtherAlloc>&& builder)
1741 assert(builder.stage_ == UnsequencedSparseIndexRangeBuilder<OtherAlloc>::Stage::BuildSetIndices && "Sparsity pattern is not in correct build mode");
1744 IndexVariant compressed_indices = Impl::SparseIndexRangeHelper<A>::compress(std::span<size_type>(builder.offsets_, size_ + 1), builder.indices_, alloc_);
1817 constexpr auto CompressedSparseIndexRanges<A>::range() const noexcept -> IntegralRange<index_type>
1857 constexpr CompressedSparseIndexRanges<A>::Iterator::Iterator(CompressedSparseIndexRanges const *sp, size_type i)
1868 constexpr auto CompressedSparseIndexRanges<A>::Iterator::baseIterator() const -> const size_type &
1884 constexpr CompressedSparseIndexRanges<A>::IndexIterator::IndexIterator(CompressedSparseIndexRanges const *csi, size_type i, size_type j)
1903 constexpr auto CompressedSparseIndexRanges<A>::IndexIterator::baseIterator() const -> const size_type &
1919 constexpr CompressedSparseIndexRanges<A>::IndexRangeView::IndexRangeView(const CompressedSparseIndexRanges *cis, size_type i)
1942 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::range() const -> IntegralRange<index_type>
1948 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::contains(index_type j) const -> bool
1958 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::lower_bound(index_type j) const -> IndexIterator
1968 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::upper_bound(index_type j) const -> IndexIterator
1978 constexpr auto CompressedSparseIndexRanges<A>::IndexRangeView::find(index_type j) const -> IndexIterator
1995 constexpr UnsequencedSparseIndexRangeBuilder<A>::UnsequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices, allocator_type allocator)
2025 constexpr void UnsequencedSparseIndexRangeBuilder<A>::incrementSize(size_type i, size_type increment)
2042 std::tie(indices_, offsets_[size_]) = Impl::SparseIndexRangeHelper<A>::initAllocateIndices(alloc_, offsets_[size_], is_size_);
2061 Impl::SparseIndexRangeHelper<A>::addIndex(std::span(indices + offsets[i], indices + offsets[i + 1]), jj, [this, i, offsets]() -> std::span<index_t> {
2075 constexpr SequencedSparseIndexRangeBuilder<A>::SequencedSparseIndexRangeBuilder(size_type size, size_type is_size, size_type avg_indices, allocator_type allocator)
2081 std::tie(indices_, offsets_[size_]) = Impl::SparseIndexRangeHelper<A>::initAllocateIndices(allocator, avg_indices * size_, is_size_);
2104 constexpr SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::IndexRangeBuilder(SequencedSparseIndexRangeBuilder* builder)
2116 constexpr SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::IndexRangeBuilder(IndexRangeBuilder && other) {
2121 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator=(IndexRangeBuilder && other) -> IndexRangeBuilder& {
2141 bool new_index_added = std::visit([offsets, j, i = i_, builder = builder_]<class index_t>(index_t * indices) {
2143 return Impl::SparseIndexRangeHelper<A>::addIndex(std::span(indices + offsets[i], indices + offsets[i + 1]), jj, [i, offsets, builder]() -> std::span<index_t> {
2146 // check if there is space left in the tail of the indices, if not, grow the indices by expanding the last index set
2148 Impl::SparseIndexRangeHelper<A>::growLastIndexRange(offsets, builder->indices_, growth_factor, builder->alloc_);
2149 // set new size of current index set by growth_factor times the current size or by the small index set threshold, whichever is larger
2150 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));
2166 constexpr void SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::overrideIndices(It begin,
2185 ? static_cast<double>(offsets.back() + (requested_count - available_count) + 1) / static_cast<double>(offsets.back())
2193 assert(offsets.back() - row_begin >= requested_count && "Growing index set failed to provide enough space for new indices");
2222 constexpr bool SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::contains(index_type j) const {
2245 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::index() const -> size_type {
2250 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator++() -> IndexRangeBuilder& {
2260 const std::size_t index_size = std::visit([]<class index_t>(index_t *) { return sizeof(index_t); }, builder_->indices_);
2263 offsets[i_ + 1] = std::min(offsets[i_] + std::max<size_type>(Impl::SPARSE_SEARCH_THRESHOLD/index_size, 1), offsets[builder_->size_]);
2271 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::size() const -> size_type {
2277 constexpr auto SequencedSparseIndexRangeBuilder<A>::IndexRangeBuilder::operator*() -> IndexRangeBuilder& {
Traits for sets of indices.
#define DUNE_NO_UNIQUE_ADDRESS
STL namespace.
Definition experimental/bcrsmatrix.hh:21
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
void swap(T &v1, T &v2, bool mask)
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:1484
constexpr SparseIndexRanges(SequencedSparseIndexRangeBuilder< OtherAlloc > &&builder)
Construct from a finished SequencedSparseIndexRangeBuilder, taking ownership of its storage and compr...
Definition sparseindexranges.hh:1436
constexpr IntegralRange< index_type > range() const noexcept
Returns the integer range [0, n) that every stored index belongs to.
Definition sparseindexranges.hh:1542
constexpr void swap(SparseIndexRanges &other)
Swap contents with other honoring allocator swap propagation traits.
Definition sparseindexranges.hh:1509
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:1536
constexpr ~SparseIndexRanges()
Destroy the index sets and release all allocated memory.
Definition sparseindexranges.hh:1530
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:1561
constexpr size_type offset(size_type i) const
Definition sparseindexranges.hh:1554
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:1461
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:1548
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:1493
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:1767
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:1734
constexpr CompressedSparseIndexRanges(CompressedSparseIndexRanges &&other)
Move-construct, transferring ownership of storage from other. other is left in a valid but empty stat...
Definition sparseindexranges.hh:1756
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:1837
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:1811
constexpr size_type offset(size_type i) const
Definition sparseindexranges.hh:1829
constexpr void swap(CompressedSparseIndexRanges &other)
Swap contents with other honoring allocator swap propagation traits.
Definition sparseindexranges.hh:1784
constexpr IntegralRange< index_type > range() const noexcept
Returns the integer range [0, n) that every stored index belongs to.
Definition sparseindexranges.hh:1817
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:1823
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:1710
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:1805
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:2012
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:2018
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:1995
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:2046
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:2025
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:2098
constexpr SequencedSparseIndexRangeBuilder(SequencedSparseIndexRangeBuilder &&)=delete
constexpr SequencedSparseIndexRangeBuilder & operator=(SequencedSparseIndexRangeBuilder &&)=delete
constexpr IndexRangeBuilder begin()
Returns an IndexRangeBuilder positioned at the first index set.
Definition sparseindexranges.hh:2092
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:2075
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:2086
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:2222
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:2245
constexpr IndexRangeBuilder & operator*()
Dereference — returns a reference to this IndexRangeBuilder itself (enables range-for).
Definition sparseindexranges.hh:2277
constexpr void insert(index_type j)
Insert index j into the current index set. Duplicate insertions are silently ignored.
Definition sparseindexranges.hh:2130
constexpr size_type size() const
Returns the number of distinct indices inserted into the current index set so far.
Definition sparseindexranges.hh:2271
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:2166
constexpr ~IndexRangeBuilder()=default
constexpr IndexRangeBuilder & operator++()
Definition sparseindexranges.hh:2250
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:1584
Definition sparseindexranges.hh:646
constexpr size_type offset() const
Definition sparseindexranges.hh:1611
typename Facade::reference reference
Definition sparseindexranges.hh:650
constexpr reference operator*() const
Definition sparseindexranges.hh:1617
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:1685
constexpr IntegralRange< index_type > range() const
Returns an integer range [0, n) usable as a local index range over this set.
Definition sparseindexranges.hh:1662
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:1668
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:1676
constexpr IndexIterator end() const
Returns an iterator past the last index in this index set.
Definition sparseindexranges.hh:1650
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:1693
IndexRangeView()=default
constexpr IndexIterator begin() const
Returns an iterator to the first index in this index set.
Definition sparseindexranges.hh:1644
constexpr size_type size() const
Returns the number of indices in this index set.
Definition sparseindexranges.hh:1656
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:1862
constexpr Iterator()=default
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:919
Definition sparseindexranges.hh:944
constexpr reference operator*() const
Definition sparseindexranges.hh:1895
typename Facade::difference_type difference_type
Definition sparseindexranges.hh:949
constexpr IndexIterator()=default
constexpr size_type offset() const
Definition sparseindexranges.hh:1889
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:1978
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:1942
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:1968
constexpr size_type size() const
Returns the number of indices in this index set.
Definition sparseindexranges.hh:1936
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:1948
constexpr IndexIterator end() const
Returns an iterator past the last index in this index set.
Definition sparseindexranges.hh:1930
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:1958
constexpr IndexIterator begin() const
Returns an iterator to the first index in this index set.
Definition sparseindexranges.hh:1924
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