@@ -59,31 +59,81 @@ static void test_iterate_lambda(const BitMap& map,
5959 ASSERT_EQ (positions_index, positions_size);
6060}
6161
62+ static void test_reverse_iterate_lambda (const BitMap& map,
63+ const idx_t * positions,
64+ size_t positions_size) {
65+ SCOPED_TRACE (" reverse iterate with lambda" );
66+ size_t positions_index = positions_size;
67+ auto f = [&](idx_t i) {
68+ test_iterate_step (map, i, positions, --positions_index, positions_size);
69+ };
70+ ASSERT_TRUE (map.reverse_iterate (f));
71+ ASSERT_EQ (positions_index, 0u );
72+ }
73+
74+
75+ struct TestBitMapIterationData {
76+ const BitMap& _map;
77+ const idx_t * _positions;
78+ size_t _positions_index;
79+ size_t _positions_size;
80+
81+ TestBitMapIterationData (const BitMap& map,
82+ const idx_t * positions,
83+ size_t positions_index,
84+ size_t positions_size)
85+ : _map(map),
86+ _positions (positions),
87+ _positions_index(positions_index),
88+ _positions_size(positions_size)
89+ {}
90+
91+ void test (idx_t index) const {
92+ test_iterate_step (_map, index, _positions, _positions_index, _positions_size);
93+ }
94+ };
95+
6296// Test closure returning bool. Also tests lambda returning bool.
6397static void test_iterate_closure (const BitMap& map,
6498 const idx_t * positions,
6599 size_t positions_size) {
66100 SCOPED_TRACE (" iterate with BitMapClosure" );
67101 struct Closure : public BitMapClosure {
68- const BitMap& _map;
69- const idx_t * _positions;
70- size_t _positions_index;
71- size_t _positions_size;
102+ TestBitMapIterationData _data;
72103
73104 Closure (const BitMap& map, const idx_t * positions, size_t positions_size)
74- : _map(map),
75- _positions (positions),
76- _positions_index(0 ),
77- _positions_size(positions_size)
105+ : _data(map, positions, 0 , positions_size)
78106 {}
79107
80108 bool do_bit (idx_t i) override {
81- test_iterate_step (_map, i, _positions, _positions_index++, _positions_size);
109+ _data.test (i);
110+ _data._positions_index += 1 ;
82111 return true ;
83112 }
84113 } closure{map, positions, positions_size};
85114 ASSERT_TRUE (map.iterate(&closure));
86- ASSERT_EQ (closure._positions_index, positions_size);
115+ ASSERT_EQ (closure._data ._positions_index , positions_size);
116+ }
117+
118+ static void test_reverse_iterate_closure (const BitMap& map,
119+ const idx_t * positions,
120+ size_t positions_size) {
121+ SCOPED_TRACE (" reverse iterate with BitMapClosure" );
122+ struct Closure : public BitMapClosure {
123+ TestBitMapIterationData _data;
124+
125+ Closure (const BitMap& map, const idx_t * positions, size_t positions_size)
126+ : _data(map, positions, positions_size, positions_size)
127+ {}
128+
129+ bool do_bit (idx_t i) override {
130+ _data._positions_index -= 1 ;
131+ _data.test (i);
132+ return true ;
133+ }
134+ } closure{map, positions, positions_size};
135+ ASSERT_TRUE (map.reverse_iterate (&closure));
136+ ASSERT_EQ (closure._data ._positions_index , 0u );
87137}
88138
89139// Test closure returning void. Also tests lambda returning bool.
@@ -92,24 +142,37 @@ static void test_iterate_non_closure(const BitMap& map,
92142 size_t positions_size) {
93143 SCOPED_TRACE (" iterate with non-BitMapClosure" );
94144 struct Closure {
95- const BitMap& _map;
96- const idx_t * _positions;
97- size_t _positions_index;
98- size_t _positions_size;
99-
145+ TestBitMapIterationData _data;
100146 Closure (const BitMap& map, const idx_t * positions, size_t positions_size)
101- : _map(map),
102- _positions (positions),
103- _positions_index(0 ),
104- _positions_size(positions_size)
147+ : _data(map, positions, 0 , positions_size)
105148 {}
106149
107150 void do_bit (idx_t i) {
108- test_iterate_step (_map, i, _positions, _positions_index++, _positions_size);
151+ _data.test (i);
152+ _data._positions_index += 1 ;
109153 }
110154 } closure{map, positions, positions_size};
111155 ASSERT_TRUE (map.iterate(&closure));
112- ASSERT_EQ (closure._positions_index, positions_size);
156+ ASSERT_EQ (closure._data ._positions_index , positions_size);
157+ }
158+
159+ static void test_reverse_iterate_non_closure (const BitMap& map,
160+ const idx_t * positions,
161+ size_t positions_size) {
162+ SCOPED_TRACE (" reverse iterate with non-BitMapClosure" );
163+ struct Closure {
164+ TestBitMapIterationData _data;
165+ Closure (const BitMap& map, const idx_t * positions, size_t positions_size)
166+ : _data(map, positions, positions_size, positions_size)
167+ {}
168+
169+ void do_bit (idx_t i) {
170+ _data._positions_index -= 1 ;
171+ _data.test (i);
172+ }
173+ } closure{map, positions, positions_size};
174+ ASSERT_TRUE (map.reverse_iterate (&closure));
175+ ASSERT_EQ (closure._data ._positions_index , 0u );
113176}
114177
115178static void fill_iterate_map (BitMap& map,
@@ -125,9 +188,14 @@ static void test_iterate(BitMap& map,
125188 const idx_t * positions,
126189 size_t positions_size) {
127190 fill_iterate_map (map, positions, positions_size);
191+
128192 test_iterate_lambda (map, positions, positions_size);
129193 test_iterate_closure (map, positions, positions_size);
130194 test_iterate_non_closure (map, positions, positions_size);
195+
196+ test_reverse_iterate_lambda (map, positions, positions_size);
197+ test_reverse_iterate_closure (map, positions, positions_size);
198+ test_reverse_iterate_non_closure (map, positions, positions_size);
131199}
132200
133201TEST (BitMap, iterate_empty) {
0 commit comments