File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,49 @@ where
256
256
}
257
257
}
258
258
259
+ fn fold < B , G > ( mut self , init : B , mut f : G ) -> B
260
+ where
261
+ Self : Sized ,
262
+ G : FnMut ( B , Self :: Item ) -> B ,
263
+ {
264
+ let mut acc = init;
265
+ let mut left = self . left . next ( ) ;
266
+ let mut right = self . right . next ( ) ;
267
+
268
+ loop {
269
+ match ( left, right) {
270
+ ( Some ( l) , Some ( r) ) => match self . cmp_fn . merge ( l, r) {
271
+ ( None , Some ( r) , x) => {
272
+ acc = f ( acc, x) ;
273
+ left = self . left . next ( ) ;
274
+ right = Some ( r) ;
275
+ }
276
+ ( Some ( l) , _, x) => {
277
+ acc = f ( acc, x) ;
278
+ left = Some ( l) ;
279
+ right = self . right . next ( ) ;
280
+ }
281
+ _ => unreachable ! ( ) ,
282
+ } ,
283
+ ( Some ( l) , None ) => {
284
+ self . left . put_back ( l) ;
285
+ acc = self . left . fold ( acc, |acc, x| f ( acc, F :: left ( x) ) ) ;
286
+ break ;
287
+ }
288
+ ( None , Some ( r) ) => {
289
+ self . right . put_back ( r) ;
290
+ acc = self . right . fold ( acc, |acc, x| f ( acc, F :: right ( x) ) ) ;
291
+ break ;
292
+ }
293
+ ( None , None ) => {
294
+ break ;
295
+ }
296
+ }
297
+ }
298
+
299
+ acc
300
+ }
301
+
259
302
fn size_hint ( & self ) -> SizeHint {
260
303
F :: size_hint ( self . left . size_hint ( ) , self . right . size_hint ( ) )
261
304
}
You can’t perform that action at this time.
0 commit comments