Skip to content

Commit ab7c4b6

Browse files
lrvideckisweb-flow
andauthored
Clippy and refactor (#18)
* now lint with clippy * consistency * asdf * install verifyer helper tool later * fix unused var * revert * add back in clippy * fix clippy warnings * [auto-verifier] verify commit f96bc61 * better way * [auto-verifier] verify commit bc8f6ea * revert * less diff * [auto-verifier] verify commit 22d5e9f * new CI file * set up rust * [auto-verifier] verify commit 15ead42 * increase time limit * only build as we use oj verify to test * [auto-verifier] verify commit 13d63c5 * to test CI * revert * no longer keep timestamp file since all tests will run each time * comment some reasons --------- Co-authored-by: Luke Videckis <lukevideckis@gmail.com> Co-authored-by: GitHub <noreply@github.com>
1 parent 1170e0d commit ab7c4b6

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,55 @@ name: CI
22

33
on: [push, workflow_dispatch]
44

5+
env:
6+
CARGO_TERM_COLOR: always
7+
# causes CI to fail on any warning
8+
RUSTFLAGS: -D warnings
9+
RUSTDOCFLAGS: -D warnings
10+
511
jobs:
6-
verify:
12+
cargo:
713
runs-on: ubuntu-latest
8-
permissions:
9-
contents: write
10-
1114
steps:
1215
- uses: actions/checkout@v3
13-
1416
- uses: actions/setup-python@v4
15-
16-
- name: install oj-verify
17-
run: pip3 install -U online-judge-verify-helper
18-
1917
- name: Set up Rust (nightly)
2018
run: |
2119
rustup install nightly
2220
rustup override set nightly
23-
rustup component add --toolchain nightly rustfmt
24-
21+
rustup component add --toolchain nightly rustfmt clippy
2522
- name: cargo fmt
2623
run: cargo fmt --all -- --check
24+
- name: cargo clippy
25+
run: cargo clippy --all-targets --all-features -- -D warnings
26+
- name: cargo build
27+
run: cargo build --verbose
2728

28-
- name: cargo test
29-
# RUSTFLAGS="-D warnings" will fail CI on any compile warning
30-
run: RUSTFLAGS="-D warnings" cargo test
31-
29+
library_checker_aizu_tests:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- uses: actions/setup-python@v4
34+
- name: install oj-verify
35+
run: pip3 install -U online-judge-verify-helper
36+
- name: Set up Rust (nightly)
37+
run: |
38+
rustup install nightly
39+
rustup override set nightly
40+
rustup component add --toolchain nightly rustfmt clippy
3241
- name: use oj-verify
33-
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
run: oj-verify all --tle 1
42+
# regarging `--tle 2`: the oj-verify tool only allows testing in release mode
43+
#
44+
# regarding `--jobs 4`: github CI runs with 4 cores
45+
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
46+
#
47+
# regarding `--timeout `: github CI limits jobs to 6 hours
48+
# https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits
49+
#
50+
# since the library is a single crate, on a commit the entire crate is
51+
# rebuild, so oj-verify tool thinks everything changed, and then reruns all
52+
# tests; thus another reason for setting long timeout.
53+
#
54+
# since all tests are rerun on every commit anyways, there's no need for
55+
# the .verify-helper/timestamps.remote.json file
56+
run: oj-verify all --tle 2 --jobs 4 --timeout 21600

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.verify-helper/

.verify-helper/timestamps.remote.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/point_add_range_sum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn main() {
1212
}
1313

1414
let mut fenwick = Fenwick::<u64>::new(n);
15-
for i in 0..n {
16-
fenwick.add(i, a[i] as u64);
15+
for (i, &elem) in a.iter().enumerate() {
16+
fenwick.add(i, elem as u64);
1717
}
1818

1919
for que in queries {

src/dijk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::cmp::Reverse;
22
use std::collections::BinaryHeap;
33

4-
pub fn dijk(adj: &Vec<Vec<(usize, u64)>>, s: usize) -> Vec<u64> {
4+
pub fn dijk(adj: &[Vec<(usize, u64)>], s: usize) -> Vec<u64> {
55
let n = adj.len();
6-
let mut dist = vec![std::u64::MAX; n];
6+
let mut dist = vec![u64::MAX; n];
77
let mut q = BinaryHeap::new();
88
q.push(Reverse((0, s)));
99
while let Some(Reverse((d, u))) = q.pop() {

src/rmq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ pub struct RMQ<T> {
33
op: fn(T, T) -> T,
44
}
55
impl<T: Copy> RMQ<T> {
6-
pub fn new(a: &Vec<T>, op: fn(T, T) -> T) -> Self {
7-
let mut t = vec![a.clone(); 1];
6+
pub fn new(a: &[T], op: fn(T, T) -> T) -> Self {
7+
let mut t = vec![a.to_owned(); 1];
88
let mut i = 0;
99
while (2 << i) <= a.len() {
1010
t.push(

0 commit comments

Comments
 (0)