DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
AdjacencyRow.hpp
Go to the documentation of this file.
1#pragma once
2/// @file AdjacencyRow.hpp
3/// @brief Non-owning row view for adjacency arrays.
4
5#include "../Defines.hpp"
6
7namespace DNDS
8{
9 /**
10 * @brief Non-owning span `(pointer, size)` into an @ref DNDS::ArrayAdjacency "ArrayAdjacency" row.
11 *
12 * @details Serves as the return value of `ArrayAdjacency::operator[]`.
13 * It is the "typed row handle" equivalent of `std::span<index_T>` with a
14 * few DNDSR-specific conveniences:
15 * - indexing is bounds-checked in debug (@ref DNDS_assert);
16 * - assignment from / conversion to `std::vector<index>`;
17 * - device-callable accessors so kernels can walk adjacency rows.
18 *
19 * The span does not own the underlying storage; it must not outlive the
20 * backing @ref DNDS::ArrayAdjacency "ArrayAdjacency".
21 *
22 * @tparam index_T Either `DNDS::index` (mutable) or `const DNDS::index`.
23 */
24 template <typename index_T = index>
25 class AdjacencyRow // instead of std::vector<index> for building on raw buffer as a "mapping" object
26 {
27 index_T *__p_indices;
28 rowsize __Row_size;
29
30 public:
31 //! the copy is not trivial!
32 // DNDS_DEVICE_TRIVIAL_COPY_DEFINE(AdjacencyRow, AdjacencyRow)
33
37 /// @brief Construct a span from raw pointer and size.
38 DNDS_DEVICE_CALLABLE AdjacencyRow(index_T *ptr, rowsize siz) : __p_indices(ptr), __Row_size(siz) {} // default actually
39
40 /// @brief Bounds-checked (debug) element access.
42 {
43 DNDS_assert(j >= 0 && j < __Row_size);
44 return __p_indices[j];
45 }
46
48 {
49 DNDS_assert(j >= 0 && j < __Row_size);
50 return __p_indices[j];
51 }
52
53 /// @brief Copy the row into a new `std::vector<index>`.
54 operator std::vector<index>() const // copies to a new std::vector<index>
55 {
56 return {__p_indices, __p_indices + __Row_size};
57 }
58
59 /// @brief Overwrite the row from a vector of the same size.
60 void operator=(const std::vector<index> &r)
61 {
62 DNDS_assert(__Row_size == r.size());
63 std::copy(r.begin(), r.end(), __p_indices);
64 }
65
66 /// @brief Copy contents of another span (same size required).
68 {
69 DNDS_assert(__Row_size == r.size());
70 std::copy(r.cbegin(), r.cend(), __p_indices);
71 }
72
73 DNDS_DEVICE_CALLABLE index_T *begin() { return __p_indices; }
74 DNDS_DEVICE_CALLABLE index_T *end() { return __p_indices + __Row_size; } // past-end
75 DNDS_DEVICE_CALLABLE index_T *cbegin() const { return __p_indices; }
76 DNDS_DEVICE_CALLABLE index_T *cend() const { return __p_indices + __Row_size; } // past-end
77 /// @brief Row width in number of `index_T` elements.
78 DNDS_DEVICE_CALLABLE [[nodiscard]] rowsize size() const { return __Row_size; }
79 };
80}
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
Non-owning span (pointer, size) into an ArrayAdjacency row.
DNDS_DEVICE_CALLABLE index_T operator[](rowsize j) const
DNDS_DEVICE_CALLABLE index_T * cbegin() const
DNDS_DEVICE_CALLABLE AdjacencyRow(index_T *ptr, rowsize siz)
Construct a span from raw pointer and size.
DNDS_DEVICE_CALLABLE index_T * cend() const
DNDS_DEVICE_CALLABLE index_T & operator[](rowsize j)
Bounds-checked (debug) element access.
DNDS_DEVICE_CALLABLE index_T * end()
void operator=(const std::vector< index > &r)
Overwrite the row from a vector of the same size.
DNDS_DEVICE_CALLABLE AdjacencyRow()=default
the copy is not trivial!
DNDS_DEVICE_CALLABLE AdjacencyRow(const AdjacencyRow &)=default
DNDS_DEVICE_CALLABLE ~AdjacencyRow()=default
DNDS_DEVICE_CALLABLE void operator=(const AdjacencyRow &r)
Copy contents of another span (same size required).
DNDS_DEVICE_CALLABLE index_T * begin()
DNDS_DEVICE_CALLABLE rowsize size() const
Row width in number of index_T elements.
the host side operators are provided as implemented
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:109
tVec r(NCells)