File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ pub mod info;
33pub use info:: Info ;
44
55use super :: { data_tree:: DataTree , size} ;
6+ use itertools:: Itertools ;
67use rayon:: prelude:: * ;
78
89/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
@@ -55,21 +56,39 @@ where
5556
5657 let children = children
5758 . into_iter ( )
58- . par_bridge ( )
59- . map ( |name| TreeBuilder {
60- path : join_path ( & path, & name) ,
61- name,
62- get_info,
63- join_path,
64- max_depth,
59+ . chunks ( 100 )
60+ . into_iter ( )
61+ . map ( Vec :: < NameIter :: Item > :: from_iter)
62+ . map ( |names| -> Vec < _ > {
63+ names
64+ . into_par_iter ( )
65+ . map ( |name| TreeBuilder {
66+ path : join_path ( & path, & name) ,
67+ name,
68+ get_info,
69+ join_path,
70+ max_depth,
71+ } )
72+ . map ( Self :: from)
73+ . collect ( )
6574 } )
66- . map ( Self :: from ) ;
75+ . fold ( Vec :: new ( ) , add_short_vec_to_long ) ;
6776
6877 if max_depth > 0 {
69- DataTree :: dir ( name, size, children. collect ( ) )
78+ DataTree :: dir ( name, size, children)
7079 } else {
71- let size = size + children. map ( |child| child. size ( ) ) . sum ( ) ;
80+ let size = size + children. into_iter ( ) . map ( |child| child. size ( ) ) . sum ( ) ;
7281 DataTree :: dir ( name, size, Vec :: new ( ) )
7382 }
7483 }
7584}
85+
86+ fn add_short_vec_to_long < Item > ( mut a : Vec < Item > , mut b : Vec < Item > ) -> Vec < Item > {
87+ if a. len ( ) > b. len ( ) {
88+ a. extend ( b) ;
89+ a
90+ } else {
91+ b. extend ( a) ;
92+ b
93+ }
94+ }
You can’t perform that action at this time.
0 commit comments