Skip to content

Commit 6b41d7e

Browse files
committed
Improved example [skip ci]
1 parent 40b1c11 commit 6b41d7e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

examples/disco/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6767

6868
fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
6969
// read movies, removing invalid UTF-8 bytes
70-
let mut movies = HashMap::new();
70+
let mut movies = HashMap::with_capacity(2000);
7171
let mut movies_file = File::open(path.join("u.item"))?;
7272
let mut buf = Vec::new();
7373
movies_file.read_to_end(&mut buf)?;
@@ -82,15 +82,15 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
8282
}
8383

8484
// read ratings and create dataset
85-
let mut data = Dataset::new();
85+
let mut data = Dataset::with_capacity(100000);
8686
let ratings_file = File::open(path.join("u.data"))?;
8787
let rdr = BufReader::new(ratings_file);
8888
for line in rdr.lines() {
8989
let line = line?;
9090
let mut row = line.split('\t');
91-
let user_id: i32 = row.next().unwrap().parse()?;
91+
let user_id = row.next().unwrap().parse()?;
9292
let item_id = movies.get(row.next().unwrap()).unwrap().to_string();
93-
let rating: f32 = row.next().unwrap().parse()?;
93+
let rating = row.next().unwrap().parse()?;
9494
data.push(user_id, item_id, rating);
9595
}
9696

0 commit comments

Comments
 (0)