diff --git a/Cargo.lock b/Cargo.lock index 76ff3cca..78f55416 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -900,7 +900,7 @@ dependencies = [ [[package]] name = "rstm" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "criterion", @@ -916,7 +916,7 @@ dependencies = [ [[package]] name = "rstm-core" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "bytes", @@ -943,7 +943,7 @@ dependencies = [ [[package]] name = "rstm-macros" -version = "0.1.4" +version = "0.1.5" dependencies = [ "proc-macro2", "quote", @@ -952,7 +952,7 @@ dependencies = [ [[package]] name = "rstm-state" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "bytes", @@ -977,7 +977,7 @@ dependencies = [ [[package]] name = "rstm-tape" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "bytes", @@ -1004,7 +1004,7 @@ dependencies = [ [[package]] name = "rstm-traits" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 7bd6e024..8aa1f714 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,21 +15,21 @@ categories = [ description = "This crate focuses on building concrete implementations for Turing Machines." edition = "2024" homepage = "https://github.com/FL03/rstm/wiki" -keywords = ["turing machine", "tm", "fsm", "computation"] +keywords = ["turing-machine", "tm", "fsm", "computation"] license = "Apache-2.0" readme = "README.md" repository = "https://github.com/FL03/rstm.git" rust-version = "1.91.0" -version = "0.1.4" +version = "0.1.5" [workspace.dependencies] # local -rstm = { default-features = false, path = "crates/rstm", version = "0.1.4" } -rstm-core = { default-features = false, path = "crates/core", version = "0.1.4" } -rstm-macros = { default-features = false, path = "crates/macros", version = "0.1.4" } -rstm-state = { default-features = false, path = "crates/state", version = "0.1.4" } -rstm-tape = { default-features = false, path = "crates/tape", version = "0.1.4" } -rstm-traits = { default-features = false, path = "crates/traits", version = "0.1.4" } +rstm = { default-features = false, path = "crates/rstm", version = "0.1.5" } +rstm-core = { default-features = false, path = "crates/core", version = "0.1.5" } +rstm-macros = { default-features = false, path = "crates/macros", version = "0.1.5" } +rstm-state = { default-features = false, path = "crates/state", version = "0.1.5" } +rstm-tape = { default-features = false, path = "crates/tape", version = "0.1.5" } +rstm-traits = { default-features = false, path = "crates/traits", version = "0.1.5" } # custom contained = { default-features = false, features = ["macros"], version = "0.2.3" } rspace-traits = { default-features = false, version = "0.0.9" } diff --git a/crates/core/src/programs/impls/imp_program_base.rs b/crates/core/src/programs/impls/imp_program_base.rs index 2b68ffa4..fdd8a42b 100644 --- a/crates/core/src/programs/impls/imp_program_base.rs +++ b/crates/core/src/programs/impls/imp_program_base.rs @@ -107,7 +107,8 @@ where { self.rules().get(head) } - + /// given a state and symbol, returns the corresponding tail if it exists within the + /// ruleset pub fn find_tail(&self, state: State<&Q>, sym: &A) -> Option<&Tail> where R: Ruleset, @@ -115,4 +116,15 @@ where { self.rules().find_tail(state, sym) } + /// returns the number of rules within the ruleset + pub fn len(&self) -> usize + { + self.rules().len() + } + /// returns true if the ruleset is considered empty (i.e. contains no rules), + /// otherwise false. + pub fn is_empty(&self) -> bool + { + self.rules().is_empty() + } } diff --git a/crates/core/src/programs/traits/ruleset.rs b/crates/core/src/programs/traits/ruleset.rs index bd987bd1..79276be2 100644 --- a/crates/core/src/programs/traits/ruleset.rs +++ b/crates/core/src/programs/traits/ruleset.rs @@ -15,6 +15,12 @@ where type Rule: Instruction; private! {} + + fn len(&self) -> usize; + + fn is_empty(&self) -> bool { + self.len() == 0 + } } pub trait Ruleset: RawRuleset @@ -22,9 +28,14 @@ where Q: RawState, Self::Rule: Instruction, Tail = Tail>, { - fn get(&self, head: &Head) -> Option<&Tail>; fn find_tail(&self, state: State<&Q>, sym: &A) -> Option<&Tail>; + + fn get(&self, head: &Head) -> Option<&Tail>; + + fn find_head(&self, Head { state, symbol }: Head<&Q, &A>) -> Option<&Tail> { + self.find_tail(state, symbol) + } } pub trait RuleSetMut: RawRuleset @@ -47,6 +58,10 @@ where type Rule = R::Rule; seal! {} + + fn len(&self) -> usize { + (*self).len() + } } macro_rules! get_tail { @@ -81,6 +96,14 @@ where type Rule = I; seal! {} + + fn len(&self) -> usize { + <[I]>::len(self) + } + + fn is_empty(&self) -> bool { + <[I]>::is_empty(self) + } } impl Ruleset for [I] @@ -105,6 +128,14 @@ where type Rule = I; seal! {} + + fn len(&self) -> usize { + <[I]>::len(self) + } + + fn is_empty(&self) -> bool { + <[I]>::is_empty(self) + } } impl Ruleset for &[I] @@ -130,6 +161,14 @@ where type Rule = I; seal! {} + + fn len(&self) -> usize { + <[I]>::len(self) + } + + fn is_empty(&self) -> bool { + <[I]>::is_empty(self) + } } impl Ruleset for &mut [I] @@ -172,6 +211,14 @@ where type Rule = I; seal! {} + + fn len(&self) -> usize { + <[I]>::len(self) + } + + fn is_empty(&self) -> bool { + <[I]>::is_empty(self) + } } impl Ruleset for [I; N] @@ -205,6 +252,14 @@ mod impl_alloc { type Rule = I; seal! {} + + fn len(&self) -> usize { + >::len(self) + } + + fn is_empty(&self) -> bool { + >::is_empty(self) + } } impl Ruleset for Vec @@ -228,7 +283,16 @@ mod impl_alloc { I: Instruction, { type Rule = I; + seal! {} + + fn len(&self) -> usize { + >::len(self) + } + + fn is_empty(&self) -> bool { + >::is_empty(self) + } } impl Ruleset for BTreeSet @@ -254,7 +318,16 @@ mod impl_alloc { type Rule = Rule; seal! {} + + fn len(&self) -> usize { + , Tail>>::len(self) + } + + fn is_empty(&self) -> bool { + , Tail>>::is_empty(self) + } } + impl Ruleset for BTreeMap, Tail> where Q: RawState + Ord, @@ -282,14 +355,23 @@ mod impl_hashbrown { use core::hash::Hash; use hashbrown::{HashMap, HashSet}; - impl RawRuleset for HashSet> + impl RawRuleset for HashSet where + I: Instruction, Q: RawState + Eq + Hash, A: Eq + Hash, { type Rule = Rule; seal! {} + + fn len(&self) -> usize { + >::len(self) + } + + fn is_empty(&self) -> bool { + >::is_empty(self) + } } impl Ruleset for HashSet> @@ -314,6 +396,14 @@ mod impl_hashbrown { type Rule = Rule; seal! {} + + fn len(&self) -> usize { + , Tail>>::len(self) + } + + fn is_empty(&self) -> bool { + , Tail>>::is_empty(self) + } } impl Ruleset for HashMap, Tail> @@ -343,14 +433,23 @@ mod impl_std { use core::hash::Hash; use std::collections::{HashMap, HashSet}; - impl RawRuleset for HashSet> + impl RawRuleset for HashSet where + I: Instruction, Q: RawState + Eq + Hash, A: Eq + Hash, { type Rule = Rule; seal! {} + + fn len(&self) -> usize { + >::len(self) + } + + fn is_empty(&self) -> bool { + >::is_empty(self) + } } impl Ruleset for HashSet> @@ -375,6 +474,14 @@ mod impl_std { type Rule = Rule; seal! {} + + fn len(&self) -> usize { + , Tail>>::len(self) + } + + fn is_empty(&self) -> bool { + , Tail>>::is_empty(self) + } } impl Ruleset for HashMap, Tail> diff --git a/default.nix b/default.nix index 21e31777..96ff11ed 100644 --- a/default.nix +++ b/default.nix @@ -27,7 +27,7 @@ let }; common = { - version = "0.1.4"; + version = "0.1.5"; src = self; cargoLock = { diff --git a/flake.nix b/flake.nix index 83585788..04683249 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ in rec { packages.default = pkgs.rustPlatform.buildRustPackage { pname = "rstm"; - version = "0.1.4"; + version = "0.1.5"; src = self; # ./.; cargoLock = { lockFile = ./Cargo.lock; }; };