Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@ name: Clippy

on:
pull_request:
branches-ignore: [ "dev*" ]
tags: [ "v*.*.*" ]
branches: [ main, master, v*.*.*, ]
push:
branches-ignore: [ "dev*" ]
tags: [ "v*.*.*" ]
branches-ignore: [ "beta*", "dev*", "next*" ]
tags: [ "nightly*", "v*.*.*" ]
release:
schedule:
- cron: "30 9 * * *"
- cron: "30 9 * * *" # 9:30am UTC
workflow_dispatch:

jobs:
rust-clippy-analyze:
name: Run rust-clippy analyzing
runs-on: ubuntu-latest
clippy:
name: Clippy
permissions:
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true

- name: Install required cargo
- name: Setup
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-clippy
- name: clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
Expand Down
64 changes: 39 additions & 25 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ env:

on:
pull_request:
branches-ignore: [ "dev*" ]
tags: [ "v*.*.*" ]
branches: [ main, master, v*.*.*, ]
push:
branches-ignore: [ "dev*" ]
tags: [ "v*.*.*" ]
branches-ignore: [ "beta*", "dev*", "next*" ]
tags: [ "nightly*", "v*.*.*" ]
release:
types: [created]
schedule:
- cron: "30 9 * * *"
- cron: "30 9 * * *" # 9:30am UTC
workflow_dispatch:
inputs:
publish:
Expand All @@ -23,39 +24,52 @@ on:
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- nightly
platform: [ ubuntu-latest ]
toolchain: [ stable, nightly ]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- name: setup
run: rustup default ${{ matrix.toolchain }}
- run: cargo build --release -v --workspace
- run: cargo test --all --all-features --release -v
- name: setup (langspace)
run: |
rustup update
rustup default ${{ matrix.toolchain }}
- name: Build
run: cargo build --release -v --workspace
- name: Cache build
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target/release
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test
run: cargo test --all --release -v
- name: Bench
if: matrix.toolchain == 'nightly'
run: cargo bench --all -v
features:
if: ${{ github.event.inputs.publish }}
name: Features
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.event_name == 'release' && github.event.action == 'created' || github.event.inputs.publish == 'true'
name: Publish (features)
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
package:
- algae-graph
- algae-merkle
- algae-mmr
feature: [ "graph", "merkle", "mmr" ]
env:
PACKAGE_NAME: ${{ github.event.repository.name }}-${{ matrix.feature }}
steps:
- uses: actions/checkout@v3
- name: Publish (${{matrix.package}})
run: cargo publish --all-features -v -p ${{ matrix.package }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish (${{ env.PACKAGE_NAME }})
run: cargo publish --all-features -v -p ${{ env.PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish:
if: ${{ github.event.inputs.publish }}
name: Publish
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && github.event_name == 'release' && github.event.action == 'created' || github.event.inputs.publish == 'true'
name: Publish (sdk)
needs: features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish (algae)
run: cargo publish --all-features -v -p algae --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish (${{ github.event.repository.name }})
run: cargo publish --all-features -v -p ${{ github.event.repository.name }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/scattered-systems/algae"
version = "0.1.19"

[workspace.dependencies]
decanter = { features = ["derive", "wasm"], git = "https://github.com/FL03/decanter", branch = "v0.1.5", version = "0.1.5" }
decanter = { features = ["derive", "wasm"], version = "0.1.5" }

anyhow = "1"
itertools = "0.10"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![crates.io](https://img.shields.io/crates/v/algae.svg)](https://crates.io/crates/algae)
[![docs.rs](https://docs.rs/algae/badge.svg)](https://docs.rs/algae)
[![Clippy](https://github.com/FL03/algae/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/FL03/algae/actions/workflows/rust-clippy.yml)
[![Rust](https://github.comFL03/algae/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/algae/actions/workflows/rust.yml)
[![Clippy](https://github.com/FL03/algae/actions/workflows/clippy.yml/badge.svg)](https://github.com/FL03/algae/actions/workflows/clippy.yml)
[![Rust](https://github.com/FL03/algae/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/algae/actions/workflows/rust.yml)

***

Expand Down
13 changes: 7 additions & 6 deletions algae/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
[package]
authors.workspace = true
categories = []
categories.workspace = true
description.workspace = true
edition.workspace = true
homepage.workspace = true
keywords = ["algorithms", "data-structures"]
keywords.workspace = true
license.workspace = true
name = "algae"
readme.workspace = true
repository.workspace = true
version.workspace = true

[features]
default = ["core"]

core = [
default = ["core", "graph", "merkle", "mmr"]
full = [
"core",
"graph",
"merkle",
"mmr",
"graph"
]

core = []
graph = ["algae-graph"]
merkle = ["algae-merkle"]
mmr = ["algae-mmr"]
Expand Down
52 changes: 52 additions & 0 deletions algae/benches/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// bench.rs
#![feature(test)]

extern crate test;

use std::mem::replace;
use test::Bencher;

// bench: find the `BENCH_SIZE` first terms of the fibonacci sequence
static BENCH_SIZE: usize = 20;

// recursive fibonacci
fn fibonacci(n: usize) -> u32 {
if n < 2 {
1
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}

// iterative fibonacci
struct Fibonacci {
curr: u32,
next: u32,
}

impl Iterator for Fibonacci {
type Item = u32;
fn next(&mut self) -> Option<u32> {
let new_next = self.curr + self.next;
let new_curr = replace(&mut self.next, new_next);

Some(replace(&mut self.curr, new_curr))
}
}

fn fibonacci_sequence() -> Fibonacci {
Fibonacci { curr: 1, next: 1 }
}

// function to benchmark must be annotated with `#[bench]`
#[bench]
fn recursive_fibonacci(b: &mut Bencher) {
// exact code to benchmark must be passed as a closure to the iter
// method of Bencher
b.iter(|| (0..BENCH_SIZE).map(fibonacci).collect::<Vec<u32>>())
}

#[bench]
fn iterative_fibonacci(b: &mut Bencher) {
b.iter(|| fibonacci_sequence().take(BENCH_SIZE).collect::<Vec<u32>>())
}
25 changes: 25 additions & 0 deletions algae/benches/graphs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// bench.rs
#![feature(test)]

extern crate test;
use algae::graph::{DirectedGraph, Edge, Graph,};
use test::Bencher;

const TEST_EDGES: [(&str, &str, usize); 5] = [
("a", "b", 5),
("c", "a", 7),
("b", "c", 10),
("d", "c", 10),
("e", "f", 10),
];

#[bench]
fn bench_directed(b: &mut Bencher) {
let mut graph = DirectedGraph::<&str, usize>::new();
b.iter(|| {
TEST_EDGES
.into_iter()
.map(|i| Edge::from(i))
.for_each(|i| graph.add_edge(i));
});
}
18 changes: 7 additions & 11 deletions graph/src/cmp/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Description: an edge consists of two nodes and an optional edge value
*/
use super::Pair;
use crate::{Node, Weight};
use crate::Node;
use serde::{Deserialize, Serialize};

pub trait Related<N: Node, V> {}
Expand All @@ -13,7 +13,6 @@ pub trait Related<N: Node, V> {}
pub struct Edge<N = String, V = i64>
where
N: Node,
V: Weight,
{
pair: Pair<N>,
weight: V,
Expand All @@ -22,10 +21,12 @@ where
impl<N, V> Edge<N, V>
where
N: Node,
V: Weight,
{
pub fn new(pair: Pair<N>, weight: V) -> Self {
Self { pair, weight }
pub fn new(a: N, b: N, weight: V) -> Self {
Self {
pair: Pair::new(a, b),
weight,
}
}
pub fn pair(&self) -> Pair<N> {
self.pair.clone()
Expand All @@ -38,20 +39,15 @@ where
impl<N, V> From<(N, N, V)> for Edge<N, V>
where
N: Node,
V: Weight,
{
fn from(data: (N, N, V)) -> Self {
Self {
pair: Pair::new(data.0, data.1),
weight: data.2,
}
Self::new(data.0, data.1, data.2)
}
}

impl<N, V> From<(Pair<N>, V)> for Edge<N, V>
where
N: Node,
V: Weight,
{
fn from(data: (Pair<N>, V)) -> Self {
Self {
Expand Down
31 changes: 19 additions & 12 deletions graph/src/directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... Summary ...
*/
use crate::{cmp::Edge, store::AdjacencyTable};
use crate::{Contain, Graph, GraphExt, Node, Subgraph, Weight};
use crate::{store::AdjacencyTable, Edge, Node, Weight};
use crate::{Contain, Graph, GraphExt, Subgraph};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
Expand All @@ -16,6 +16,23 @@ where
store: AdjacencyTable<N, V>,
}

impl<N, V> DirectedGraph<N, V>
where
N: Node,
V: Weight,
{
pub fn new() -> Self {
Self {
store: AdjacencyTable::new(),
}
}
pub fn with_capacity(capacity: usize) -> Self {
Self {
store: AdjacencyTable::with_capacity(capacity),
}
}
}

impl<N, V> AsMut<AdjacencyTable<N, V>> for DirectedGraph<N, V>
where
N: Node,
Expand Down Expand Up @@ -74,16 +91,6 @@ where
N: Node,
V: Weight,
{
fn new() -> Self {
Self {
store: AdjacencyTable::new(),
}
}
fn with_capacity(capacity: usize) -> Self {
Self {
store: AdjacencyTable::with_capacity(capacity),
}
}
}

impl<N, V> Subgraph<N, V> for DirectedGraph<N, V>
Expand Down
Loading