@@ -6,7 +6,6 @@ use std::hash::{Hash, Hasher};
6
6
use std:: mem;
7
7
8
8
type Book = u32 ;
9
- type GroupedBasket = Vec < Group > ;
10
9
type Price = u32 ;
11
10
const BOOK_PRICE : Price = 800 ;
12
11
@@ -79,16 +78,15 @@ impl Hash for Group {
79
78
}
80
79
}
81
80
82
- fn basket_price ( basket : & GroupedBasket ) -> Price {
81
+ fn basket_price ( basket : & [ Group ] ) -> Price {
83
82
basket. iter ( ) . map ( |g| g. price ( ) ) . sum ( )
84
83
}
85
84
86
- /// Compute the hash of a GroupedBasket
85
+ /// Compute the hash of a Vec<Group>
87
86
///
88
87
/// Note that we don't actually care at all about the _values_ within
89
- /// the groups, only their lengths. Therefore, let's hash not the actual
90
- /// GB but its lengths.
91
- fn hash_of ( basket : & GroupedBasket ) -> u64 {
88
+ /// the groups, only their lengths. Therefore, let's hash only those.
89
+ fn hash_of ( basket : & [ Group ] ) -> u64 {
92
90
let lengths = basket
93
91
. iter ( )
94
92
. map ( |g| g. 0 . borrow ( ) . len ( ) )
@@ -107,11 +105,11 @@ pub fn lowest_price(books: &[Book]) -> Price {
107
105
108
106
struct DecomposeGroups {
109
107
prev_states : HashSet < u64 > ,
110
- next : Option < GroupedBasket > ,
108
+ next : Option < Vec < Group > > ,
111
109
}
112
110
113
111
impl Iterator for DecomposeGroups {
114
- type Item = GroupedBasket ;
112
+ type Item = Vec < Group > ;
115
113
fn next ( & mut self ) -> Option < Self :: Item > {
116
114
// our goal here: produce a stream of valid groups, differentiated by their
117
115
// counts, from most compact to most dispersed.
@@ -168,7 +166,7 @@ impl Iterator for DecomposeGroups {
168
166
169
167
impl DecomposeGroups {
170
168
fn new ( books : & [ Book ] ) -> DecomposeGroups {
171
- let mut book_groups = GroupedBasket :: new ( ) ;
169
+ let mut book_groups = Vec :: new ( ) ;
172
170
' nextbook: for book in books {
173
171
for Group ( book_group) in book_groups. iter ( ) {
174
172
if !book_group. borrow ( ) . contains ( & book) {
0 commit comments