96#ifndef __ADS_Iterators
97 #define __ADS_Iterators
108#include <type_traits>
112#if defined( __cpp_lib_format_ranges )
129template<
class C ,
class V , C * C::* Next , V C::* Value ,
133 using Cell = std::conditional_t< Const , const C , C >;
140 using reference = std::conditional_t< Const , const V & , V & >;
142 using pointer = std::conditional_t< Const , const V * , V * >;
152 requires( Const && ! K )
154 : f_c( o.
cell() ) { }
179 [[nodiscard]] Cell *
cell(
void )
const {
return( f_c ); }
182 Cell * f_c =
nullptr;
192template<
class C ,
class V ,
int C::* Next , V C::* Value ,
197 std::conditional_t< Const , const std::vector< C > , std::vector< C > >;
204 using reference = std::conditional_t< Const , const V & , V & >;
206 using pointer = std::conditional_t< Const , const V * , V * >;
216 requires( Const && ! K )
228 f_c = ( *f_A )[ f_c ].*Next;
241 return( ( f_c == o.f_c ) && ( ( f_c < 0 ) || ( f_A == o.f_A ) ) );
245 [[nodiscard]] Cells *
cells(
void )
const {
return( f_A ); }
248 [[nodiscard]]
int index(
void )
const {
return( f_c ); }
251 Cells * f_A =
nullptr;
263template<
class T ,
bool Const = true >
266 using Item = std::conditional_t< Const , const T , T >;
282 : f_A( A ) , f_head(
head ) , f_cap(
capacity ) , f_i( i ) { }
286 requires( Const && ! K )
300 return( f_A[ ( f_head + std::size_t( f_i + k ) ) % f_cap ] );
352 return( a.f_i - b.f_i );
357 return( f_i == o.f_i );
362 return( f_i <=> o.f_i );
366 [[nodiscard]] Item *
base(
void )
const {
return( f_A ); }
369 [[nodiscard]] std::size_t
head(
void )
const {
return( f_head ); }
372 [[nodiscard]] std::size_t
capacity(
void )
const {
return( f_cap ); }
378 Item * f_A =
nullptr;
379 std::size_t f_head = 0 , f_cap = 1;
390template<
class C ,
class T ,
bool Const = true >
393 using Owner = std::conditional_t< Const , const C , C >;
394 using Item = std::conditional_t< Const , const T , T >;
412 requires( Const && ! K )
424 return( ( *f_c )[ f_i + std::size_t( k ) ] );
455 f_i += std::size_t( k );
461 f_i -= std::size_t( k );
484 return( f_i <=> o.f_i );
488 [[nodiscard]] Owner *
owner(
void )
const {
return( f_c ); }
491 [[nodiscard]] std::size_t
rank(
void )
const {
return( f_i ); }
494 Owner * f_c =
nullptr;
505template< std::random_access_iterator I >
512 using value_type = std::remove_cvref_t< decltype( **std::declval< I >() ) >;
582 return( a.f_i - b.f_i );
592 [[nodiscard]] I
base(
void )
const {
return( f_i ); }
608template<
class A ,
class B ,
class VA ,
class VB >
609class PairProxy :
public std::pair< A , B >
613 using value_type = std::pair< VA , VB >;
615 using std::pair< A , B >::pair;
619 [[nodiscard]]
operator value_type(
void )
const {
620 return( value_type( VA( this->first ) , VB( this->second ) ) );
628template<
class A ,
class B ,
class VA ,
class VB >
629inline constexpr bool plainPair =
630#if defined( __cpp_lib_ranges_zip )
631 std::is_same_v< VA , std::remove_cvref_t< A > > &&
632 std::is_same_v< VB , std::remove_cvref_t< B > >;
646template<
class A ,
class B ,
class VA = std::remove_cvref_t< A > ,
647 class VB = std::remove_cvref_t< B > >
649 std::conditional_t< detail::plainPair< A , B , VA , VB > ,
651 detail::PairProxy< A , B , VA , VB > >;
662 using type = std::remove_cvref_t< R >;
665template<
class A ,
class B ,
class VA ,
class VB >
666struct ItemValue< PairProxy< A , B , VA , VB > >
668 using type = std::pair< VA , VB >;
671#if defined( __cpp_lib_ranges_zip )
672template<
class A ,
class B >
673struct ItemValue< std::pair< A , B > >
676 using type = std::pair< std::remove_cvref_t< A > , std::remove_cvref_t< B > >;
689template<
class O ,
class P >
694 using reference =
decltype( P::read( std::declval< const O & >() , 0 ) );
696 using value_type =
typename detail::ItemValue< reference >::type;
703 std::conditional_t< std::is_reference_v< reference > ,
704 std::bidirectional_iterator_tag ,
705 std::input_iterator_tag >;
712 f_i( i ) { forward(); }
749 while( ! P::occupied( *f_o , f_i ) );
771 [[nodiscard]] std::size_t
place(
void )
const {
return( f_i ); }
774 void forward(
void ) {
775 const std::size_t m = P::size( *f_o );
776 while( ( f_i < m ) && ! P::occupied( *f_o , f_i ) )
780 const O * f_o =
nullptr;
791template< std::forward_iterator I >
797 const std::remove_cvref_t< decltype( ( *std::declval< I >() ).first ) > &;
803 std::bidirectional_iterator_tag ,
804 std::forward_iterator_tag >;
834 requires std::bidirectional_iterator< I >
842 requires std::bidirectional_iterator< I >
865template<
class O ,
class P >
869 std::remove_pointer_t< decltype( P::root( std::declval< const O & >() ) ) >;
873 using reference =
decltype( P::read( std::declval< N * >() ) );
875 using value_type =
typename detail::ItemValue< reference >::type;
882 std::conditional_t< std::is_reference_v< reference > ,
883 std::bidirectional_iterator_tag ,
884 std::input_iterator_tag >;
892 descend( P::root( *f_o ) ,
true );
944 descend( P::root( *f_o ) ,
false );
966 return( f_path.empty() ? o.f_path.empty()
967 : ( ! o.f_path.empty() &&
968 ( f_path.back() == o.f_path.back() ) ) );
972 static N * child( N * n ,
bool right ) {
973 return( right ? P::right( n ) : P::left( n ) );
977 void descend( N * n ,
bool first ) {
978 for( ; n ; n = child( n , ! first ) )
979 f_path.push_back( n );
983 void step(
bool forward ) {
984 if( N * c = child( f_path.back() , forward ) ) {
985 descend( c , forward );
990 from = f_path.back();
992 }
while( ! f_path.empty() && ( child( f_path.back() , forward ) == from ) );
995 const O * f_o =
nullptr;
996 std::vector< N * > f_path;
1008template<
class O ,
class H ,
class P >
1025 : f_o( o ) , f_n( n ) , f_root( root ) { }
1032 f_n = P::next( f_o , f_n , f_root );
1047 const O * f_o =
nullptr;
1064template<
class A ,
class B ,
class VA ,
class VB ,
1065 template<
class >
class TQ ,
1066 template<
class >
class UQ >
1067struct std::basic_common_reference<
ADS::detail::PairProxy< A , B , VA , VB > ,
1068 std::pair< VA , VB > , TQ , UQ >
1070 using type = ADS::detail::PairProxy< A , B , VA , VB >;
1074template<
class A ,
class B ,
class VA ,
class VB ,
1075 template<
class >
class TQ ,
1076 template<
class >
class UQ >
1077struct std::basic_common_reference<
1078 std::pair< VA , VB > , ADS::detail::PairProxy< A , B , VA , VB > , TQ , UQ >
1080 using type = ADS::detail::PairProxy< A , B , VA , VB >;
1084template<
class A ,
class B ,
class VA ,
class VB >
1085struct std::tuple_size<
ADS::detail::PairProxy< A , B , VA , VB > >
1086 : std::integral_constant< std::size_t , 2 >
1090template< std::
size_t I ,
class A ,
class B ,
class VA ,
class VB >
1091struct std::tuple_element< I ,
ADS::detail::PairProxy< A , B , VA , VB > >
1092 : std::tuple_element< I , std::pair< A , B > >
1095#if defined( __cpp_lib_format_ranges )
1097template<
class A ,
class B ,
class VA ,
class VB ,
class C >
1098struct std::formatter<
ADS::detail::PairProxy< A , B , VA , VB > , C >
1099 : std::formatter< std::pair< A , B > , C >
bool operator==(const CircularIterator &o) const
equal on the same index from the head
Definition Iterators.h:356
CircularIterator(Item *A, std::size_t head, std::size_t capacity, difference_type i)
on the item from the head of the vector
Definition Iterators.h:280
friend CircularIterator operator-(CircularIterator a, difference_type k)
Definition Iterators.h:347
friend CircularIterator operator+(CircularIterator a, difference_type k)
Definition Iterators.h:341
friend difference_type operator-(const CircularIterator &a, const CircularIterator &b)
Definition Iterators.h:350
T value_type
the items
Definition Iterators.h:271
CircularIterator & operator+=(difference_type k)
items on
Definition Iterators.h:330
std::size_t head(void) const
the place of the first item
Definition Iterators.h:369
difference_type index(void) const
the index of the item from the head
Definition Iterators.h:375
CircularIterator operator++(int)
to the next item, returning the iterator before the step
Definition Iterators.h:316
reference operator[](difference_type k) const
the item places on, at the place
Definition Iterators.h:299
std::size_t capacity(void) const
the capacity of the vector
Definition Iterators.h:372
Item * base(void) const
the vector
Definition Iterators.h:366
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:272
std::strong_ordering operator<=>(const CircularIterator &o) const
the order of the indices from the head
Definition Iterators.h:361
CircularIterator & operator++(void)
to the next item
Definition Iterators.h:304
Item & reference
a reference to an item
Definition Iterators.h:273
CircularIterator & operator-=(difference_type k)
items back
Definition Iterators.h:336
friend CircularIterator operator+(difference_type k, CircularIterator a)
Definition Iterators.h:344
CircularIterator(const CircularIterator< T, K > &o)
the constant iterator from the mutable one
Definition Iterators.h:287
std::random_access_iterator_tag iterator_category
random access
Definition Iterators.h:270
pointer operator->(void) const
the address of the item
Definition Iterators.h:295
Item * pointer
a pointer to an item
Definition Iterators.h:274
CircularIterator & operator--(void)
to the previous item
Definition Iterators.h:310
CircularIterator operator--(int)
to the previous item, returning the iterator before the step
Definition Iterators.h:323
CircularIterator(void)=default
an iterator on no vector
reference operator*(void) const
the item
Definition Iterators.h:292
IndexIterator operator++(int)
to the next cell, returning the iterator before the step
Definition Iterators.h:233
Cells * cells(void) const
Definition Iterators.h:245
IndexIterator & operator++(void)
to the next cell, by the index Next
Definition Iterators.h:227
bool operator==(const IndexIterator &o) const
equal on the same cell; any two ends are equal
Definition Iterators.h:240
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:202
reference operator*(void) const
the item
Definition Iterators.h:221
std::conditional_t< Const, const V &, V & > reference
a reference to an item, constant if Const
Definition Iterators.h:204
std::forward_iterator_tag iterator_category
forward
Definition Iterators.h:200
IndexIterator(Cells *A, int c)
on the item of the cell , the end if
Definition Iterators.h:212
int index(void) const
Definition Iterators.h:248
IndexIterator(const IndexIterator< C, V, Next, Value, K > &o)
the constant iterator from the mutable one
Definition Iterators.h:217
IndexIterator(void)=default
the end
pointer operator->(void) const
the address of the item
Definition Iterators.h:224
std::conditional_t< Const, const V *, V * > pointer
a pointer to an item, constant if Const
Definition Iterators.h:206
V value_type
the items
Definition Iterators.h:201
friend IndirectIterator operator+(difference_type k, IndirectIterator a)
Definition Iterators.h:574
friend IndirectIterator operator+(IndirectIterator a, difference_type k)
Definition Iterators.h:571
IndirectIterator & operator-=(difference_type k)
pointers back
Definition Iterators.h:566
pointer operator->(void) const
the address of the item pointed to
Definition Iterators.h:528
IndirectIterator operator++(int)
to the next pointer, returning the iterator before the step
Definition Iterators.h:546
IndirectIterator & operator++(void)
to the next pointer
Definition Iterators.h:534
IndirectIterator & operator--(void)
to the previous pointer
Definition Iterators.h:540
std::random_access_iterator_tag iterator_category
random access
Definition Iterators.h:510
const value_type * pointer
a constant pointer to an item
Definition Iterators.h:516
reference operator*(void) const
the item pointed to
Definition Iterators.h:525
IndirectIterator operator--(int)
to the previous pointer, returning the iterator before the step
Definition Iterators.h:553
IndirectIterator(void)=default
an iterator on nothing
IndirectIterator & operator+=(difference_type k)
pointers on
Definition Iterators.h:560
const value_type & reference
a constant reference to an item
Definition Iterators.h:515
I base(void) const
the iterator on the pointers
Definition Iterators.h:592
std::iter_difference_t< I > difference_type
the distances, those of I
Definition Iterators.h:514
friend IndirectIterator operator-(IndirectIterator a, difference_type k)
Definition Iterators.h:577
friend difference_type operator-(const IndirectIterator &a, const IndirectIterator &b)
Definition Iterators.h:580
IndirectIterator(I i)
on the item pointed to by *i
Definition Iterators.h:522
bool operator==(const IndirectIterator &o) const =default
equal on the same pointer
reference operator[](difference_type k) const
the item pointed to places on
Definition Iterators.h:531
std::remove_cvref_t< decltype(**std::declval< I >()) > value_type
the items, those pointed to
Definition Iterators.h:512
auto operator<=>(const IndirectIterator &o) const =default
the order of the iterators on the pointers
bool operator==(const KeyIterator &o) const =default
equal when the iterators on the pairs are
const std::remove_cvref_t< decltype((*std::declval< I >()).first) > & reference
a constant reference to a key
Definition Iterators.h:796
KeyIterator & operator++(void)
to the next key
Definition Iterators.h:820
std::conditional_t< std::bidirectional_iterator< I >, std::bidirectional_iterator_tag, std::forward_iterator_tag > iterator_concept
bidirectional if I is, forward otherwise
Definition Iterators.h:802
std::remove_cvref_t< reference > value_type
the keys
Definition Iterators.h:798
KeyIterator operator++(int)
to the next key, returning the iterator before the step
Definition Iterators.h:826
std::iter_difference_t< I > difference_type
the distances, those of I
Definition Iterators.h:800
KeyIterator & operator--(void)
to the previous key
Definition Iterators.h:833
KeyIterator(void)=default
an iterator on nothing
reference operator*(void) const
the key
Definition Iterators.h:814
iterator_concept iterator_category
as iterator_concept
Definition Iterators.h:805
KeyIterator(I i)
on the key of what i reads
Definition Iterators.h:811
const value_type * operator->(void) const
the address of the key
Definition Iterators.h:817
KeyIterator operator--(int)
to the previous key, returning the iterator before the step
Definition Iterators.h:841
Cell * cell(void) const
Definition Iterators.h:179
V value_type
the items
Definition Iterators.h:137
std::conditional_t< Const, const V &, V & > reference
a reference to an item, constant if Const
Definition Iterators.h:140
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:138
LinkedIterator(Cell *c)
on the item of the cell , the end if is nil
Definition Iterators.h:148
LinkedIterator(void)=default
the end
std::conditional_t< Const, const V *, V * > pointer
a pointer to an item, constant if Const
Definition Iterators.h:142
LinkedIterator(const LinkedIterator< C, V, Next, Value, K > &o)
the constant iterator from the mutable one
Definition Iterators.h:153
std::forward_iterator_tag iterator_category
forward
Definition Iterators.h:136
LinkedIterator & operator++(void)
to the next cell, by the link Next
Definition Iterators.h:163
LinkedIterator operator++(int)
to the next cell, returning the iterator before the step
Definition Iterators.h:169
pointer operator->(void) const
the address of the item
Definition Iterators.h:160
reference operator*(void) const
the item
Definition Iterators.h:157
bool operator==(const LinkedIterator &o) const =default
equal on the same cell
PathIterator & operator--(void)
to the previous node in symmetric order, from the end to the last node
Definition Iterators.h:942
std::conditional_t< std::is_reference_v< reference >, std::bidirectional_iterator_tag, std::input_iterator_tag > iterator_category
bidirectional for the older algorithms if P::read() gives a reference, input otherwise
Definition Iterators.h:881
PathIterator operator++(int)
to the next node, returning the iterator before the step
Definition Iterators.h:951
decltype(P::read(std::declval< N * >())) reference
what P::read() gives
Definition Iterators.h:873
PathIterator & operator++(void)
to the next node in symmetric order, amortized over a whole visit and at most
Definition Iterators.h:923
PathIterator operator--(int)
to the previous node, returning the iterator before the step
Definition Iterators.h:958
PathIterator(const O *o, bool first)
on the first node of the tree of o if first, at the end otherwise
Definition Iterators.h:890
std::bidirectional_iterator_tag iterator_concept
bidirectional for the concepts of C++20
Definition Iterators.h:878
PathIterator(void)=default
the end of no tree
bool operator==(const PathIterator &o) const
equal on the same node, or both at the end
Definition Iterators.h:965
typename detail::ItemValue< reference >::type value_type
the items, the pair of the copies for a PairRef
Definition Iterators.h:875
reference operator*(void) const
the item of the current node, read by P::read()
Definition Iterators.h:896
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:876
friend RankIterator operator+(RankIterator a, difference_type k)
Definition Iterators.h:465
RankIterator operator--(int)
to the previous item, returning the iterator before the step
Definition Iterators.h:447
RankIterator(void)=default
an iterator on no container
std::strong_ordering operator<=>(const RankIterator &o) const
the order of the ranks
Definition Iterators.h:483
RankIterator(Owner *c, std::size_t i)
on the item of rank of c
Definition Iterators.h:408
RankIterator operator++(int)
to the next item, returning the iterator before the step
Definition Iterators.h:440
Item & reference
a reference to an item
Definition Iterators.h:401
reference operator[](difference_type k) const
the item ranks on
Definition Iterators.h:423
reference operator*(void) const
the item
Definition Iterators.h:417
bool operator==(const RankIterator &o) const
equal on the same rank
Definition Iterators.h:480
T value_type
the items
Definition Iterators.h:399
Item * pointer
a pointer to an item
Definition Iterators.h:402
Owner * owner(void) const
Definition Iterators.h:488
RankIterator(const RankIterator< C, T, K > &o)
the constant iterator from the mutable one
Definition Iterators.h:413
friend RankIterator operator+(difference_type k, RankIterator a)
Definition Iterators.h:468
pointer operator->(void) const
the address of the item
Definition Iterators.h:420
RankIterator & operator++(void)
to the next item
Definition Iterators.h:428
std::random_access_iterator_tag iterator_category
random access
Definition Iterators.h:398
RankIterator & operator-=(difference_type k)
items back
Definition Iterators.h:460
friend RankIterator operator-(RankIterator a, difference_type k)
Definition Iterators.h:471
std::size_t rank(void) const
Definition Iterators.h:491
friend difference_type operator-(const RankIterator &a, const RankIterator &b)
Definition Iterators.h:474
RankIterator & operator+=(difference_type k)
items on
Definition Iterators.h:454
RankIterator & operator--(void)
to the previous item
Definition Iterators.h:434
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:400
std::conditional_t< std::is_reference_v< reference >, std::bidirectional_iterator_tag, std::input_iterator_tag > iterator_category
Definition Iterators.h:702
std::bidirectional_iterator_tag iterator_concept
Definition Iterators.h:699
decltype(Places::read(std::declval< const BucketCuckooTable & >(), 0)) reference
Definition Iterators.h:694
std::ptrdiff_t difference_type
Definition Iterators.h:697
std::size_t place(void) const
the place
Definition Iterators.h:771
SlotIterator operator--(int)
to the previous occupied place, returning the iterator before the step
Definition Iterators.h:761
SlotIterator operator++(int)
to the next occupied place, returning the iterator before the step
Definition Iterators.h:754
SlotIterator & operator--(void)
to the previous occupied place
Definition Iterators.h:746
typename detail::ItemValue< reference >::type value_type
Definition Iterators.h:696
SlotIterator & operator++(void)
to the next occupied place, or to the end
Definition Iterators.h:729
SlotIterator(const O *o, std::size_t i)
on the first occupied place from , or at the end
Definition Iterators.h:711
SlotIterator(void)=default
an iterator on no table
reference operator*(void) const
the item of the place, read by P::read()
Definition Iterators.h:715
bool operator==(const SlotIterator &o) const
equal on the same place
Definition Iterators.h:768
WalkIterator operator++(int)
to the next node, returning the iterator before the step
Definition Iterators.h:1037
WalkIterator & operator++(void)
to the next node of the walk, P::next( o , n , root )
Definition Iterators.h:1031
H reference
a node, by value
Definition Iterators.h:1013
std::input_iterator_tag iterator_category
input for the older algorithms, since *it is a value
Definition Iterators.h:1018
WalkIterator(void)=default
the end
WalkIterator(const O *o, H n, H root)
on the node n of the walk below root of the owner o
Definition Iterators.h:1024
bool operator==(const WalkIterator &o) const
equal on the same node
Definition Iterators.h:1044
std::ptrdiff_t difference_type
the distances
Definition Iterators.h:1014
H value_type
the nodes
Definition Iterators.h:1012
std::forward_iterator_tag iterator_concept
forward for the concepts of C++20
Definition Iterators.h:1016
reference operator*(void) const
the node
Definition Iterators.h:1028
std::conditional_t< detail::plainPair< A, B, VA, VB >, std::pair< A, B >, detail::PairProxy< A, B, VA, VB > > PairRef
the pair that an iterator reads by value, in general two references into the container,...
Definition Iterators.h:648
GrB_Type type(void)
the type of GraphBLAS of the numbers T: GrB_BOOL, the integers of 8 to 64 bits with or without sign,...
Definition GraphBLAS.h:128