@@ -59,31 +59,81 @@ static void test_iterate_lambda(const BitMap& map,
59
59
ASSERT_EQ (positions_index, positions_size);
60
60
}
61
61
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
+
62
96
// Test closure returning bool. Also tests lambda returning bool.
63
97
static void test_iterate_closure (const BitMap& map,
64
98
const idx_t * positions,
65
99
size_t positions_size) {
66
100
SCOPED_TRACE (" iterate with BitMapClosure" );
67
101
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;
72
103
73
104
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)
78
106
{}
79
107
80
108
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 ;
82
111
return true ;
83
112
}
84
113
} closure{map, positions, positions_size};
85
114
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 );
87
137
}
88
138
89
139
// Test closure returning void. Also tests lambda returning bool.
@@ -92,24 +142,37 @@ static void test_iterate_non_closure(const BitMap& map,
92
142
size_t positions_size) {
93
143
SCOPED_TRACE (" iterate with non-BitMapClosure" );
94
144
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;
100
146
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)
105
148
{}
106
149
107
150
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 ;
109
153
}
110
154
} closure{map, positions, positions_size};
111
155
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 );
113
176
}
114
177
115
178
static void fill_iterate_map (BitMap& map,
@@ -125,9 +188,14 @@ static void test_iterate(BitMap& map,
125
188
const idx_t * positions,
126
189
size_t positions_size) {
127
190
fill_iterate_map (map, positions, positions_size);
191
+
128
192
test_iterate_lambda (map, positions, positions_size);
129
193
test_iterate_closure (map, positions, positions_size);
130
194
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);
131
199
}
132
200
133
201
TEST (BitMap, iterate_empty) {
0 commit comments