Skip to content

Commit 40b1c11

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

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/disco/src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
7575
let rdr = BufReader::new(movies_data.as_bytes());
7676
for line in rdr.lines() {
7777
let line = line?;
78-
let row: Vec<_> = line.split('|').collect();
79-
movies.insert(row[0].to_string(), row[1].to_string());
78+
let mut row = line.split('|');
79+
let id = row.next().unwrap().to_string();
80+
let name = row.next().unwrap().to_string();
81+
movies.insert(id, name);
8082
}
8183

8284
// read ratings and create dataset
@@ -85,12 +87,11 @@ fn load_movielens(path: &Path) -> Result<Dataset<i32, String>, Box<dyn Error>> {
8587
let rdr = BufReader::new(ratings_file);
8688
for line in rdr.lines() {
8789
let line = line?;
88-
let row: Vec<_> = line.split('\t').collect();
89-
data.push(
90-
row[0].parse::<i32>()?,
91-
movies.get(row[1]).unwrap().to_string(),
92-
row[2].parse()?,
93-
);
90+
let mut row = line.split('\t');
91+
let user_id: i32 = row.next().unwrap().parse()?;
92+
let item_id = movies.get(row.next().unwrap()).unwrap().to_string();
93+
let rating: f32 = row.next().unwrap().parse()?;
94+
data.push(user_id, item_id, rating);
9495
}
9596

9697
Ok(data)

0 commit comments

Comments
 (0)