@@ -124,40 +124,40 @@ impl Iterator for DecomposeGroups {
124124 // then move the last item from the most populous group into a new group, alone,
125125 // and return
126126 let return_value = self . next . clone ( ) ;
127- if let Some ( groups) = self . next . take ( ) {
128- if !( groups. is_empty ( ) || groups. iter ( ) . all ( |g| g. 0 . borrow ( ) . len ( ) == 1 ) ) {
129- let mut hypothetical ;
130- for mpg_book in groups [ 0 ] . 0 . borrow ( ) . iter ( ) {
131- for ( idx , other_group ) in groups[ 1 .. ] . iter ( ) . enumerate ( ) {
132- if !other_group . 0 . borrow ( ) . contains ( mpg_book ) {
133- hypothetical = groups . clone ( ) ;
134- hypothetical [ 0 ] . 0 . borrow_mut ( ) . remove ( mpg_book ) ;
135- hypothetical[ 1 + idx ] . 0 . borrow_mut ( ) . insert ( * mpg_book) ;
136- hypothetical . sort ( ) ;
137- let hypothetical_hash = hash_of ( & hypothetical) ;
138- if ! self . prev_states . contains ( & hypothetical_hash ) {
139- self . prev_states . insert ( hypothetical_hash) ;
140- self . next = Some ( hypothetical ) ;
141- return return_value ;
142- }
127+ if let Some ( groups) = self . next . take ( )
128+ && !( groups. is_empty ( ) || groups. iter ( ) . all ( |g| g. 0 . borrow ( ) . len ( ) == 1 ) )
129+ {
130+ let mut hypothetical ;
131+ for mpg_book in groups[ 0 ] . 0 . borrow ( ) . iter ( ) {
132+ for ( idx , other_group ) in groups [ 1 .. ] . iter ( ) . enumerate ( ) {
133+ if !other_group . 0 . borrow ( ) . contains ( mpg_book ) {
134+ hypothetical = groups . clone ( ) ;
135+ hypothetical[ 0 ] . 0 . borrow_mut ( ) . remove ( mpg_book) ;
136+ hypothetical [ 1 + idx ] . 0 . borrow_mut ( ) . insert ( * mpg_book ) ;
137+ hypothetical. sort ( ) ;
138+ let hypothetical_hash = hash_of ( & hypothetical ) ;
139+ if ! self . prev_states . contains ( & hypothetical_hash) {
140+ self . prev_states . insert ( hypothetical_hash ) ;
141+ self . next = Some ( hypothetical ) ;
142+ return return_value ;
143143 }
144144 }
145145 }
146- // we've gone through all the items of the most populous group,
147- // and none of them can be added to any other existing group.
148- // We need to create a new group;
149- let book = {
150- let backing_bt = groups[ 0 ] . 0 . borrow ( ) ;
151- let mut book_iter = backing_bt. iter ( ) ;
152- * book_iter. next ( ) . unwrap ( )
153- } ;
154- hypothetical = groups;
155- hypothetical[ 0 ] . 0 . borrow_mut ( ) . remove ( & book) ;
156- hypothetical. push ( Group :: new_containing ( book) ) ;
157- hypothetical. sort ( ) ;
158- self . prev_states . insert ( hash_of ( & hypothetical) ) ;
159- self . next = Some ( hypothetical) ;
160146 }
147+ // we've gone through all the items of the most populous group,
148+ // and none of them can be added to any other existing group.
149+ // We need to create a new group;
150+ let book = {
151+ let backing_bt = groups[ 0 ] . 0 . borrow ( ) ;
152+ let mut book_iter = backing_bt. iter ( ) ;
153+ * book_iter. next ( ) . unwrap ( )
154+ } ;
155+ hypothetical = groups;
156+ hypothetical[ 0 ] . 0 . borrow_mut ( ) . remove ( & book) ;
157+ hypothetical. push ( Group :: new_containing ( book) ) ;
158+ hypothetical. sort ( ) ;
159+ self . prev_states . insert ( hash_of ( & hypothetical) ) ;
160+ self . next = Some ( hypothetical) ;
161161 }
162162 return_value
163163 }
0 commit comments