Skip to content

Commit ae10da6

Browse files
authored
style: include range_plus_one (TheAlgorithms#869)
1 parent 8049c34 commit ae10da6

20 files changed

+38
-30
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ missing_panics_doc = { level = "allow", priority = 1 }
5353
module_name_repetitions = { level = "allow", priority = 1 }
5454
must_use_candidate = { level = "allow", priority = 1 }
5555
needless_pass_by_value = { level = "allow", priority = 1 }
56-
range_plus_one = { level = "allow", priority = 1 }
5756
redundant_closure_for_method_calls = { level = "allow", priority = 1 }
5857
return_self_not_must_use = { level = "allow", priority = 1 }
5958
semicolon_if_nothing_returned = { level = "allow", priority = 1 }

src/ciphers/transposition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! original message. The most commonly referred to Transposition Cipher is the
66
//! COLUMNAR TRANSPOSITION cipher, which is demonstrated below.
77
8-
use std::ops::Range;
8+
use std::ops::RangeInclusive;
99

1010
/// Encrypts or decrypts a message, using multiple keys. The
1111
/// encryption is based on the columnar transposition method.
@@ -142,8 +142,8 @@ fn decrypt(mut msg: String, key_order: Vec<usize>) -> String {
142142

143143
split_large.iter_mut().rev().for_each(|key_index| {
144144
counter -= 1;
145-
let range: Range<usize> =
146-
((*key_index * split_size) + counter)..(((*key_index + 1) * split_size) + counter + 1);
145+
let range: RangeInclusive<usize> =
146+
((*key_index * split_size) + counter)..=(((*key_index + 1) * split_size) + counter);
147147

148148
let slice: String = msg[range.clone()].to_string();
149149
indexed_vec.push((*key_index, slice));

src/data_structures/hash_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mod tests {
9393
let mut hash_table = HashTable::new();
9494
let initial_capacity = hash_table.elements.capacity();
9595

96-
for i in 0..initial_capacity * 3 / 4 + 1 {
96+
for i in 0..=initial_capacity * 3 / 4 {
9797
hash_table.insert(TestKey(i), TestKey(i + 10));
9898
}
9999

src/data_structures/lazy_segment_tree.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ mod tests {
235235
fn check_single_interval_min(array: Vec<i32>) -> TestResult {
236236
let mut seg_tree = LazySegmentTree::from_vec(&array, min);
237237
for (i, value) in array.into_iter().enumerate() {
238-
let res = seg_tree.query(i..(i + 1));
238+
let res = seg_tree.query(Range {
239+
start: i,
240+
end: i + 1,
241+
});
239242
if res != Some(value) {
240243
return TestResult::error(format!("Expected {:?}, got {:?}", Some(value), res));
241244
}
@@ -247,7 +250,10 @@ mod tests {
247250
fn check_single_interval_max(array: Vec<i32>) -> TestResult {
248251
let mut seg_tree = LazySegmentTree::from_vec(&array, max);
249252
for (i, value) in array.into_iter().enumerate() {
250-
let res = seg_tree.query(i..(i + 1));
253+
let res = seg_tree.query(Range {
254+
start: i,
255+
end: i + 1,
256+
});
251257
if res != Some(value) {
252258
return TestResult::error(format!("Expected {:?}, got {:?}", Some(value), res));
253259
}
@@ -259,7 +265,10 @@ mod tests {
259265
fn check_single_interval_sum(array: Vec<i32>) -> TestResult {
260266
let mut seg_tree = LazySegmentTree::from_vec(&array, max);
261267
for (i, value) in array.into_iter().enumerate() {
262-
let res = seg_tree.query(i..(i + 1));
268+
let res = seg_tree.query(Range {
269+
start: i,
270+
end: i + 1,
271+
});
263272
if res != Some(value) {
264273
return TestResult::error(format!("Expected {:?}, got {:?}", Some(value), res));
265274
}

src/dynamic_programming/fibonacci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn get_pisano_sequence_and_period(m: i64) -> (i128, Vec<i128>) {
226226
let mut pisano_sequence: Vec<i128> = vec![a, b];
227227

228228
// Iterating through all the fib numbers to get the sequence
229-
for _i in 0..(m * m) + 1 {
229+
for _i in 0..=(m * m) {
230230
let c = (a + b) % m as i128;
231231

232232
// adding number into the sequence

src/general/mex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::BTreeSet;
66
/// O(nlog(n)) implementation
77
pub fn mex_using_set(arr: &[i64]) -> i64 {
88
let mut s: BTreeSet<i64> = BTreeSet::new();
9-
for i in 0..arr.len() + 1 {
9+
for i in 0..=arr.len() {
1010
s.insert(i as i64);
1111
}
1212
for x in arr {

src/graph/bipartite_matching.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ impl BipartiteMatching {
4545
// Note: It does not modify self.mt1, it only works on self.mt2
4646
pub fn kuhn(&mut self) {
4747
self.mt2 = vec![-1; self.num_vertices_grp2 + 1];
48-
for v in 1..self.num_vertices_grp1 + 1 {
48+
for v in 1..=self.num_vertices_grp1 {
4949
self.used = vec![false; self.num_vertices_grp1 + 1];
5050
self.try_kuhn(v);
5151
}
5252
}
5353
pub fn print_matching(&self) {
54-
for i in 1..self.num_vertices_grp2 + 1 {
54+
for i in 1..=self.num_vertices_grp2 {
5555
if self.mt2[i] == -1 {
5656
continue;
5757
}
@@ -115,7 +115,7 @@ impl BipartiteMatching {
115115
let mut dist = vec![i32::MAX; self.num_vertices_grp1 + 1];
116116
let mut res = 0;
117117
while self.bfs(&mut dist) {
118-
for u in 1..self.num_vertices_grp1 + 1 {
118+
for u in 1..=self.num_vertices_grp1 {
119119
if self.mt1[u] == 0 && self.dfs(u as i32, &mut dist) {
120120
res += 1;
121121
}

src/machine_learning/cholesky.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub fn cholesky(mat: Vec<f64>, n: usize) -> Vec<f64> {
44
}
55
let mut res = vec![0.0; mat.len()];
66
for i in 0..n {
7-
for j in 0..(i + 1) {
7+
for j in 0..=i {
88
let mut s = 0.0;
99
for k in 0..j {
1010
s += res[i * n + k] * res[j * n + k];

src/math/area_under_curve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn area_under_curve(start: f64, end: f64, func: fn(f64) -> f64, step_count:
1212
let mut fx1 = func(start);
1313
let mut fx2: f64;
1414

15-
for eval_point in (1..step_count + 1).map(|x| (x as f64 * step_length) + start) {
15+
for eval_point in (1..=step_count).map(|x| (x as f64 * step_length) + start) {
1616
fx2 = func(eval_point);
1717
area += (fx2 + fx1).abs() * step_length * 0.5;
1818
fx1 = fx2;

src/math/factors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub fn factors(number: u64) -> Vec<u64> {
77
let mut factors: Vec<u64> = Vec::new();
88

9-
for i in 1..((number as f64).sqrt() as u64 + 1) {
9+
for i in 1..=((number as f64).sqrt() as u64) {
1010
if number % i == 0 {
1111
factors.push(i);
1212
if i != number / i {

0 commit comments

Comments
 (0)