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
2 changes: 1 addition & 1 deletion .artifacts/license/APACHE.LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Scattered-Systems
Copyright 2023 Scattered-Systems, DAO LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion .artifacts/license/MIT.LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 Joe McCain III
Copyright (c) 2023 Scattered-Systems, DAO LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
4 changes: 3 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tasks:
- init: |
J
sudo update -y && sudo upgrade -y && sudo autoremove -y
rustup default nightly
rustup target add wasm32-unknown-unknown wasm32-wasi --toolchain nightly
cargo build --release --target wasm32-unknown-unknown --workspace
command: cargo watch -x test --all

Expand Down
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
[workspace.package]
authors = ["FL03 <jo3mccain@icloud.com> (https://gitlab.com/FL03)", "Scattered-Systems (https://gitlab.com/scsys)"]
categories = []
description = "Algae is a collection of core algorithms and data-structures, written in Rust"
edition = "2021"
homepage = "https://github.com/scattered-systems/algae/wiki"
keywords = ["algorithms", "data-structures"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/scattered-systems/algae"
version = "0.1.18"

[workspace.dependencies]
decanter = { features = ["derive", "wasm"], version = "0.1.3" }
scsys = { features = [], version = "0.1.41" }

itertools = "0.10"
serde = { features = ["derive"], version = "1" }
serde_json = "1"
smart-default = "0.6"
strum = { features = ["derive"], version = "0.24" }

[workspace]
default-members = [
"algae"
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Scattered-Systems
Copyright 2023 Joe McCain III

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
# algae

[![Rust Clippy](https://github.com/scattered-systems/algae/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/scattered-systems/algae/actions/workflows/rust-clippy.yml)
[![Rust](https://github.com/scattered-systems/algae/actions/workflows/rust.yml/badge.svg)](https://github.com/scattered-systems/algae/actions/workflows/rust.yml)
[![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.bokerqi.topFL03/algae/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/algae/actions/workflows/rust.yml)

***

Welcome to algae, a collection of optimized data-structures and algorithms intended for use within blockchain environments.

## Developers

### Getting Started

git clone https://github.com/scattered-systems/algae
git clone https://github.com/FL03/algae

#### Testing

cargo build --release
cargo test --all-features --release

### Resources
## Contributors

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

* [Crate.io](https://crates.io/crates/algae)
* [Docs](https://docs.rs/algae)
## License

#### _References_
- [Apache-2.0](https://choosealicense.com/licenses/apache-2.0/)
- [MIT](https://choosealicense.com/licenses/mit/)
69 changes: 39 additions & 30 deletions algae/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
[package]
authors = ["FL03 <jo3mccain@icloud.com> (https://gitlab.com/FL03)", "Scattered-Systems (https://gitlab.com/scsys)"]
authors.workspace = true
categories = []
description = "Algae is a collection of core algorithms and data-structures, written in Rust"
edition = "2021"
homepage = "https://github.com/scattered-systems/algae/wiki"
description.workspace = true
edition.workspace = true
homepage.workspace = true
keywords = ["algorithms", "data-structures"]
license = "Apache-2.0"
license.workspace = true
name = "algae"
readme = "README.md"
repository = "https://github.com/scattered-systems/algae"
version = "0.1.17" # TODO - Update the cargo package version
readme.workspace = true
repository.workspace = true
version.workspace = true

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

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

core = ["merkle", "mmr"]
graph = ["algae-graph"]
merkle = ["algae-merkle"]
mmr = ["algae-mmr"]

wasm = []

[lib]
bench = false
crate-type = ["cdylib", "rlib"]
test = true

[dependencies]
scsys = { features = ["full"], version = "0.1.40" }
serde = { features = ["derive"], version = "1" }
serde_json = "1"

[dependencies.algae-graph]
optional = true
path = "../graph"
version = "0.1.17"

[dependencies.algae-merkle]
optional = true
path = "../merkle"
version = "0.1.17"

[dependencies.algae-mmr]
optional = true
path = "../mmr"
version = "0.1.17"
[build-dependencies]

[dependencies]
algae-graph = { features = [], optional = true, path = "../graph", version = "0.1.18" }
algae-merkle = { features = [], optional = true, path = "../merkle", version = "0.1.18" }
algae-mmr = { features = [], optional = true, path = "../mmr", version = "0.1.18" }

decanter.workspace = true
itertools.workspace = true
scsys.workspace = true
serde.workspace = true
serde_json.workspace = true
smart-default.workspace = true
strum.workspace = true

[dev-dependencies]
decanter.workspace = true
hex-literal = "0.3"
vrf = "0.2"

[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]

[target.wasm32-unknown-unknown]

[target.wasm32-wasi]
10 changes: 0 additions & 10 deletions algae/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions algae/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Appellation: algae <library>
Creator: FL03 <jo3mccain@icloud.com>
Contrib: FL03 <jo3mccain@icloud.com>
Description:
Algae is a comprehensive collection of algorithms and data-structures
*/
Expand All @@ -11,7 +11,7 @@ pub use algae_merkle as merkle;
#[cfg(feature = "mmr")]
pub use algae_mmr as mmr;

pub mod trees;
pub mod list;

pub mod prelude {
#[cfg(feature = "graph")]
Expand Down
7 changes: 7 additions & 0 deletions algae/src/list/linked/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Appellation: linked <module>
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... Summary ...
*/

pub mod persistant;
130 changes: 130 additions & 0 deletions algae/src/list/linked/persistant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
Appellation: persistant <module>
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... Summary ...
*/
use std::rc::Rc;

type Link<T> = Option<Rc<Node<T>>>;

struct Node<T> {
elem: T,
next: Link<T>,
}

impl<T> Node<T> {
pub fn new(elem: T, next: Link<T>) -> Self {
Self { elem, next }
}
pub fn data(&self) -> &T {
&self.elem
}
pub fn link(&self) -> &Link<T> {
&self.next
}
}

/// Singly-Linked, Persistant List
pub struct SLPList<T> {
head: Link<T>,
}

impl<T> SLPList<T> {
pub fn new() -> Self {
Self::from(None)
}
pub fn prepend(&self, elem: T) -> Self {
SLPList::from(Some(Rc::new(Node::new(elem, self.head.clone()))))
}

pub fn tail(&self) -> Self {
SLPList::from(self.head.as_ref().and_then(|node| node.link().clone()))
}

pub fn head(&self) -> Option<&T> {
self.head.as_ref().map(|node| node.data())
}

pub fn iter(&self) -> Iter<'_, T> {
Iter {
next: self.head.as_deref(),
}
}
}

impl<T> From<Link<T>> for SLPList<T> {
fn from(head: Link<T>) -> SLPList<T> {
SLPList { head }
}
}

impl<T> Default for SLPList<T> {
fn default() -> Self {
Self::from(None)
}
}

impl<T> Drop for SLPList<T> {
fn drop(&mut self) {
let mut head = self.head.take();
while let Some(node) = head {
if let Ok(mut node) = Rc::try_unwrap(node) {
head = node.next.take();
} else {
break;
}
}
}
}

pub struct Iter<'a, T> {
next: Option<&'a Node<T>>,
}

impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;

fn next(&mut self) -> Option<Self::Item> {
self.next.map(|node| {
self.next = node.next.as_deref();
&node.elem
})
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_linked_list() {
let list = SLPList::default();
assert_eq!(list.head(), None);

let list = list.prepend(1).prepend(2).prepend(3);
assert_eq!(list.head(), Some(&3));

let list = list.tail();
assert_eq!(list.head(), Some(&2));

let list = list.tail();
assert_eq!(list.head(), Some(&1));

let list = list.tail();
assert_eq!(list.head(), None);

// Make sure empty tail works
let list = list.tail();
assert_eq!(list.head(), None);
}

#[test]
fn test_linked_list_iter() {
let list = SLPList::default().prepend(1).prepend(2).prepend(3);

let mut iter = list.iter();
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&1));
}
}
7 changes: 7 additions & 0 deletions algae/src/list/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Appellation: list <module>
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... Summary ...
*/

pub mod linked;
10 changes: 0 additions & 10 deletions algae/src/trees/btree/cmps/mod.rs

This file was deleted.

Loading