20 #ifndef GALOIS_TWO_LEVEL_ITER_H
21 #define GALOIS_TWO_LEVEL_ITER_H
27 #include <type_traits>
32 #include "galois/config.h"
37 template <
typename Iter>
38 void safe_decrement(Iter& it,
const Iter& beg,
39 const Iter& GALOIS_USED_ONLY_IN_DEBUG(end),
40 std::forward_iterator_tag) {
57 template <
typename Iter>
58 void safe_decrement(Iter& it,
const Iter& GALOIS_USED_ONLY_IN_DEBUG(beg),
59 const Iter&, std::bidirectional_iterator_tag) {
64 template <
typename Iter>
65 void safe_decrement(Iter& it,
const Iter& beg,
const Iter& end) {
66 safe_decrement(it, beg, end,
67 typename std::iterator_traits<Iter>::iterator_category());
72 template <
typename Outer,
typename Inner,
typename InnerBegFn,
129 innerEndFn(innerEndFn) {}
133 template <
typename Outer,
typename Inner,
typename InnerBegFn,
136 :
public std::iterator_traits<Inner>,
140 typedef std::iterator_traits<Inner>
Traits;
185 :
Base(beg_outer, end_outer, outer_pos, innerBegFn, innerEndFn) {
223 template <
typename Outer,
typename Inner,
typename InnerBegFn,
270 :
FwdBase(beg_outer, end_outer, outer_pos, innerBegFn, innerEndFn) {}
285 template <
typename Outer,
typename Inner,
typename InnerBegFn,
293 typedef typename BiDirBase::Traits::difference_type
Diff_ty;
406 :
BiDirBase(beg_outer, end_outer, outer_pos, innerBegFn, innerEndFn) {}
441 return *((*this) + d);
452 return (left < right) || (left == right);
457 return !(left <= right);
462 return !(left < right);
468 template <
typename Outer,
typename Inner,
typename InnerBegFn,
469 typename InnerEndFn,
typename Cat>
470 struct ByCategory {};
472 template <
typename Outer,
typename Inner,
typename InnerBegFn,
474 struct ByCategory<Outer, Inner, InnerBegFn, InnerEndFn,
475 std::forward_iterator_tag> {
476 typedef TwoLevelFwdIter<Outer, Inner, InnerBegFn, InnerEndFn> type;
479 template <
typename Outer,
typename Inner,
typename InnerBegFn,
481 struct ByCategory<Outer, Inner, InnerBegFn, InnerEndFn,
482 std::bidirectional_iterator_tag> {
483 typedef TwoLevelBiDirIter<Outer, Inner, InnerBegFn, InnerEndFn> type;
486 template <
typename Outer,
typename Inner,
typename InnerBegFn,
488 struct ByCategory<Outer, Inner, InnerBegFn, InnerEndFn,
489 std::random_access_iterator_tag> {
490 typedef TwoLevelRandIter<Outer, Inner, InnerBegFn, InnerEndFn> type;
524 template <
typename Outer,
typename Inner,
typename InnerBegFn,
529 typedef typename std::iterator_traits<Inner>::iterator_category CatInner;
532 typedef typename internal::ByCategory<Outer, Inner, InnerBegFn, InnerEndFn,
537 template <
typename Outer,
typename InnerBegFn,
typename InnerEndFn>
539 InnerBegFn, InnerEndFn>::type
541 InnerEndFn innerEndFn) {
543 const bool V = std::is_same<
typename InnerBegFn::result_type,
544 typename InnerEndFn::result_type>::value;
548 typedef typename InnerBegFn::result_type Inner;
550 InnerEndFn>::type Ret_ty;
552 return Ret_ty(beg, end, beg, innerBegFn, innerEndFn);
556 template <
typename Outer,
typename InnerBegFn,
typename InnerEndFn>
557 typename ChooseTwoLevelIterator<Outer,
typename InnerBegFn::result_type,
558 InnerBegFn, InnerEndFn>::type
560 InnerEndFn innerEndFn) {
564 typedef typename InnerBegFn::result_type Inner;
566 InnerEndFn>::type Ret_ty;
568 return Ret_ty(beg, end, end, innerBegFn, innerEndFn);
572 template <
typename C>
573 struct GetBegin :
public std::unary_function<C&, typename C::iterator> {
574 inline typename C::iterator
operator()(C& c)
const {
return c.begin(); }
577 template <
typename C>
578 struct GetEnd :
public std::unary_function<C&, typename C::iterator> {
579 inline typename C::iterator
operator()(C& c)
const {
return c.end(); }
583 template <
typename C>
585 :
public std::unary_function<const C&, typename C::const_iterator> {
586 inline typename C::const_iterator
operator()(
const C& c)
const {
591 template <
typename C>
593 :
public std::unary_function<const C&, typename C::const_iterator> {
594 inline typename C::const_iterator
operator()(
const C& c)
const {
599 template <
typename C>
601 :
public std::unary_function<C&, typename C::reverse_iterator> {
602 inline typename C::reverse_iterator
operator()(C& c)
const {
607 template <
typename C>
608 struct GetRend :
public std::unary_function<C&, typename C::reverse_iterator> {
609 inline typename C::reverse_iterator
operator()(C& c)
const {
615 template <
typename C>
617 :
public std::unary_function<const C&, typename C::const_reverse_iterator> {
618 inline typename C::const_reverse_iterator
operator()(
const C& c)
const {
623 template <
typename C>
625 :
public std::unary_function<const C&, typename C::const_reverse_iterator> {
626 inline typename C::const_reverse_iterator
operator()(
const C& c)
const {
631 enum StlIterKind { NORMAL, _CONST, REVERSE, _CONST_REVERSE };
633 template <
typename C,
typename I>
635 static const bool value =
false;
638 template <
typename C>
639 struct IsConstIter<C, typename C::const_iterator> {
640 static const bool value =
true;
643 template <
typename C,
typename I>
645 static const bool value =
false;
648 template <
typename C>
649 struct IsRvrsIter<C, typename C::reverse_iterator> {
650 static const bool value =
true;
653 template <
typename C,
typename I>
654 struct IsRvrsConstIter {
655 static const bool value =
false;
658 template <
typename C>
659 struct IsRvrsConstIter<C, typename C::const_reverse_iterator> {
660 static const bool value =
true;
663 template <
typename C,
typename I>
664 struct GetStlIterKind {
665 static const bool isRvrs =
666 IsRvrsIter<C, I>::value || IsRvrsConstIter<C, I>::value;
667 static const bool isConst =
668 IsConstIter<C, I>::value || IsRvrsConstIter<C, I>::value;
670 static const StlIterKind value = isRvrs ? (isConst ? _CONST_REVERSE : REVERSE)
671 : (isConst ? _CONST : NORMAL);
674 template <
typename C,
typename I, enum StlIterKind>
675 struct ChooseStlIter {
679 template <
typename C,
typename I>
680 struct ChooseStlIter<C, I, NORMAL> {
682 typedef typename C::iterator Inner;
683 typedef GetBegin<C> InnerBegFn;
684 typedef GetEnd<C> InnerEndFn;
687 template <
typename C,
typename I>
688 struct ChooseStlIter<C, I, _CONST> {
690 typedef typename C::const_iterator Inner;
691 typedef GetCbegin<C> InnerBegFn;
692 typedef GetCend<C> InnerEndFn;
695 template <
typename C,
typename I>
696 struct ChooseStlIter<C, I, REVERSE> {
698 typedef typename C::reverse_iterator Inner;
699 typedef GetRbegin<C> InnerBegFn;
700 typedef GetRend<C> InnerEndFn;
703 template <
typename C,
typename I>
704 struct ChooseStlIter<C, I, _CONST_REVERSE> {
706 typedef typename C::const_reverse_iterator Inner;
707 typedef GetCRbegin<C> InnerBegFn;
708 typedef GetCRend<C> InnerEndFn;
711 template <
typename Outer,
typename Inner>
712 struct ChooseStlTwoLevelIterImpl {
715 static const internal::StlIterKind KIND =
716 internal::GetStlIterKind<C, Inner>::value;
717 typedef internal::ChooseStlIter<C, Inner, KIND> CStl;
718 typedef typename CStl::InnerBegFn InnerBegFn;
719 typedef typename CStl::InnerEndFn InnerEndFn;
720 typedef typename ChooseTwoLevelIterator<Outer, Inner, InnerBegFn,
721 InnerEndFn>::type type;
723 static type make(Outer beg, Outer end, Outer outer_pos) {
724 return type(beg, end, outer_pos, InnerBegFn(), InnerEndFn());
728 template <
typename Outer>
729 struct StlInnerIsIterator
730 :
public ChooseStlTwoLevelIterImpl<
731 Outer, typename std::iterator_traits<Outer>::value_type::iterator> {};
733 template <
typename Outer>
734 struct StlInnerIsConstIterator
735 :
public ChooseStlTwoLevelIterImpl<
737 typename std::iterator_traits<Outer>::value_type::const_iterator> {};
739 template <
typename Outer>
740 struct StlInnerIsRvrsIterator
741 :
public ChooseStlTwoLevelIterImpl<
743 typename std::iterator_traits<Outer>::value_type::reverse_iterator> {
746 template <
typename Outer>
747 struct StlInnerIsConstRvrsIterator
748 :
public ChooseStlTwoLevelIterImpl<
749 Outer, typename std::iterator_traits<
750 Outer>::value_type::const_reverse_iterator> {};
755 template <
typename Outer,
typename Inner>
757 typedef typename internal::ChooseStlTwoLevelIterImpl<Outer, Inner>::type
type;
760 template <
typename Outer>
761 typename internal::StlInnerIsIterator<Outer>::type
763 return internal::StlInnerIsIterator<Outer>::make(beg, end, beg);
766 template <
typename Outer>
767 typename internal::StlInnerIsIterator<Outer>::type
769 return internal::StlInnerIsIterator<Outer>::make(beg, end, end);
772 template <
typename Outer>
773 typename internal::StlInnerIsConstIterator<Outer>::type
775 return internal::StlInnerIsConstIterator<Outer>::make(beg, end, beg);
778 template <
typename Outer>
779 typename internal::StlInnerIsConstIterator<Outer>::type
781 return internal::StlInnerIsConstIterator<Outer>::make(beg, end, end);
784 template <
typename Outer>
785 typename internal::StlInnerIsRvrsIterator<Outer>::type
787 return internal::StlInnerIsRvrsIterator<Outer>::make(beg, end, beg);
790 template <
typename Outer>
791 typename internal::StlInnerIsRvrsIterator<Outer>::type
793 return internal::StlInnerIsRvrsIterator<Outer>::make(beg, end, end);
796 template <
typename Outer>
797 typename internal::StlInnerIsConstRvrsIterator<Outer>::type
799 return internal::StlInnerIsConstRvrsIterator<Outer>::make(beg, end, beg);
802 template <
typename Outer>
803 typename internal::StlInnerIsConstRvrsIterator<Outer>::type
805 return internal::StlInnerIsConstRvrsIterator<Outer>::make(beg, end, end);
810 #endif // GALOIS_TWO_LEVEL_ITER_H
TwoLevelIterBase()
Definition: TwoLevelIterator.h:121
BiDirBase::Traits::reference operator[](Diff_ty d) const
Definition: TwoLevelIterator.h:440
Two-Level forward iterator.
Definition: TwoLevelIterator.h:135
Outer m_outer
Definition: TwoLevelIterator.h:80
friend bool operator<(const TwoLevelRandIter &left, const TwoLevelRandIter &right)
Definition: TwoLevelIterator.h:444
internal::StlInnerIsConstIterator< Outer >::type stl_two_level_cend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:780
Traits::reference operator*() const
Definition: TwoLevelIterator.h:194
void step_forward()
Definition: TwoLevelIterator.h:160
void seekValidBegin()
Definition: TwoLevelIterator.h:154
friend bool operator!=(const TwoLevelFwdIter &left, const TwoLevelFwdIter &right)
Definition: TwoLevelIterator.h:216
bool outerAtEnd() const
Definition: TwoLevelIterator.h:91
TwoLevelIterBase(Outer beg_outer, Outer end_outer, Outer outer_pos, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Definition: TwoLevelIterator.h:125
TwoLevelIterBase< Outer, Inner, InnerBegFn, InnerEndFn > Base
Definition: TwoLevelIterator.h:141
bool innerAtBegin() const
Definition: TwoLevelIterator.h:111
TwoLevelFwdIter()
Definition: TwoLevelIterator.h:181
const Inner & getInnerEnd() const
Definition: TwoLevelIterator.h:97
bool innerAtEnd() const
Definition: TwoLevelIterator.h:116
TwoLevelBiDirIter< Outer, Inner, InnerBegFn, InnerEndFn > BiDirBase
Definition: TwoLevelIterator.h:291
internal::StlInnerIsRvrsIterator< Outer >::type stl_two_level_rbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:786
Type function to select appropriate two-level iterator.
Definition: TwoLevelIterator.h:526
friend bool operator==(const TwoLevelFwdIter &left, const TwoLevelFwdIter &right)
Definition: TwoLevelIterator.h:211
TwoLevelRandIter()
Definition: TwoLevelIterator.h:402
friend TwoLevelRandIter operator+(Diff_ty d, const TwoLevelRandIter &it)
Definition: TwoLevelIterator.h:424
TwoLevelRandIter(Outer beg_outer, Outer end_outer, Outer outer_pos, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Definition: TwoLevelIterator.h:404
Inner m_inner
Definition: TwoLevelIterator.h:84
ChooseTwoLevelIterator< Outer, typename InnerBegFn::result_type, InnerBegFn, InnerEndFn >::type make_two_level_end(Outer beg, Outer end, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Creates two level iterator.
Definition: TwoLevelIterator.h:559
TwoLevelFwdIter< Outer, Inner, InnerBegFn, InnerEndFn > FwdBase
Definition: TwoLevelIterator.h:229
friend TwoLevelRandIter operator-(const TwoLevelRandIter &it, Diff_ty d)
Definition: TwoLevelIterator.h:428
bool outerEmpty() const
Definition: TwoLevelIterator.h:93
TwoLevelRandIter & operator-=(Diff_ty d)
Definition: TwoLevelIterator.h:413
void jump_backward(const Diff_ty d)
Definition: TwoLevelIterator.h:326
void nextOuter()
Definition: TwoLevelIterator.h:143
Inner m_beg_inner
Definition: TwoLevelIterator.h:82
internal::StlInnerIsConstRvrsIterator< Outer >::type stl_two_level_crbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:798
Common functionality of TwoLevelIterators.
Definition: TwoLevelIterator.h:74
Outer m_beg_outer
Definition: TwoLevelIterator.h:78
TwoLevelBiDirIter operator--(int)
Definition: TwoLevelIterator.h:277
ChooseTwoLevelIterator< Outer, typename InnerBegFn::result_type, InnerBegFn, InnerEndFn >::type make_two_level_begin(Outer beg, Outer end, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Creates two level iterator.
Definition: TwoLevelIterator.h:540
Two-Level random access iterator.
Definition: TwoLevelIterator.h:287
Outer m_end_outer
Definition: TwoLevelIterator.h:79
std::iterator_traits< Inner > Traits
Definition: TwoLevelIterator.h:140
Traits::pointer operator->() const
Definition: TwoLevelIterator.h:196
BiDirBase::Traits::difference_type Diff_ty
Definition: TwoLevelIterator.h:293
Inner m_end_inner
Definition: TwoLevelIterator.h:83
friend bool operator<=(const TwoLevelRandIter &left, const TwoLevelRandIter &right)
Definition: TwoLevelIterator.h:450
friend TwoLevelRandIter operator+(const TwoLevelRandIter &it, Diff_ty d)
Definition: TwoLevelIterator.h:418
TwoLevelFwdIter operator++(int)
Definition: TwoLevelIterator.h:205
Diff_ty compute_dist(const TwoLevelRandIter &that) const
Definition: TwoLevelIterator.h:360
bool outerAtBegin() const
Definition: TwoLevelIterator.h:89
TwoLevelFwdIter(Outer beg_outer, Outer end_outer, Outer outer_pos, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Definition: TwoLevelIterator.h:183
TwoLevelBiDirIter(Outer beg_outer, Outer end_outer, Outer outer_pos, InnerBegFn innerBegFn, InnerEndFn innerEndFn)
Definition: TwoLevelIterator.h:268
void setInnerAtBegin(void)
Definition: TwoLevelIterator.h:99
TwoLevelRandIter & operator+=(Diff_ty d)
Definition: TwoLevelIterator.h:408
TwoLevelFwdIter & operator++()
Definition: TwoLevelIterator.h:200
void operator()(void)
Definition: Executor_ParaMeter.h:417
internal::StlInnerIsConstIterator< Outer >::type stl_two_level_cbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:774
Two-Level bidirectional iterator.
Definition: TwoLevelIterator.h:225
internal::StlInnerIsConstRvrsIterator< Outer >::type stl_two_level_crend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:804
InnerBegFn innerBegFn
Definition: TwoLevelIterator.h:86
internal::ChooseStlTwoLevelIterImpl< Outer, Inner >::type type
Definition: TwoLevelIterator.h:757
internal::ByCategory< Outer, Inner, InnerBegFn, InnerEndFn, CatInner >::type type
Definition: TwoLevelIterator.h:533
TwoLevelBiDirIter()
Definition: TwoLevelIterator.h:266
TwoLevelBiDirIter & operator--()
Definition: TwoLevelIterator.h:272
bool is_equal(const TwoLevelFwdIter &that) const
Definition: TwoLevelIterator.h:169
InnerEndFn innerEndFn
Definition: TwoLevelIterator.h:87
internal::StlInnerIsIterator< Outer >::type stl_two_level_begin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:762
internal::StlInnerIsIterator< Outer >::type stl_two_level_end(Outer beg, Outer end)
Definition: TwoLevelIterator.h:768
friend Diff_ty operator-(const TwoLevelRandIter &left, const TwoLevelRandIter &right)
Definition: TwoLevelIterator.h:434
void jump_forward(const Diff_ty d)
Definition: TwoLevelIterator.h:295
Type function to select appropriate two-level iterator.
Definition: TwoLevelIterator.h:756
T value_type
Definition: Executor_ParaMeter.h:111
const Inner & getInnerBegin() const
Definition: TwoLevelIterator.h:95
friend bool operator>(const TwoLevelRandIter &left, const TwoLevelRandIter &right)
Definition: TwoLevelIterator.h:455
void setInnerAtEnd(void)
Definition: TwoLevelIterator.h:105
void prevOuter()
Definition: TwoLevelIterator.h:232
void step_backward()
Definition: TwoLevelIterator.h:243
internal::StlInnerIsRvrsIterator< Outer >::type stl_two_level_rend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:792
friend bool operator>=(const TwoLevelRandIter &left, const TwoLevelRandIter &right)
Definition: TwoLevelIterator.h:460