Skip to content

Commit bb04ba6

Browse files
lrvideckisweb-flow
andauthored
functional style rmq (#13)
* functional style * format * fix * [auto-verifier] verify commit 33889c5 --------- Co-authored-by: Luke Videckis <lukevideckis@gmail.com> Co-authored-by: GitHub <noreply@github.com>
1 parent 4babcfa commit bb04ba6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"examples/point_add_range_sum.rs": "2024-05-16 05:41:44 -0600",
3+
"examples/shortest_path.rs": "2024-05-16 05:41:44 -0600",
4+
"examples/staticrmq.rs": "2024-05-16 05:41:44 -0600",
5+
"examples/unionfind.rs": "2024-05-16 05:41:44 -0600"
6+
}

src/rmq.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ impl<T: Ord + Copy> RMQ<T> {
77
let mut t = vec![a.clone(); 1];
88
let mut i = 0;
99
while (2 << i) <= a.len() {
10-
t.push(Vec::with_capacity(t[i].len() - (1 << i)));
11-
for j in 0..t[i].len() - (1 << i) {
12-
let x = op(t[i][j], t[i][j + (1 << i)]);
13-
t[i + 1].push(x);
14-
}
10+
t.push(
11+
(0..t[i].len() - (1 << i))
12+
.map(|j| op(t[i][j], t[i][j + (1 << i)]))
13+
.collect(),
14+
);
1515
i += 1;
1616
}
1717
Self { t, op }

0 commit comments

Comments
 (0)