Interface Documentation
Version: invalid
index_space.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Los Alamos National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <algorithm>
19 #include <functional>
20 #include <map>
21 #include <type_traits>
22 #include <vector>
23 
24 namespace flecsi {
25 namespace topo {
26 
27 /*----------------------------------------------------------------------------*
28  * class index_space
29  *----------------------------------------------------------------------------*/
30 
31 template<size_t, class E>
32 class domain_entity;
33 
35 template<typename T>
37  using type = T &;
38 };
39 
41 template<typename S>
42 struct index_space_ref_type<S *> {
43  using type = S *;
44 };
45 
47 template<size_t M, class E>
49  using type = domain_entity<M, E>;
50 };
51 
52 //----------------------------------------------------------------------------//
77 //----------------------------------------------------------------------------//
78 template<class T,
79  bool STORAGE = false,
80  bool OWNED = true,
81  bool SORTED = false,
82  class F = void,
83  template<typename, typename...> class ID_STORAGE_TYPE = std::vector,
84  template<typename, typename...> class STORAGE_TYPE = ID_STORAGE_TYPE>
86 {
87 public:
89  using id_t = typename std::remove_pointer<T>::type::id_t;
90 
92  using id_storage_t = ID_STORAGE_TYPE<id_t>;
93 
95  using storage_t = STORAGE_TYPE<T>;
96 
99 
101  using ref_t = typename index_space_ref_type<T>::type;
102 
104  using cast_t = std::decay_t<ref_t>;
105 
107  using apply_function = std::function<void(T &)>;
108 
110  template<typename S>
111  using map_function = std::function<S(T &)>;
112 
114  template<typename S>
115  using reduce_function = std::function<void(T &, S &)>;
116 
117  //--------------------------------------------------------------------------//
121  //--------------------------------------------------------------------------//
122  class id_range_
123  {
124  public:
125  //-----------------------------------------------------------------//
127  //-----------------------------------------------------------------//
128  id_range_(const id_storage_t & items)
129  : items_(&items), begin_(0), end_(items_->size()) {}
130 
131  //-----------------------------------------------------------------//
133  //-----------------------------------------------------------------//
134  id_range_(const id_storage_t & items, size_t begin, size_t end)
135  : items_(&items), begin_(begin), end_(end) {}
136 
137  //-----------------------------------------------------------------//
139  //-----------------------------------------------------------------//
140  typename id_storage_t::const_iterator begin() const {
141  return items_->begin() + begin_;
142  }
143 
144  //-----------------------------------------------------------------//
146  //-----------------------------------------------------------------//
147  typename id_storage_t::const_iterator end() const {
148  return items_->begin() + end_;
149  }
150 
151  private:
152  const id_storage_t * items_;
153  size_t begin_;
154  size_t end_;
155  };
156 
157  //------------------------------------------------------------------//
159  //------------------------------------------------------------------//
160  template<class S>
162  {
163  public:
164  //-----------------------------------------------------------------//
166  //-----------------------------------------------------------------//
168  const id_storage_t & items,
169  size_t index,
170  size_t end)
171  : items_(&items), index_(index), end_(end), s_(s) {}
172 
173  //-----------------------------------------------------------------//
175  //-----------------------------------------------------------------//
177  const id_storage_t & items,
178  size_t index,
179  size_t end)
180  : items_(&items), index_(index), end_(end),
181  s_(const_cast<storage_t *>(s)) {}
182 
183  //-----------------------------------------------------------------//
185  //-----------------------------------------------------------------//
186  bool operator==(const iterator_base_ & itr) const {
187  return index_ == itr.index_;
188  }
189 
190  //-----------------------------------------------------------------//
192  //-----------------------------------------------------------------//
193  bool operator!=(const iterator_base_ & itr) const {
194  return index_ != itr.index_;
195  }
196 
197  //-----------------------------------------------------------------//
199  //-----------------------------------------------------------------//
200  bool operator<(const iterator_base_ & itr) const {
201  return index_ < itr.index_;
202  }
203 
204  //-----------------------------------------------------------------//
206  //-----------------------------------------------------------------//
207  bool operator<=(const iterator_base_ & itr) const {
208  return index_ <= itr.index_;
209  }
210 
211  //-----------------------------------------------------------------//
213  //-----------------------------------------------------------------//
214  bool operator>(const iterator_base_ & itr) const {
215  return index_ > itr.index_;
216  }
217 
218  //-----------------------------------------------------------------//
220  //-----------------------------------------------------------------//
221  bool operator>=(const iterator_base_ & itr) const {
222  return index_ >= itr.index_;
223  }
224 
225  //-----------------------------------------------------------------//
227  //-----------------------------------------------------------------//
228  size_t operator-(const iterator_base_ & itr) const {
229  return index_ - itr.index_;
230  }
231 
232  //-----------------------------------------------------------------//
234  //-----------------------------------------------------------------//
235  auto get_(size_t index) {
236  return static_cast<cast_t>((*s_)[(*items_)[index].index_space_index()]);
237  }
238 
239  //-----------------------------------------------------------------//
241  //-----------------------------------------------------------------//
242  auto operator[](size_t index) const {
243  return get_(index);
244  }
245 
246  protected:
247  const id_storage_t * items_;
248  size_t index_;
249  size_t end_;
250  storage_t * s_;
251  };
252 
253  //------------------------------------------------------------------------//
260  //------------------------------------------------------------------------//
261  template<class S, class P>
262  class iterator_ : public iterator_base_<S>
263  {
264  public:
265  using B = iterator_base_<S>;
266 
267  //-----------------------------------------------------------------//
269  //-----------------------------------------------------------------//
271  const id_storage_t & items,
272  size_t index,
273  size_t end)
274  : B(s, items, index, end) {}
275 
276  //-----------------------------------------------------------------//
278  //-----------------------------------------------------------------//
279  iterator_(const storage_t * s,
280  const id_storage_t & items,
281  size_t index,
282  size_t end)
283  : B(s, items, index, end) {}
284 
285  //-----------------------------------------------------------------//
287  //-----------------------------------------------------------------//
289  ++B::index_;
290  return *this;
291  }
292 
293  //-----------------------------------------------------------------//
295  //-----------------------------------------------------------------//
297  --B::index_;
298  return *this;
299  }
300 
301  //-----------------------------------------------------------------//
303  //-----------------------------------------------------------------//
305  iterator_ itr(*this);
306  B::index_++;
307  return itr;
308  }
309 
310  //-----------------------------------------------------------------//
312  //-----------------------------------------------------------------//
314  iterator_ itr(*this);
315  B::index_--;
316  return itr;
317  }
318 
319  //-----------------------------------------------------------------//
321  //-----------------------------------------------------------------//
322  iterator_ operator+(size_t offset) const {
323  iterator_ itr(*this);
324  itr.B::index_ += offset;
325  return itr;
326  }
327 
328  //-----------------------------------------------------------------//
330  //-----------------------------------------------------------------//
331  friend iterator_ operator+(size_t offset, const iterator_ & itr) {
332  iterator_ itr2(itr);
333  itr2.B::index_ += offset;
334  return itr2;
335  }
336 
337  //-----------------------------------------------------------------//
339  //-----------------------------------------------------------------//
340  iterator_ operator-(size_t offset) const {
341  iterator_ itr(*this);
342  itr.B::index_ -= offset;
343  return itr;
344  }
345 
346  //-----------------------------------------------------------------//
348  //-----------------------------------------------------------------//
349  friend iterator_ operator-(size_t offset, const iterator_ & itr) {
350  iterator_ itr2(itr);
351  itr2.B::index_ = offset - itr.B::index_;
352  return itr2;
353  }
354 
355  //-----------------------------------------------------------------//
357  //-----------------------------------------------------------------//
358  iterator_ & operator+=(size_t offset) {
359  B::index_ += offset;
360  return *this;
361  }
362 
363  //-----------------------------------------------------------------//
365  //-----------------------------------------------------------------//
366  iterator_ & operator-=(size_t offset) {
367  B::index_ -= offset;
368  return *this;
369  }
370 
371  //-----------------------------------------------------------------//
373  //-----------------------------------------------------------------//
374  S & operator*() {
375  while(B::index_ < B::end_) {
376  T & item = B::get_(B::index_);
377  if(P()(item)) {
378  return item;
379  }
380  ++B::index_;
381  }
382 
383  assert(false && "end of range");
384  }
385 
386  //-----------------------------------------------------------------//
388  //-----------------------------------------------------------------//
389  S * operator->() {
390  while(B::index_ < B::end_) {
391  T & item = B::get_(B::index_);
392  if(P()(item)) {
393  return &item;
394  }
395  ++B::index_;
396  }
397 
398  assert(false && "end of range");
399  }
400  };
401 
402  //------------------------------------------------------------------------//
408  //------------------------------------------------------------------------//
409  template<class S>
410  class iterator_<S, void> : public iterator_base_<S>
411  {
412  public:
413  using B = iterator_base_<S>;
414 
416 
417  //-----------------------------------------------------------------//
419  //-----------------------------------------------------------------//
421  const id_storage_t & items,
422  size_t index,
423  size_t end)
424  : B(s, items, index, end) {}
425 
426  //-----------------------------------------------------------------//
428  //-----------------------------------------------------------------//
429  iterator_(const storage_t * s,
430  const id_storage_t & items,
431  size_t index,
432  size_t end)
433  : B(s, items, index, end) {}
434 
435  //-----------------------------------------------------------------//
437  //-----------------------------------------------------------------//
439  ++B::index_;
440  return *this;
441  }
442 
443  //-----------------------------------------------------------------//
445  //-----------------------------------------------------------------//
447  --B::index_;
448  return *this;
449  }
450 
451  //-----------------------------------------------------------------//
453  //-----------------------------------------------------------------//
455  iterator_ itr(*this);
456  B::index_++;
457  return itr;
458  }
459 
460  //-----------------------------------------------------------------//
462  //-----------------------------------------------------------------//
464  iterator_ itr(*this);
465  B::index_--;
466  return itr;
467  }
468 
469  //-----------------------------------------------------------------//
471  //-----------------------------------------------------------------//
472  iterator_ operator+(size_t offset) const {
473  iterator_ itr(*this);
474  itr.B::index_ += offset;
475  return itr;
476  }
477 
478  //-----------------------------------------------------------------//
480  //-----------------------------------------------------------------//
481  friend iterator_ operator+(size_t offset, const iterator_ & itr) {
482  iterator_ itr2(itr);
483  itr2.B::index_ += offset;
484  return itr2;
485  }
486 
487  //-----------------------------------------------------------------//
489  //-----------------------------------------------------------------//
490  iterator_ operator-(size_t offset) const {
491  iterator_ itr(*this);
492  itr.B::index_ -= offset;
493  return itr;
494  }
495 
496  //-----------------------------------------------------------------//
498  //-----------------------------------------------------------------//
499  friend iterator_ operator-(size_t offset, const iterator_ & itr) {
500  iterator_ itr2(itr);
501  itr2.B::index_ = offset - itr.B::index_;
502  return itr2;
503  }
504 
505  //-----------------------------------------------------------------//
507  //-----------------------------------------------------------------//
508  iterator_ & operator+=(size_t offset) {
509  B::index_ += offset;
510  return *this;
511  }
512 
513  //-----------------------------------------------------------------//
515  //-----------------------------------------------------------------//
516  iterator_ & operator-=(size_t offset) {
517  B::index_ -= offset;
518  return *this;
519  }
520 
521  //-----------------------------------------------------------------//
523  //-----------------------------------------------------------------//
524  S operator*() {
525  return B::get_(B::index_);
526  }
527 
528  //-----------------------------------------------------------------//
530  //-----------------------------------------------------------------//
531  S * operator->() {
532  return &B::get_(B::index_);
533  }
534  };
535 
536  //-----------------------------------------------------------------//
539  //-----------------------------------------------------------------//
540  index_space(bool storage = STORAGE)
541  : v_(new id_storage_t), begin_(0), end_(0), owned_(true), sorted_(SORTED),
542  s_(storage ? new storage_t : nullptr) {
543  assert((STORAGE || !storage) && "invalid instantiation");
544  }
545 
546  //-----------------------------------------------------------------//
549  //-----------------------------------------------------------------//
550  template<class S,
551  bool STORAGE2,
552  bool OWNED2,
553  bool SORTED2,
554  class F2,
555  template<typename, typename...>
556  class ID_STORAGE_TYPE2,
557  template<typename, typename...>
558  class STORAGE_TYPE2>
560  STORAGE2,
561  OWNED2,
562  SORTED2,
563  F2,
564  ID_STORAGE_TYPE2,
565  STORAGE_TYPE2> & is,
566  size_t begin,
567  size_t end)
568  : v_(is.v_), begin_(begin), end_(end), owned_(false), sorted_(is.sorted_),
569  s_(reinterpret_cast<storage_t *>(is.s_)) {
570 
571  static_assert(
572  std::is_convertible<T, S>::value, "invalid index space construction");
573  static_assert(!STORAGE, "expected !STORAGE");
574  static_assert(!OWNED, "expected !OWNED");
575  }
576 
577  //-----------------------------------------------------------------//
579  //-----------------------------------------------------------------//
581  : v_(OWNED ? new id_storage_t(*is.v_) : is.v_), begin_(is.begin_),
582  end_(is.end_), owned_(OWNED), sorted_(is.sorted_), s_(is.s_) {
583  assert(s_ && "no storage");
584  static_assert(!STORAGE, "expected !STORAGE");
585  }
586 
587  //-----------------------------------------------------------------//
589  //-----------------------------------------------------------------//
591  : v_(std::move(is.v_)), begin_(std::move(is.begin_)),
592  end_(std::move(is.end_)), sorted_(std::move(is.sorted_)),
593  s_(std::move(is.s_)) {
594 
595  if(OWNED || is.owned_) {
596  is.v_ = nullptr;
597  owned_ = true;
598  }
599  else {
600  owned_ = false;
601  }
602 
603  if(STORAGE) {
604  is.s_ = nullptr;
605  }
606 
607  is.begin_ = 0;
608  is.end_ = 0;
609  }
610 
611  //-----------------------------------------------------------------//
613  //-----------------------------------------------------------------//
615  if(OWNED || owned_) {
616  delete v_;
617  }
618 
619  if(STORAGE) {
620  delete s_;
621  }
622  }
623 
624  //-----------------------------------------------------------------//
626  //-----------------------------------------------------------------//
628  return s_;
629  }
630 
631  //-----------------------------------------------------------------//
633  //-----------------------------------------------------------------//
634  const storage_t * storage() const {
635  return s_;
636  }
637 
638  //-----------------------------------------------------------------//
640  //-----------------------------------------------------------------//
641  void set_storage(storage_t * s) {
642  s_ = s;
643  }
644 
645  //-----------------------------------------------------------------//
647  //-----------------------------------------------------------------//
649  assert(!STORAGE && "invalid assignment");
650 
651  if(OWNED) {
652  delete v_;
653  v_ = new id_storage_t(*is.v_);
654  owned_ = true;
655  }
656  else {
657  v_ = is.v_;
658  owned_ = false;
659  }
660 
661  begin_ = is.begin_;
662  end_ = is.end_;
663  sorted_ = is.sorted_;
664  s_ = is.s_;
665 
666  return *this;
667  }
668 
669  //-----------------------------------------------------------------//
671  //-----------------------------------------------------------------//
673  v_ = std::move(is.v_);
674 
675  if(OWNED || is.owned_) {
676  is.v_ = nullptr;
677  owned_ = true;
678  }
679  else {
680  owned_ = false;
681  }
682 
683  begin_ = std::move(is.begin_);
684  end_ = std::move(is.end_);
685  sorted_ = std::move(is.sorted_);
686  s_ = std::move(is.s_);
687 
688  if(STORAGE) {
689  is.s_ = nullptr;
690  }
691 
692  is.begin_ = 0;
693  is.end_ = 0;
694 
695  return *this;
696  }
697 
698  //-----------------------------------------------------------------//
701  //-----------------------------------------------------------------//
702  template<class S,
703  bool STORAGE2 = STORAGE,
704  bool OWNED2 = OWNED,
705  bool SORTED2 = SORTED,
706  class F2 = F,
707  template<typename, typename...> class ID_STORAGE_TYPE2 = ID_STORAGE_TYPE,
708  template<typename, typename...> class STORAGE_TYPE2 = STORAGE_TYPE>
709  auto & cast() {
710  static_assert(std::is_convertible<S, T>::value, "invalid index space cast");
711 
712  auto res = reinterpret_cast<index_space<S,
713  STORAGE2,
714  OWNED2,
715  SORTED2,
716  F2,
717  ID_STORAGE_TYPE2,
718  STORAGE_TYPE2> *>(this);
719  assert(res != nullptr && "invalid cast");
720  return *res;
721  }
722 
723  //-----------------------------------------------------------------//
726  //-----------------------------------------------------------------//
727  template<class S,
728  bool STORAGE2 = STORAGE,
729  bool OWNED2 = OWNED,
730  bool SORTED2 = SORTED,
731  class F2 = F,
732  template<typename, typename...> class ID_STORAGE_TYPE2 = ID_STORAGE_TYPE,
733  template<typename, typename...> class STORAGE_TYPE2 = STORAGE_TYPE>
734  auto & cast() const {
735  static_assert(std::is_convertible<S, T>::value, "invalid index space cast");
736 
737  auto res = reinterpret_cast<index_space<S,
738  STORAGE2,
739  OWNED2,
740  SORTED2,
741  F2,
742  ID_STORAGE_TYPE2,
743  STORAGE_TYPE2> *>(this);
744  assert(res != nullptr && "invalid cast");
745  return *res;
746  }
747 
748  //-----------------------------------------------------------------//
750  //-----------------------------------------------------------------//
751  auto begin() {
752  return iterator_<T, F>(s_, *v_, begin_, end_);
753  }
754 
755  //-----------------------------------------------------------------//
757  //-----------------------------------------------------------------//
758  auto begin() const {
759  return iterator_<const T, F>(s_, *v_, begin_, end_);
760  }
761 
762  //-----------------------------------------------------------------//
764  //-----------------------------------------------------------------//
765  auto end() {
766  return iterator_<T, F>(s_, *v_, end_, end_);
767  }
768 
769  //-----------------------------------------------------------------//
771  //-----------------------------------------------------------------//
772  auto end() const {
773  return iterator_<const T, F>(s_, *v_, end_, end_);
774  }
775 
776  //-----------------------------------------------------------------//
778  //-----------------------------------------------------------------//
779  size_t begin_offset() const {
780  return begin_;
781  }
782 
783  //-----------------------------------------------------------------//
785  //-----------------------------------------------------------------//
786  size_t end_offset() const {
787  return end_;
788  }
789 
790  //-----------------------------------------------------------------//
792  //-----------------------------------------------------------------//
793  ref_t get_offset(size_t offset) {
794  return (*s_)[(*v_)[offset].index_space_index()];
795  }
796 
797  //-----------------------------------------------------------------//
799  //-----------------------------------------------------------------//
800  const ref_t get_offset(size_t offset) const {
801  return (*s_)[(*v_)[offset].index_space_index()];
802  }
803 
804  //-----------------------------------------------------------------//
806  //-----------------------------------------------------------------//
807  id_range_ ids() const {
808  return id_range_(*v_, begin_, end_);
809  }
810 
811  //-----------------------------------------------------------------//
813  //-----------------------------------------------------------------//
814  id_range_ ids(size_t begin, size_t end) const {
815  return id_range_(*v_, begin, end);
816  }
817 
818  //-----------------------------------------------------------------//
820  //-----------------------------------------------------------------//
821  id_range_ ids(const std::pair<size_t, size_t> & p) const {
822  return id_range_(*v_, p.first, p.second);
823  }
824 
825  //-----------------------------------------------------------------//
831  //-----------------------------------------------------------------//
832  template<class S = T>
833  auto slice(size_t begin, size_t end) const {
834  return index_space<S,
835  false,
836  false,
837  SORTED,
838  F,
839  ID_STORAGE_TYPE,
840  STORAGE_TYPE>(*this, begin, end);
841  }
842 
843  //-----------------------------------------------------------------//
850  //-----------------------------------------------------------------//
851  template<class S = T>
852  auto slice(const std::pair<size_t, size_t> & range) const {
853  return index_space<S,
854  false,
855  false,
856  SORTED,
857  F,
858  ID_STORAGE_TYPE,
859  STORAGE_TYPE>(*this, range.first, range.second);
860  }
861 
862  //-----------------------------------------------------------------//
868  //-----------------------------------------------------------------//
869  template<class S = T>
870  auto slice() const {
871  return index_space<S,
872  false,
873  false,
874  SORTED,
875  F,
876  ID_STORAGE_TYPE,
877  STORAGE_TYPE>(*this, begin_, end_);
878  }
879 
880  //-----------------------------------------------------------------//
882  //-----------------------------------------------------------------//
883  ref_t get_(size_t offset) {
884  return static_cast<cast_t>(
885  (*s_)[(*v_)[begin_ + offset].index_space_index()]);
886  }
887 
888  //-----------------------------------------------------------------//
890  //-----------------------------------------------------------------//
891  const ref_t get_(size_t offset) const {
892  return static_cast<cast_t>(
893  (*s_)[(*v_)[begin_ + offset].index_space_index()]);
894  }
895 
896  //-----------------------------------------------------------------//
898  //-----------------------------------------------------------------//
899  ref_t get_end_(size_t offset) {
900  return static_cast<cast_t>(
901  (*s_)[(*v_)[end_ - 1 - offset].index_space_index()]);
902  }
903 
904  //-----------------------------------------------------------------//
906  //-----------------------------------------------------------------//
907  const ref_t get_end_(size_t offset) const {
908  return static_cast<cast_t>(
909  (*s_)[(*v_)[end_ - 1 - offset].index_space_index()]);
910  }
911 
912  //-----------------------------------------------------------------//
914  //-----------------------------------------------------------------//
915  ref_t operator[](size_t offset) {
916  return get_(offset);
917  }
918 
919  //-----------------------------------------------------------------//
921  //-----------------------------------------------------------------//
922  const ref_t operator[](size_t i) const {
923  return get_(i);
924  }
925 
926  //-----------------------------------------------------------------//
929  //-----------------------------------------------------------------//
930  const id_t & operator()(size_t i) const {
931  return (*v_)[begin_ + i];
932  }
933 
934  //-----------------------------------------------------------------//
937  //-----------------------------------------------------------------//
938  id_t & operator()(size_t i) {
939  return (*v_)[begin_ + i];
940  }
941 
942  //-----------------------------------------------------------------//
944  //-----------------------------------------------------------------//
946  return get_(0);
947  }
948 
949  //-----------------------------------------------------------------//
951  //-----------------------------------------------------------------//
952  const ref_t front() const {
953  return get_(0);
954  }
955 
956  //-----------------------------------------------------------------//
958  //-----------------------------------------------------------------//
960  return get_end_(0);
961  }
962 
963  //-----------------------------------------------------------------//
965  //-----------------------------------------------------------------//
966  const ref_t back() const {
967  return get_end_(0);
968  }
969 
970  //-----------------------------------------------------------------//
972  //-----------------------------------------------------------------//
973  size_t size() const {
974  return end_ - begin_;
975  }
976 
977  //-----------------------------------------------------------------//
979  //-----------------------------------------------------------------//
980  bool empty() const {
981  return begin_ == end_;
982  }
983 
984  //-----------------------------------------------------------------//
986  //-----------------------------------------------------------------//
987  void clear() {
988  begin_ = 0;
989  end_ = 0;
990 
991  if(OWNED || owned_) {
992  v_->clear();
993  sorted_ = SORTED;
994  }
995 
996  if(STORAGE) {
997  s_->clear();
998  }
999  }
1000 
1001  //-----------------------------------------------------------------//
1004  //-----------------------------------------------------------------//
1005  template<bool STORAGE2,
1006  bool OWNED2,
1007  bool SORTED2,
1008  class F2,
1009  template<typename, typename...>
1010  class INDEX_STORAGE_TYPE2,
1011  template<typename, typename...>
1012  class STORAGE_TYPE2>
1013  void set_master(const index_space<T,
1014  STORAGE2,
1015  OWNED2,
1016  SORTED2,
1017  F2,
1018  INDEX_STORAGE_TYPE2,
1019  STORAGE_TYPE2> & master) {
1020  set_master(const_cast<index_space<T,
1021  STORAGE2,
1022  OWNED2,
1023  SORTED2,
1024  F2,
1025  INDEX_STORAGE_TYPE2,
1026  STORAGE_TYPE2> &>(master));
1027  }
1028 
1029  //-----------------------------------------------------------------//
1032  //-----------------------------------------------------------------//
1033  template<bool STORAGE2,
1034  bool OWNED2,
1035  bool SORTED2,
1036  class F2,
1037  template<typename, typename...>
1038  class INDEX_STORAGE_TYPE2,
1039  template<typename, typename...>
1040  class STORAGE_TYPE2>
1042  STORAGE2,
1043  OWNED2,
1044  SORTED2,
1045  F2,
1046  INDEX_STORAGE_TYPE2,
1047  STORAGE_TYPE2> & master) {
1048  s_ = reinterpret_cast<storage_t *>(master.s_);
1049  }
1050 
1051  //-----------------------------------------------------------------//
1054  //-----------------------------------------------------------------//
1055  std::vector<const T> to_vec() const {
1056  return to_vec_<const T>();
1057  }
1058 
1059  //-----------------------------------------------------------------//
1062  //-----------------------------------------------------------------//
1063  std::vector<T> to_vec() {
1064  return to_vec_<T>();
1065  }
1066 
1067  //-----------------------------------------------------------------//
1072  //-----------------------------------------------------------------//
1073  template<class S>
1074  std::vector<S> to_vec_() {
1075  std::vector<S> ret;
1076  size_t n = end_ - begin_;
1077  ret.reserve(n);
1078  for(size_t i = 0; i < n; ++i) {
1079  ret.push_back((*this)[i]);
1080  } // for
1081  return ret;
1082  }
1083 
1084  //-----------------------------------------------------------------//
1086  //-----------------------------------------------------------------//
1087  const id_storage_t & id_storage() const {
1088  return *v_;
1089  }
1090 
1091  //-----------------------------------------------------------------//
1093  //-----------------------------------------------------------------//
1095  return *v_;
1096  }
1097 
1098  //-----------------------------------------------------------------//
1100  //-----------------------------------------------------------------//
1102  if(owned_) {
1103  delete v_;
1104  }
1105 
1106  v_ = v;
1107  owned_ = false;
1108  }
1109 
1110  //-----------------------------------------------------------------//
1112  //-----------------------------------------------------------------//
1113  const id_t * id_array() const {
1114  return v_->data();
1115  }
1116 
1117  id_t * id_array() {
1118  return v_->data();
1119  }
1120 
1121  //-----------------------------------------------------------------//
1126  //-----------------------------------------------------------------//
1127  template<typename Predicate>
1128  auto filter(Predicate && f) const {
1130  is.set_master(*this);
1131 
1132  for(auto item : *this) {
1133  if(std::forward<Predicate>(f)(item)) {
1134  is.push_back(item);
1135  }
1136  }
1137 
1138  return is;
1139  }
1140 
1141  //-----------------------------------------------------------------//
1144  //-----------------------------------------------------------------//
1145  void apply(apply_function f) const {
1146  for(auto ent : *this) {
1147  f(ent);
1148  }
1149  }
1150 
1151  //-----------------------------------------------------------------//
1154  //-----------------------------------------------------------------//
1155  template<class S>
1156  auto map(map_function<S> f) const {
1158  is.set_master(*this);
1159 
1160  is.begin_push_(v_->size());
1161 
1162  for(auto item : *this) {
1163  is.batch_push_(f(*item));
1164  }
1165  return is;
1166  }
1167 
1168  //-----------------------------------------------------------------//
1173  //-----------------------------------------------------------------//
1174  template<typename S>
1176  T r = start;
1177 
1178  for(auto item : *this) {
1179  f(*item, r);
1180  }
1181 
1182  return r;
1183  }
1184 
1185  //-----------------------------------------------------------------//
1199  //-----------------------------------------------------------------//
1200  template<typename Predicate>
1201  auto bin(Predicate && f) const {
1202  return bin_as_map(std::forward<Predicate>(f));
1203  }
1204 
1205  //-----------------------------------------------------------------//
1220  //-----------------------------------------------------------------//
1221  template<typename Predicate>
1222  auto bin_as_map(Predicate && f) const {
1223 
1224  // If the list was sorted beforehand, the result will also be
1225  // sorted. Own the index_vector_t (i.e., create storage for it)
1226  using new_index_space_t = index_space<T, false, true, SORTED>;
1227 
1228  // get the predicate result type
1229  using result_t =
1230  std::decay_t<decltype(std::forward<Predicate>(f)(operator[](0)))>;
1231 
1232  // bin the data, and use a map to sort the keys
1233  std::map<result_t, new_index_space_t> bins;
1234  for(auto ent : *this)
1235  bins[std::forward<Predicate>(f)(ent)].push_back(ent);
1236 
1237  // now go and set the master
1238  for(auto & entry : bins)
1239  entry.second.set_master(*this);
1240 
1241  return bins;
1242  }
1243 
1244  //-----------------------------------------------------------------//
1258  //-----------------------------------------------------------------//
1259  template<typename Predicate>
1260  auto bin_as_vector(Predicate && f) const {
1261 
1262  // get the bins as a map
1263  auto bins_map = bin_as_map(std::forward<Predicate>(f));
1264 
1265  // If the list was sorted beforehand, the result will also be
1266  // sorted. Own the index_vector_t (i.e., create storage for it)
1267  using new_index_space_t =
1268  typename std::decay_t<decltype(bins_map)>::mapped_type;
1269 
1270  // now extract the results and store them in a vector.
1271  // should be faster for access.
1272  std::vector<new_index_space_t> bins_vec;
1273  bins_vec.reserve(bins_map.size());
1274 
1275  for(auto && entry : bins_map)
1276  bins_vec.emplace_back(std::move(entry.second));
1277 
1278  return bins_vec;
1279  }
1280 
1281  //-----------------------------------------------------------------//
1285  //-----------------------------------------------------------------//
1286  void prepare_() {
1287  if(!OWNED && !owned_) {
1288  v_ = new id_storage_t(*v_);
1289  owned_ = true;
1290  }
1291 
1292  if(!SORTED && !sorted_) {
1293  auto vc = const_cast<id_storage_t *>(v_);
1294  std::sort(vc->begin(), vc->end());
1295  sorted_ = true;
1296  }
1297  }
1298 
1299  //-----------------------------------------------------------------//
1303  //-----------------------------------------------------------------//
1305  prepare_();
1306 
1307  id_storage_t ret;
1308 
1309  if(r.sorted_) {
1310  ret.resize(std::min(v_->size(), r.v_->size()));
1311 
1312  auto itr = std::set_intersection(
1313  v_->begin(), v_->end(), r.v_->begin(), r.v_->end(), ret.begin());
1314 
1315  ret.resize(itr - ret.begin());
1316  }
1317  else {
1318  id_storage_t v2(*r.v_);
1319  std::sort(v2.begin(), v2.end());
1320 
1321  ret.resize(std::min(v_->size(), v2.size()));
1322 
1323  auto itr = std::set_intersection(
1324  v_->begin(), v_->end(), v2.begin(), v2.end(), ret.begin());
1325 
1326  ret.resize(itr - ret.begin());
1327  }
1328 
1329  *v_ = std::move(ret);
1330 
1331  begin_ = 0;
1332  end_ = v_->size();
1333 
1334  return *this;
1335  }
1336 
1337  //-----------------------------------------------------------------//
1339  //-----------------------------------------------------------------//
1340  index_space operator&(const index_space & r) const {
1341  index_space ret(*this);
1342  ret &= r;
1343  return ret;
1344  }
1345 
1346  //-----------------------------------------------------------------//
1350  //-----------------------------------------------------------------//
1352  prepare_();
1353 
1354  id_storage_t ret;
1355 
1356  if(r.sorted_) {
1357  ret.resize(v_->size() + r.v_->size());
1358 
1359  auto itr = std::set_union(
1360  v_->begin(), v_->end(), r.v_->begin(), r.v_->end(), ret.begin());
1361 
1362  ret.resize(itr - ret.begin());
1363  }
1364  else {
1365  id_storage_t v2(*r.v_);
1366 
1367  std::sort(v2.begin(), v2.end());
1368 
1369  ret.resize(v_->size() + v2.size());
1370 
1371  auto itr = std::set_union(
1372  v_->begin(), v_->end(), v2.begin(), v2.end(), ret.begin());
1373 
1374  ret.resize(itr - ret.begin());
1375  }
1376 
1377  *v_ = std::move(ret);
1378 
1379  begin_ = 0;
1380  end_ = v_->size();
1381 
1382  return *this;
1383  }
1384 
1385  //-----------------------------------------------------------------//
1387  //-----------------------------------------------------------------//
1388  index_space operator|(const index_space & r) const {
1389  index_space ret(*this);
1390  ret |= r;
1391  return ret;
1392  }
1393 
1394  //-----------------------------------------------------------------//
1398  //-----------------------------------------------------------------//
1400  prepare_();
1401 
1402  id_storage_t ret(v_->size());
1403 
1404  if(r.sorted_) {
1405  auto itr = std::set_difference(
1406  v_->begin(), v_->end(), r.v_->begin(), r.v_->end(), ret.begin());
1407 
1408  ret.resize(itr - ret.begin());
1409  }
1410  else {
1411  id_storage_t v2(*r.v_);
1412 
1413  std::sort(v2.begin(), v2.end());
1414 
1415  auto itr = std::set_difference(
1416  v_->begin(), v_->end(), v2.begin(), v2.end(), ret.begin());
1417 
1418  ret.resize(itr - ret.begin());
1419  }
1420 
1421  *v_ = std::move(ret);
1422 
1423  begin_ = 0;
1424  end_ = v_->size();
1425 
1426  return *this;
1427  }
1428 
1429  //-----------------------------------------------------------------//
1431  //-----------------------------------------------------------------//
1432  index_space operator-(const index_space & r) const {
1433  index_space ret(*this);
1434  ret -= r;
1435  return ret;
1436  }
1437 
1438  //-----------------------------------------------------------------//
1442  //-----------------------------------------------------------------//
1443  void push_back(const T & item) {
1444  if(!OWNED && !owned_) {
1445  v_ = new id_storage_t(*v_);
1446  owned_ = true;
1447  }
1448 
1449  if(STORAGE) {
1450  s_->push_back(item);
1451  }
1452 
1453  if(SORTED || sorted_) {
1454  auto id = id_(item);
1455  auto itr = std::upper_bound(v_->begin(), v_->end(), id);
1456  v_->insert(itr, id);
1457  }
1458  else {
1459  v_->push_back(id_(item));
1460  }
1461 
1462  ++end_;
1463  }
1464 
1465  //-----------------------------------------------------------------//
1469  //-----------------------------------------------------------------//
1471  if(!OWNED && !owned_) {
1472  v_ = new id_storage_t(*v_);
1473  owned_ = true;
1474  }
1475 
1476  if(SORTED || sorted_) {
1477  auto itr = std::upper_bound(v_->begin(), v_->end(), index);
1478  v_->insert(itr, index);
1479  }
1480  else {
1481  v_->push_back(index);
1482  }
1483 
1484  ++end_;
1485  }
1486 
1487  //-----------------------------------------------------------------//
1489  //-----------------------------------------------------------------//
1490  void pushed() {
1491  ++end_;
1492  }
1493 
1494  //-----------------------------------------------------------------//
1499  //-----------------------------------------------------------------//
1500  void append(const index_space & is) {
1501  if(!OWNED && !owned_) {
1502  v_ = new id_storage_t(*v_);
1503  owned_ = true;
1504  }
1505 
1506  if(STORAGE) {
1507  s_->insert(s_->begin(), is.s_->begin(), is.s_->end());
1508  }
1509 
1510  size_t n = is.size();
1511 
1512  if(SORTED || sorted_) {
1513  v_->reserve(n);
1514 
1515  for(auto ent : is) {
1516  id_t id = id_(ent);
1517  auto itr = std::upper_bound(v_->begin(), v_->end(), id);
1518  v_->insert(itr, id);
1519  }
1520  }
1521  else {
1522  v_->insert(v_->begin(), is.v_->begin(), is.v_->end());
1523  }
1524 
1525  end_ += n;
1526  }
1527 
1528  //-----------------------------------------------------------------//
1530  //-----------------------------------------------------------------//
1532  push_back(item);
1533  return *this;
1534  }
1535 
1536  //-----------------------------------------------------------------//
1538  //-----------------------------------------------------------------//
1539  void append_(const std::vector<T> & ents, const std::vector<id_t> & ids) {
1540  static_assert(STORAGE, "expected STORAGE");
1541  static_assert(OWNED, "expected OWNED");
1542 
1543  assert(ents.size() == ids.size());
1544 
1545  s_->insert(s_->begin(), ents.begin(), ents.end());
1546 
1547  size_t n = ents.size();
1548 
1549  if(SORTED || sorted_) {
1550  v_->reserve(n);
1551 
1552  for(id_t id : ids) {
1553  auto itr = std::upper_bound(v_->begin(), v_->end(), id);
1554  v_->insert(itr, id);
1555  }
1556  }
1557  else {
1558  v_->insert(v_->begin(), ids.begin(), ids.end());
1559  }
1560 
1561  end_ += n;
1562  }
1563 
1564  //-----------------------------------------------------------------//
1566  //-----------------------------------------------------------------//
1567  id_t id_(const item_t & item) {
1568  return item.index_space_id();
1569  }
1570 
1571  //-----------------------------------------------------------------//
1573  //-----------------------------------------------------------------//
1574  id_t id_(const item_t * item) {
1575  return item->index_space_id();
1576  }
1577 
1578  //-----------------------------------------------------------------//
1580  //-----------------------------------------------------------------//
1581  void set_begin(size_t begin) {
1582  begin_ = begin;
1583  }
1584 
1585  //-----------------------------------------------------------------//
1587  //-----------------------------------------------------------------//
1588  void set_end(size_t end) {
1589  end_ = end;
1590  }
1591 
1592 private:
1593  template<class,
1594  bool,
1595  bool,
1596  bool,
1597  class,
1598  template<class, class...>
1599  class,
1600  template<class, class...>
1601  class>
1602  friend class index_space;
1603 
1604  friend class connectivity_t;
1605 
1606  id_storage_t * v_;
1607  size_t begin_;
1608  size_t end_;
1609  bool owned_;
1610  bool sorted_;
1611  storage_t * s_;
1612 
1613  //-----------------------------------------------------------------//
1615  //-----------------------------------------------------------------//
1616  size_t begin_push_() {
1617  static_assert(OWNED, "expected OWNED");
1618  return v_->size();
1619  }
1620 
1621  //-----------------------------------------------------------------//
1623  //-----------------------------------------------------------------//
1624  void reserve_(size_t n) {
1625  static_assert(OWNED, "expected OWNED");
1626  return v_->reserve(n);
1627  }
1628 
1629  //-----------------------------------------------------------------//
1631  //-----------------------------------------------------------------//
1632  void begin_push_(size_t n) {
1633  static_assert(OWNED, "expected OWNED");
1634  assert(begin_ == 0);
1635  size_t m = v_->size();
1636  v_->reserve(m + n);
1637  end_ += n;
1638  }
1639 
1640  //-----------------------------------------------------------------//
1642  //-----------------------------------------------------------------//
1643  void batch_push_(id_t index) {
1644  static_assert(OWNED, "expected OWNED");
1645  v_->push_back(index);
1646  }
1647 
1648  //-----------------------------------------------------------------//
1650  //-----------------------------------------------------------------//
1651  void push_(id_t index) {
1652  static_assert(OWNED, "expected OWNED");
1653  v_->push_back(index);
1654  ++end_;
1655  }
1656 
1657  //-----------------------------------------------------------------//
1659  //-----------------------------------------------------------------//
1660  void end_push_(size_t n) {
1661  static_assert(OWNED, "expected OWNED");
1662  assert(begin_ == 0);
1663  end_ += v_->size() - n;
1664  }
1665 
1666  //-----------------------------------------------------------------//
1668  //-----------------------------------------------------------------//
1669  void resize_(size_t n) {
1670  static_assert(OWNED, "expected OWNED");
1671  assert(begin_ == 0);
1672  v_->resize(n);
1673  end_ = v_->size();
1674  }
1675 
1676  //-----------------------------------------------------------------//
1678  //-----------------------------------------------------------------//
1679  void fill_(id_t index) {
1680  static_assert(OWNED, "expected OWNED");
1681  std::fill(v_->begin(), v_->end(), index);
1682  }
1683 
1684  //-----------------------------------------------------------------//
1686  //-----------------------------------------------------------------//
1687  id_storage_t & id_storage_() {
1688  return *v_;
1689  }
1690 
1691  //-----------------------------------------------------------------//
1693  //-----------------------------------------------------------------//
1694  typename id_storage_t::iterator index_begin_() {
1695  return v_->begin();
1696  }
1697 
1698  //-----------------------------------------------------------------//
1700  //-----------------------------------------------------------------//
1701  typename id_storage_t::iterator index_end_() {
1702  return v_->end();
1703  }
1704 };
1705 
1706 //----------------------------------------------------------------------------//
1710 //----------------------------------------------------------------------------//
1712 {
1713 public:
1714  //-----------------------------------------------------------------//
1716  //-----------------------------------------------------------------//
1717  simple_id(size_t id) : id_(id) {}
1718 
1719  //-----------------------------------------------------------------//
1721  //-----------------------------------------------------------------//
1722  operator size_t() const {
1723  return id_;
1724  }
1725 
1726  //-----------------------------------------------------------------//
1728  //-----------------------------------------------------------------//
1729  bool operator<(const simple_id & eid) const {
1730  return id_ < eid.id_;
1731  }
1732 
1733  //-----------------------------------------------------------------//
1735  //-----------------------------------------------------------------//
1736  size_t index_space_index() const {
1737  return id_;
1738  }
1739 
1740 private:
1741  size_t id_;
1742 };
1743 
1744 //----------------------------------------------------------------------------//
1746 //----------------------------------------------------------------------------//
1747 template<typename T>
1749 {
1750 public:
1751  using id_t = simple_id;
1752 
1753  //-----------------------------------------------------------------//
1755  //-----------------------------------------------------------------//
1756  simple_entry(id_t id, const T & entry) : id_(id), entry_(entry) {}
1757 
1758  //-----------------------------------------------------------------//
1760  //-----------------------------------------------------------------//
1761  operator T() const {
1762  return entry_;
1763  }
1764 
1765  //-----------------------------------------------------------------//
1767  //-----------------------------------------------------------------//
1768  auto entry_id() const {
1769  return entry_;
1770  }
1771 
1772  //-----------------------------------------------------------------//
1774  //-----------------------------------------------------------------//
1776  return id_;
1777  }
1778 
1779 private:
1780  id_t id_;
1781  T entry_;
1782 };
1783 
1784 } // namespace topo
1785 } // namespace flecsi
bool operator<(const iterator_base_ &itr) const
Less than operator.
Definition: index_space.hh:200
iterator_ & operator+=(size_t offset)
Plus assignment offset operator.
Definition: index_space.hh:508
iterator_ & operator-=(size_t offset)
Minus assignment offset operator.
Definition: index_space.hh:516
auto bin_as_vector(Predicate &&f) const
Bin entities using a predicate function.
Definition: index_space.hh:1260
iterator_ operator-(size_t offset) const
Minus offset operator.
Definition: index_space.hh:490
Definition: index_space.hh:262
id_storage_t::const_iterator begin() const
Get begin iterator.
Definition: index_space.hh:140
index_space(bool storage=STORAGE)
Definition: index_space.hh:540
iterator_ operator+(size_t offset) const
Plus offset operator.
Definition: index_space.hh:472
std::function< void(entity_t * &, S &)> reduce_function
Reduce function signature.
Definition: index_space.hh:115
const ref_t back() const
Get the entity at the back of the index space.
Definition: index_space.hh:966
helper classes for resolving types
Definition: index_space.hh:36
auto slice(size_t begin, size_t end) const
Definition: index_space.hh:833
S * operator->()
Arrow operator.
Definition: index_space.hh:389
auto filter(Predicate &&f) const
Definition: index_space.hh:1128
~index_space()
Destructor.
Definition: index_space.hh:614
void append(const index_space &is)
Definition: index_space.hh:1500
typename std::remove_pointer< entity_t * >::type item_t
item, e.g. entity type
Definition: index_space.hh:98
bool operator>=(const iterator_base_ &itr) const
Greater than equal operator.
Definition: index_space.hh:221
const ref_t get_end_(size_t offset) const
Helper method. Get item at offset from end.
Definition: index_space.hh:907
std::function< S(entity_t * &)> map_function
map function signature
Definition: index_space.hh:111
index_space & operator=(index_space &&is)
Move assignment operator.
Definition: index_space.hh:672
index_space operator &(const index_space &r) const
Return r-value of set intersection of passed index spaces.
Definition: index_space.hh:1340
ref_t get_(size_t offset)
Helper method. Get item at offset.
Definition: index_space.hh:883
void prepare_()
Definition: index_space.hh:1286
iterator_ operator+(size_t offset) const
Plus offset operator.
Definition: index_space.hh:322
a convenience class which associates a simple ID with type T
Definition: index_space.hh:1748
index_space(const index_space< S, STORAGE2, OWNED2, SORTED2, F2, ID_STORAGE_TYPE2, STORAGE_TYPE2 > &is, size_t begin, size_t end)
Definition: index_space.hh:559
std::decay_t< ref_t > cast_t
reference casting type
Definition: index_space.hh:104
typename std::remove_pointer< entity_t * >::type::id_t id_t
ID type.
Definition: index_space.hh:89
const ref_t operator[](size_t i) const
Get item at offset.
Definition: index_space.hh:922
void apply(apply_function f) const
Definition: index_space.hh:1145
index_space operator-(const index_space &r) const
Return r-value of set difference of passed index spaces.
Definition: index_space.hh:1432
iterator_(const storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from item storage and index range.
Definition: index_space.hh:279
simple_id(size_t id)
Constructor.
Definition: index_space.hh:1717
void append_(const std::vector< T > &ents, const std::vector< id_t > &ids)
Append helper method. Do not call directly.
Definition: index_space.hh:1539
const ref_t get_(size_t offset) const
Helper method. Get item at offset.
Definition: index_space.hh:891
Definition: array_buffer.hh:71
auto bin(Predicate &&f) const
Bin entities using a predicate function.
Definition: index_space.hh:1201
std::function< void(entity_t * &)> apply_function
apply function signature
Definition: index_space.hh:107
id_range_ ids(size_t begin, size_t end) const
Get all IDs in range.
Definition: index_space.hh:814
ID_STORAGE_TYPE< id_t > id_storage_t
ID storage type.
Definition: index_space.hh:92
bool operator==(const iterator_base_ &itr) const
Equality operator.
Definition: index_space.hh:186
index_space(index_space &&is)
Move constructor.
Definition: index_space.hh:590
iterator_ & operator++()
Increment operator.
Definition: index_space.hh:288
bool operator!=(const iterator_base_ &itr) const
Inequality operator.
Definition: index_space.hh:193
ref_t operator[](size_t offset)
Get item at offset.
Definition: index_space.hh:915
id_storage_t::const_iterator end() const
Get end iterator.
Definition: index_space.hh:147
const id_t * id_array() const
Return the index space IDs as an array.
Definition: index_space.hh:1113
bool operator<=(const iterator_base_ &itr) const
Less than equal operator.
Definition: index_space.hh:207
auto begin() const
Return begin iterator.
Definition: index_space.hh:758
auto operator[](size_t index) const
Get item at index.
Definition: index_space.hh:242
id_t id_(const item_t &item)
Helper method to get ID.
Definition: index_space.hh:1567
ref_t front()
Get the entity at the front of the index space.
Definition: index_space.hh:945
index_space & operator-=(const index_space &r)
Definition: index_space.hh:1399
auto end()
Return end iterator.
Definition: index_space.hh:765
int start(const std::function< int()> &action)
Definition: execution.hh:69
id_t & operator()(size_t i)
Definition: index_space.hh:938
iterator_ & operator+=(size_t offset)
Plus assignment offset operator.
Definition: index_space.hh:358
S & operator*()
Dereference operator.
Definition: index_space.hh:374
bool operator<(const simple_id &eid) const
Comparison operator.
Definition: index_space.hh:1729
std::string type()
Definition: demangle.hh:44
auto slice() const
Definition: index_space.hh:870
iterator_base_(storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from items and range.
Definition: index_space.hh:167
auto end() const
Return end iterator.
Definition: index_space.hh:772
index_space & operator &=(const index_space &r)
Definition: index_space.hh:1304
id_storage_t & id_storage()
Return the index storage object.
Definition: index_space.hh:1094
size_t operator-(const iterator_base_ &itr) const
Difference.
Definition: index_space.hh:228
iterator_ & operator-=(size_t offset)
Minus assignment offset operator.
Definition: index_space.hh:366
STORAGE_TYPE< T > storage_t
Storage type.
Definition: index_space.hh:95
auto & cast() const
Definition: index_space.hh:734
auto & cast()
Definition: index_space.hh:709
S reduce(T start, reduce_function< T > f) const
Definition: index_space.hh:1175
Definition: index_space.hh:85
void push_back(id_t index)
Definition: index_space.hh:1470
auto map(map_function< S > f) const
Definition: index_space.hh:1156
iterator_base_(const storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from items and range.
Definition: index_space.hh:176
const ref_t front() const
Get the entity at the front of the index space.
Definition: index_space.hh:952
index_space & operator=(const index_space &is)
Assignment operator. Alias an existing index space unless OWNED.
Definition: index_space.hh:648
simple_entry(id_t id, const T &entry)
Constructor to associate an id with an entry.
Definition: index_space.hh:1756
storage_t * storage()
Return the storage object.
Definition: index_space.hh:627
auto get_(size_t index)
Helper method. Get item at index.
Definition: index_space.hh:235
Definition: index_space.hh:1711
void set_master(const index_space< T, STORAGE2, OWNED2, SORTED2, F2, INDEX_STORAGE_TYPE2, STORAGE_TYPE2 > &master)
Definition: index_space.hh:1013
std::vector< const T > to_vec() const
Definition: index_space.hh:1055
Definition: index.hh:64
ref_t get_offset(size_t offset)
Get offset.
Definition: index_space.hh:793
void set_storage(storage_t *s)
Set the storage object.
Definition: index_space.hh:641
id_range_ ids(const std::pair< size_t, size_t > &p) const
Get all IDs in range.
Definition: index_space.hh:821
index_space & operator<<(T item)
Shortcut for push_back()
Definition: index_space.hh:1531
friend iterator_ operator-(size_t offset, const iterator_ &itr)
Minus offset operator.
Definition: index_space.hh:499
typename index_space_ref_type< entity_t * >::type ref_t
Reference type.
Definition: index_space.hh:101
bool operator>(const iterator_base_ &itr) const
Greater than operator.
Definition: index_space.hh:214
iterator_ & operator++()
Increment operator.
Definition: index_space.hh:438
iterator_ operator++(int)
Post-increment operator.
Definition: index_space.hh:304
index_space & operator|=(const index_space &r)
Definition: index_space.hh:1351
auto begin()
Return begin iterator.
Definition: index_space.hh:751
Definition: index_space.hh:122
id_range_(const id_storage_t &items, size_t begin, size_t end)
Initialize range from items with beginning and end.
Definition: index_space.hh:134
friend iterator_ operator+(size_t offset, const iterator_ &itr)
Plus offset operator.
Definition: index_space.hh:481
S * operator->()
Arrow operator.
Definition: index_space.hh:531
auto bin_as_map(Predicate &&f) const
Bin entities using a predicate function.
Definition: index_space.hh:1222
domain_entity is a simple wrapper to mesh entity that associates with its a domain id ...
Definition: array_buffer.hh:24
id_range_ ids() const
Get all IDs in range.
Definition: index_space.hh:807
iterator_ operator--(int)
Post-decrement operator.
Definition: index_space.hh:313
iterator_ operator++(int)
Post-increment operator.
Definition: index_space.hh:454
ref_t get_end_(size_t offset)
Helper method. Get item at offset from end.
Definition: index_space.hh:899
const ref_t get_offset(size_t offset) const
Get offset.
Definition: index_space.hh:800
void set_end(size_t end)
Set the end index of contained IDs.
Definition: index_space.hh:1588
iterator_ operator--(int)
Post-decrement operator.
Definition: index_space.hh:463
iterator_(storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from items and range.
Definition: index_space.hh:420
void clear()
Clear all indices and entities.
Definition: index_space.hh:987
const id_storage_t & id_storage() const
Return the index storage object.
Definition: index_space.hh:1087
iterator_(const storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from items and range.
Definition: index_space.hh:429
size_t index_space_index() const
Define the index space ID.
Definition: index_space.hh:1736
const storage_t * storage() const
Return the storage object.
Definition: index_space.hh:634
void push_back(const T &item)
Definition: index_space.hh:1443
auto entry_id() const
Get the entry ID.
Definition: index_space.hh:1768
Iterator base, const be parameterized with &#39;T&#39; or &#39;const T&#39;.
Definition: index_space.hh:161
iterator_ & operator--()
Decrement operator.
Definition: index_space.hh:446
id_t index_space_id() const
Get the index space ID.
Definition: index_space.hh:1775
size_t end_offset() const
Return end offset.
Definition: index_space.hh:786
friend iterator_ operator-(size_t offset, const iterator_ &itr)
Minus offset operator.
Definition: index_space.hh:349
index_space operator|(const index_space &r) const
Return r-value of set union of passed index spaces.
Definition: index_space.hh:1388
void set_begin(size_t begin)
Set to begin index of contained IDs.
Definition: index_space.hh:1581
std::vector< S > to_vec_()
Definition: index_space.hh:1074
void set_master(index_space< T, STORAGE2, OWNED2, SORTED2, F2, INDEX_STORAGE_TYPE2, STORAGE_TYPE2 > &master)
Definition: index_space.hh:1041
S operator*()
Dereference operator.
Definition: index_space.hh:524
std::vector< T > to_vec()
Definition: index_space.hh:1063
void pushed()
Called if an index was added to storage internally.
Definition: index_space.hh:1490
connectivity_t provides basic connectivity information in a compressed storage format.
Definition: connectivity.hh:41
void set_id_storage(id_storage_t *v)
Set the index storage object.
Definition: index_space.hh:1101
ref_t back()
Get the entity at the back of the index space.
Definition: index_space.hh:959
const id_t & operator()(size_t i) const
Definition: index_space.hh:930
bool empty() const
Return if the index space is empty, i.e. has no indices.
Definition: index_space.hh:980
size_t begin_offset() const
Return begin offset.
Definition: index_space.hh:779
friend iterator_ operator+(size_t offset, const iterator_ &itr)
Plus offset operator.
Definition: index_space.hh:331
size_t size() const
Get the size of the index space.
Definition: index_space.hh:973
auto slice(const std::pair< size_t, size_t > &range) const
Definition: index_space.hh:852
id_t id_(const item_t *item)
Helper method to get ID.
Definition: index_space.hh:1574
iterator_ operator-(size_t offset) const
Minus offset operator.
Definition: index_space.hh:340
iterator_(storage_t *s, const id_storage_t &items, size_t index, size_t end)
Initialize iterator from item storage and index range.
Definition: index_space.hh:270
iterator_ & operator--()
Decrement operator.
Definition: index_space.hh:296
id_range_(const id_storage_t &items)
Initialize range from items.
Definition: index_space.hh:128
Definition: control.hh:31
index_space(const index_space &is)
Constructor to alias an existing index space unless OWNED.
Definition: index_space.hh:580