Skip to content
Open
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# we use the 2024 edition resolver
resolver = "3"

members = ["crates/*", "bin/*"]
default-members = ["crates/automata", "crates/automata-*", "crates/hoars", "bin/*"]
exclude = ["python", "bench"]
members = ["crates/*", "bin/*", "python"]
default-members = ["crates/automata", "crates/automata-*", "crates/hoars", "python", "bin/*"]
exclude = []

[workspace.dependencies]
tracing = "0.1"
Expand Down
2 changes: 0 additions & 2 deletions bench/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions bench/Cargo.toml

This file was deleted.

67 changes: 0 additions & 67 deletions bench/src/main.rs

This file was deleted.

4 changes: 0 additions & 4 deletions benchmarks.csv

This file was deleted.

11 changes: 0 additions & 11 deletions bin/incong/Cargo.toml

This file was deleted.

43 changes: 0 additions & 43 deletions bin/incong/src/main.rs

This file was deleted.

65 changes: 0 additions & 65 deletions perf

This file was deleted.

4 changes: 2 additions & 2 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ name = "automata"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.21.1"
automata = { path = "../" }
pyo3 = "0.27"
automata = { path = "../crates/automata" }
59 changes: 59 additions & 0 deletions python/src/dpa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use automata::{
TransitionSystem,
automaton::DPA,
core::{Void, alphabet::CharAlphabet},
ts::{Shrinkable, Sproutable},
};
use pyo3::prelude::*;

#[pyclass(name = "DPA")]
pub struct PyDPA {
inner: DPA,
}

#[pymethods]
impl PyDPA {
#[new]
#[pyo3(signature = (alphabet_size))]
pub fn new(alphabet_size: u8) -> Self {
Self {
inner: DPA::new_with_initial_color(CharAlphabet::of_size(alphabet_size as usize), Void),
}
}

pub fn size(&self) -> usize {
self.inner.size()
}

pub fn add_state(&mut self) -> u32 {
self.inner.add_state(Void)
}

/// Removes state with given id, returns `true` if some state is removed and `false` if no state was removed.
pub fn remove_state(&mut self, id: u32) -> bool {
self.inner.remove_state(id).is_some()
}

pub fn add_edge(
&mut self,
source: u32,
symbol: char,
priority: u8,
target: u32,
) -> Option<u32> {
self.inner
.add_edge((source, symbol, priority, target))
.map(|tup| tup.3)
}

pub fn remove_edge(&mut self, source: u32, symbol: char, target: u32) -> bool {
let Some(removed) = self
.inner
.remove_edges_between_matching(source, target, symbol)
else {
return false;
};
assert!(removed.len() <= 1);
removed.is_empty()
}
}
17 changes: 10 additions & 7 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use ::automata::{
TransitionSystem,
automaton::DFA,
core::alphabet::CharAlphabet,
ts::{Shrinkable, Sproutable},
};
use pyo3::prelude::*;

mod dpa;
pub use dpa::*;

#[pyclass(name = "DFA")]
pub struct PyDFA {
inner: DFA,
Expand Down Expand Up @@ -58,16 +67,10 @@ impl PyDFA {
}
}

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}

/// A Python module implemented in Rust.
#[pymodule]
fn automata(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
m.add_class::<PyDFA>()?;
m.add_class::<PyDPA>()?;
Ok(())
}
Loading