Skip to content

Commit

Permalink
gh workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
coado committed May 18, 2024
1 parent c98d8ae commit 44cf4c5
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
on: [push, pull_request]

name: Continuous integration

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
5 changes: 2 additions & 3 deletions src/data_structures/fenwick_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl From<Vec<i32>> for FenwickTree {
fn from(nums: Vec<i32>) -> Self {
let mut fenwick_tree = FenwickTree::new(nums.len());

for i in 0..nums.len() {
fenwick_tree.tree[i] += nums[i];
for (i, val) in nums.iter().enumerate() {
fenwick_tree.tree[i] += val;
let r = i | (i + 1);
fenwick_tree.tree[r] += fenwick_tree.tree[i];
}
Expand Down Expand Up @@ -143,7 +143,6 @@ mod test {
use std::cmp::min;

use super::{FenwickTree, FenwickTree2D, MinFenwickTree};
use crate::utils::print_2d_vector;
use rand::prelude::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/data_structures/min_queue.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use std::collections::VecDeque;
// use std::collections::VecDeque;
9 changes: 9 additions & 0 deletions src/data_structures/min_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ where
}
}

impl<T> Default for Stack<T>
where
T: Ord + Copy,
{
fn default() -> Self {
Self::new()
}
}

#[cfg(test)]
mod test {
use super::Stack;
Expand Down
4 changes: 1 addition & 3 deletions src/data_structures/sparse_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ impl SparseTable {
let k = f64::log2(nums.len() as f64) as usize;
let mut st = vec![vec![0; nums.len()]; k + 1];

for i in 0..nums.len() {
st[0][i] = nums[i];
}
st[0][..nums.len()].copy_from_slice(&nums[..]);

for i in 1..=k {
let mut j = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/math/binary_exponentiation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

pub fn bipow_rec(a: i64, b: i64) -> i64 {
if b == 0 {
return 1;
}
let res = bipow_rec(a, b / 2);

if b % 2 == 1 {
return res * res * 2;
res * res * a
} else {
return res * res;
res * res
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::fmt::Display;

pub fn print_2d_vector<T: Display>(vector: &Vec<Vec<T>>) {
for i in 0..vector.len() {
for j in 0..vector[i].len() {
print!("{}, ", vector[i][j]);
for row in vector {
for val in row {
print!("{}, ", val);
}
println!();
}
}

pub fn print_vector<T: Display>(vector: &Vec<T>) {
for i in 0..vector.len() {
print!("{}, ", vector[i]);
for val in vector {
print!("{}, ", val);
}
}

0 comments on commit 44cf4c5

Please sign in to comment.