Skip to content

Commit 1740afa

Browse files
Added max memory load
1 parent 561e53b commit 1740afa

4 files changed

Lines changed: 46 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 29 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/python_mg/_lib_name.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ class SyntacticStructure:
4040
def to_tree(self) -> ParseTree:
4141
"""Converts a syntactic structure into a graph structure"""
4242

43+
def max_memory_load(self) -> int:
44+
"""Gets the largest amount of movers at a single point"""
45+
4346
def __to_tree_inner(
4447
self,
4548
) -> tuple[list[tuple[int, MGNode]], list[tuple[int, int, MGEdge]], int]: ...
4649

4750
class Continuation:
4851
"""A continuation of a prefix string"""
4952

50-
def __init__(self) -> None: ...
53+
def __init__(self, word: str) -> None: ...
5154
@staticmethod
5255
def EOS() -> "Continuation": ...
5356
def is_end_of_string(self) -> bool:

python/tests/test_mg.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ def test_lexicon():
1313
)
1414

1515

16+
def test_memory_load():
17+
grammar = Lexicon("a::b= c= +a +e C\nb::b -a\nc::c -e")
18+
parse = grammar.parse("c b a", "C")[0]
19+
assert parse.max_memory_load() == 2
20+
grammar = Lexicon("a::b= +a c= +e C\nb::b -a\nc::c -e")
21+
parse = grammar.parse("c b a", "C")[0]
22+
assert parse.max_memory_load() == 1
23+
24+
1625
def test_continuations():
1726
x = Lexicon("a::b= S\nb::b")
1827
assert x.continuations("a", "S") == {Continuation("b")}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl PySyntacticStructure {
8686
self.rules.to_tree(&lex.lexicon).to_latex()
8787
}
8888

89+
fn max_memory_load(&self) -> usize {
90+
self.rules.max_memory_load()
91+
}
92+
8993
#[allow(clippy::type_complexity)]
9094
fn __to_tree_inner(&self) -> (Vec<(usize, PyMgNode)>, Vec<(usize, usize, PyMgEdge)>, usize) {
9195
let (g, root) = self.rules.to_petgraph(&self.lex.get().lexicon);

0 commit comments

Comments
 (0)