30 #define define_as(member) \ 31 template<typename T> \ 32 std::vector<T> member##_as() const { \ 33 std::vector<T> asvec(member.begin(), member.end()); \ 50 using value_type = size_t;
52 std::vector<size_t> offsets;
53 std::vector<size_t> indices;
55 define_as(offsets) define_as(indices)
61 return offsets.size() - 1;
65 void erase(
const std::vector<size_t> & ids) {
71 assert(std::is_sorted(ids.begin(), ids.end()) &&
72 "entries to delete are not sorted");
74 auto num_remove = ids.size();
75 auto num_offsets = size();
77 std::vector<size_t> new_offsets(offsets.size() - num_remove);
78 std::vector<size_t> new_indices;
79 new_indices.reserve(indices.size());
82 auto delete_it = ids.begin();
84 for(
size_t iold = 0, inew = 0; iold < num_offsets; ++iold) {
87 if(delete_it != ids.end()) {
88 if(*delete_it == iold) {
95 auto start = offsets[iold];
96 auto end = offsets[iold + 1];
97 for(
auto j =
start; j < end; ++j) {
98 new_indices.push_back(indices[j]);
100 new_offsets[inew + 1] = new_indices.size();
104 assert(new_offsets.size() == offsets.size() - num_remove);
107 std::swap(offsets, new_offsets);
108 std::swap(indices, new_indices);
123 iterator(
crs & data,
size_t pos = 0) : data_(data), pos_(pos) {}
125 auto i = data_.offsets[pos_];
126 auto n = data_.offsets[pos_ + 1] - i;
127 return util::make_array_ref(&data_.indices[i], n);
129 auto & operator++() {
133 auto operator++(
int) {
138 bool operator!=(
const iterator & it)
const {
139 return (pos_ != it.pos_ || &data_ != &it.data_);
151 auto i = data_.offsets[pos_];
152 auto n = data_.offsets[pos_ + 1] - i;
153 return util::make_array_ref(&data_.indices[i], n);
155 auto & operator++() {
159 auto operator++(
int) {
165 return (pos_ != it.pos_ || &data_ != &it.data_);
184 assert(i < size() &&
"index out of range");
187 auto at(
size_t i)
const {
188 assert(i < size() &&
"index out of range");
191 auto operator[](
size_t i) {
194 auto operator[](
size_t i)
const {
198 template<
typename InputIt>
199 void append(InputIt first, InputIt last) {
203 offsets.emplace_back(0);
204 offsets.emplace_back(offsets.back() + std::distance(first, last));
205 indices.insert(indices.end(), first, last);
209 void append(
const U & value) {
211 append(ptr, ptr + 1);
215 void push_back(std::initializer_list<U> init) {
216 append(init.begin(), init.end());
219 template<
typename U,
template<
typename>
class Vector>
220 void push_back(
const Vector<U> & init) {
221 append(init.begin(), init.end());
230 inline std::ostream &
232 stream <<
"offsets: ";
233 for(
auto i : crs.offsets) {
238 stream <<
"indices: ";
239 for(
auto i : crs.indices) {
255 std::vector<size_t> distribution;
262 distribution.clear();
271 inline std::ostream &
273 stream << static_cast<const crs &>(dcrs) << std::endl;
275 stream <<
"distribution: ";
276 for(
auto i : dcrs.distribution) {
void clear()
clears the current storage
Definition: crs.hh:112
std::ostream & operator<<(std::ostream &ostr, const filling_curve< D, T, DER > &k)
output for filling_curve using output_ function defined in the class
Definition: filling_curve.hh:206
constexpr point< TYPE, DIMENSION > operator*(TYPE const val, point< TYPE, DIMENSION > const &p)
Definition: point.hh:52
int start(const std::function< int()> &action)
Definition: execution.hh:69
define_as(distribution) void clear()
clears the current storage
Definition: crs.hh:257
void erase(const std::vector< size_t > &ids)
erase a bunch of ids
Definition: crs.hh:65
Definition: control.hh:31