@@ -16,12 +16,40 @@ impl<'a> Iterator for To64Iter<'a> {
16
16
fn next ( & mut self ) -> Option < u64 > {
17
17
self . inner . next ( ) . map ( |n| util:: join ( self . hi , n) )
18
18
}
19
+
20
+ #[ inline]
21
+ fn fold < B , F > ( self , init : B , f : F ) -> B
22
+ where
23
+ Self : Sized ,
24
+ F : FnMut ( B , Self :: Item ) -> B ,
25
+ {
26
+ #[ inline]
27
+ fn f_with_hi < B > ( mut f : impl FnMut ( B , u64 ) -> B , hi : u32 ) -> impl FnMut ( B , u32 ) -> B {
28
+ move |b, lo| f ( b, ( ( hi as u64 ) << 32 ) + ( lo as u64 ) )
29
+ }
30
+
31
+ self . inner . fold ( init, f_with_hi ( f, self . hi ) )
32
+ }
19
33
}
20
34
21
35
impl DoubleEndedIterator for To64Iter < ' _ > {
22
36
fn next_back ( & mut self ) -> Option < Self :: Item > {
23
37
self . inner . next_back ( ) . map ( |n| util:: join ( self . hi , n) )
24
38
}
39
+
40
+ #[ inline]
41
+ fn rfold < B , F > ( self , init : B , f : F ) -> B
42
+ where
43
+ Self : Sized ,
44
+ F : FnMut ( B , Self :: Item ) -> B ,
45
+ {
46
+ #[ inline]
47
+ fn f_with_hi < B > ( mut f : impl FnMut ( B , u64 ) -> B , hi : u32 ) -> impl FnMut ( B , u32 ) -> B {
48
+ move |b, lo| f ( b, ( ( hi as u64 ) << 32 ) + ( lo as u64 ) )
49
+ }
50
+
51
+ self . inner . rfold ( init, f_with_hi ( f, self . hi ) )
52
+ }
25
53
}
26
54
27
55
fn to64iter < ' a > ( t : ( & ' a u32 , & ' a RoaringBitmap ) ) -> To64Iter < ' a > {
@@ -38,12 +66,40 @@ impl Iterator for To64IntoIter {
38
66
fn next ( & mut self ) -> Option < u64 > {
39
67
self . inner . next ( ) . map ( |n| util:: join ( self . hi , n) )
40
68
}
69
+
70
+ #[ inline]
71
+ fn fold < B , F > ( self , init : B , f : F ) -> B
72
+ where
73
+ Self : Sized ,
74
+ F : FnMut ( B , Self :: Item ) -> B ,
75
+ {
76
+ #[ inline]
77
+ fn f_with_hi < B > ( mut f : impl FnMut ( B , u64 ) -> B , hi : u32 ) -> impl FnMut ( B , u32 ) -> B {
78
+ move |b, lo| f ( b, ( ( hi as u64 ) << 32 ) + ( lo as u64 ) )
79
+ }
80
+
81
+ self . inner . fold ( init, f_with_hi ( f, self . hi ) )
82
+ }
41
83
}
42
84
43
85
impl DoubleEndedIterator for To64IntoIter {
44
86
fn next_back ( & mut self ) -> Option < Self :: Item > {
45
87
self . inner . next_back ( ) . map ( |n| util:: join ( self . hi , n) )
46
88
}
89
+
90
+ #[ inline]
91
+ fn rfold < B , F > ( self , init : B , f : F ) -> B
92
+ where
93
+ Self : Sized ,
94
+ F : FnMut ( B , Self :: Item ) -> B ,
95
+ {
96
+ #[ inline]
97
+ fn f_with_hi < B > ( mut f : impl FnMut ( B , u64 ) -> B , hi : u32 ) -> impl FnMut ( B , u32 ) -> B {
98
+ move |b, lo| f ( b, ( ( hi as u64 ) << 32 ) + ( lo as u64 ) )
99
+ }
100
+
101
+ self . inner . rfold ( init, f_with_hi ( f, self . hi ) )
102
+ }
47
103
}
48
104
49
105
fn to64intoiter ( t : ( u32 , RoaringBitmap ) ) -> To64IntoIter {
@@ -104,13 +160,30 @@ impl<'a> Iterator for Iter<'a> {
104
160
( usize:: MAX , None )
105
161
}
106
162
}
163
+
164
+ #[ inline]
165
+ fn fold < B , F > ( self , init : B , f : F ) -> B
166
+ where
167
+ Self : Sized ,
168
+ F : FnMut ( B , Self :: Item ) -> B ,
169
+ {
170
+ self . inner . fold ( init, f)
171
+ }
107
172
}
108
173
109
174
impl DoubleEndedIterator for Iter < ' _ > {
110
175
fn next_back ( & mut self ) -> Option < Self :: Item > {
111
176
self . size_hint = self . size_hint . saturating_sub ( 1 ) ;
112
177
self . inner . next_back ( )
113
178
}
179
+
180
+ #[ inline]
181
+ fn rfold < Acc , Fold > ( self , init : Acc , fold : Fold ) -> Acc
182
+ where
183
+ Fold : FnMut ( Acc , Self :: Item ) -> Acc ,
184
+ {
185
+ self . inner . rfold ( init, fold)
186
+ }
114
187
}
115
188
116
189
#[ cfg( target_pointer_width = "64" ) ]
@@ -135,13 +208,30 @@ impl Iterator for IntoIter {
135
208
( usize:: MAX , None )
136
209
}
137
210
}
211
+
212
+ #[ inline]
213
+ fn fold < B , F > ( self , init : B , f : F ) -> B
214
+ where
215
+ Self : Sized ,
216
+ F : FnMut ( B , Self :: Item ) -> B ,
217
+ {
218
+ self . inner . fold ( init, f)
219
+ }
138
220
}
139
221
140
222
impl DoubleEndedIterator for IntoIter {
141
223
fn next_back ( & mut self ) -> Option < Self :: Item > {
142
224
self . size_hint = self . size_hint . saturating_sub ( 1 ) ;
143
225
self . inner . next_back ( )
144
226
}
227
+
228
+ #[ inline]
229
+ fn rfold < Acc , Fold > ( self , init : Acc , fold : Fold ) -> Acc
230
+ where
231
+ Fold : FnMut ( Acc , Self :: Item ) -> Acc ,
232
+ {
233
+ self . inner . rfold ( init, fold)
234
+ }
145
235
}
146
236
147
237
#[ cfg( target_pointer_width = "64" ) ]
0 commit comments