Skip to content

Commit ce949fb

Browse files
authored
Revert "Successors length limits (#224)" (#229)
This reverts commit 39ca92a.
1 parent 39ca92a commit ce949fb

File tree

2 files changed

+4
-66
lines changed

2 files changed

+4
-66
lines changed

automata/fa/dfa.py

+4-55
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,6 @@ def predecessor(
12761276
*,
12771277
strict: bool = True,
12781278
key: Optional[Callable[[Any], Any]] = None,
1279-
min_length: int = 0,
1280-
max_length: Optional[int] = None,
12811279
) -> Optional[str]:
12821280
"""
12831281
Returns the first string accepted by the DFA that comes before
@@ -1293,10 +1291,6 @@ def predecessor(
12931291
key : Optional[Callable], default: None
12941292
Function for defining custom lexicographical ordering. Defaults to using
12951293
the standard string ordering.
1296-
min_length : int, default: 0
1297-
Limits generation to words with at least the given length.
1298-
max_length : Optional[int], default: None
1299-
Limits generation to words with at most the given length.
13001294
13011295
Returns
13021296
------
@@ -1309,13 +1303,7 @@ def predecessor(
13091303
Raised if the language accepted by self is infinite, as we cannot
13101304
generate predecessors in this case.
13111305
"""
1312-
for word in self.predecessors(
1313-
input_str,
1314-
strict=strict,
1315-
key=key,
1316-
min_length=min_length,
1317-
max_length=max_length,
1318-
):
1306+
for word in self.predecessors(input_str, strict=strict, key=key):
13191307
return word
13201308
return None
13211309

@@ -1325,8 +1313,6 @@ def predecessors(
13251313
*,
13261314
strict: bool = True,
13271315
key: Optional[Callable[[Any], Any]] = None,
1328-
min_length: int = 0,
1329-
max_length: Optional[int] = None,
13301316
) -> Generator[str, None, None]:
13311317
"""
13321318
Generates all strings that come before the input string
@@ -1342,10 +1328,6 @@ def predecessors(
13421328
key : Optional[Callable], default: None
13431329
Function for defining custom lexicographical ordering. Defaults to using
13441330
the standard string ordering.
1345-
min_length : int, default: 0
1346-
Limits generation to words with at least the given length.
1347-
max_length : Optional[int], default: None
1348-
Limits generation to words with at most the given length.
13491331
13501332
Returns
13511333
------
@@ -1359,23 +1341,14 @@ def predecessors(
13591341
Raised if the language accepted by self is infinite, as we cannot
13601342
generate predecessors in this case.
13611343
"""
1362-
yield from self.successors(
1363-
input_str,
1364-
strict=strict,
1365-
reverse=True,
1366-
key=key,
1367-
min_length=min_length,
1368-
max_length=max_length,
1369-
)
1344+
yield from self.successors(input_str, strict=strict, reverse=True, key=key)
13701345

13711346
def successor(
13721347
self,
13731348
input_str: Optional[str],
13741349
*,
13751350
strict: bool = True,
13761351
key: Optional[Callable[[Any], Any]] = None,
1377-
min_length: int = 0,
1378-
max_length: Optional[int] = None,
13791352
) -> Optional[str]:
13801353
"""
13811354
Returns the first string accepted by the DFA that comes after
@@ -1391,23 +1364,13 @@ def successor(
13911364
key : Optional[Callable], default: None
13921365
Function for defining custom lexicographical ordering. Defaults to using
13931366
the standard string ordering.
1394-
min_length : int, default: 0
1395-
Limits generation to words with at least the given length.
1396-
max_length : Optional[int], default: None
1397-
Limits generation to words with at most the given length.
13981367
13991368
Returns
14001369
------
14011370
str
14021371
The first string accepted by the DFA lexicographically before input_string.
14031372
"""
1404-
for word in self.successors(
1405-
input_str,
1406-
strict=strict,
1407-
key=key,
1408-
min_length=min_length,
1409-
max_length=max_length,
1410-
):
1373+
for word in self.successors(input_str, strict=strict, key=key):
14111374
return word
14121375
return None
14131376

@@ -1418,8 +1381,6 @@ def successors(
14181381
strict: bool = True,
14191382
key: Optional[Callable[[Any], Any]] = None,
14201383
reverse: bool = False,
1421-
min_length: int = 0,
1422-
max_length: Optional[int] = None,
14231384
) -> Generator[str, None, None]:
14241385
"""
14251386
Generates all strings that come after the input string
@@ -1437,10 +1398,6 @@ def successors(
14371398
the standard string ordering.
14381399
reverse : bool, default: False
14391400
If True, then predecessors will be generated instead of successors.
1440-
min_length : int, default: 0
1441-
Limits generation to words with at least the given length.
1442-
max_length : Optional[int], default: None
1443-
Limits generation to words with at most the given length.
14441401
14451402
Returns
14461403
------
@@ -1489,8 +1446,6 @@ def successors(
14891446
if (
14901447
not reverse
14911448
and should_yield
1492-
and min_length <= len(char_stack)
1493-
and (max_length is None or len(char_stack) <= max_length)
14941449
and candidate == first_symbol
14951450
and state in self.final_states
14961451
):
@@ -1501,9 +1456,7 @@ def successors(
15011456
else self._get_next_current_state(state, candidate)
15021457
)
15031458
# Traverse to child if candidate is viable
1504-
if candidate_state in coaccessible_nodes and (
1505-
max_length is None or len(char_stack) < max_length
1506-
):
1459+
if candidate_state in coaccessible_nodes:
15071460
state_stack.append(candidate_state)
15081461
char_stack.append(cast(str, candidate))
15091462
candidate = first_symbol
@@ -1512,8 +1465,6 @@ def successors(
15121465
if (
15131466
reverse
15141467
and should_yield
1515-
and min_length <= len(char_stack)
1516-
and (max_length is None or len(char_stack) <= max_length)
15171468
and candidate is None
15181469
and state in self.final_states
15191470
):
@@ -1529,8 +1480,6 @@ def successors(
15291480
if (
15301481
reverse
15311482
and should_yield
1532-
and min_length <= len(char_stack)
1533-
and (max_length is None or len(char_stack) <= max_length)
15341483
and candidate is None
15351484
and state in self.final_states
15361485
):

tests/test_dfa.py

-11
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,6 @@ def test_predecessor(self, as_partial: bool) -> None:
18361836
actual = list(dfa.predecessors("010", strict=False))
18371837

18381838
self.assertEqual(dfa.predecessor("000"), "00")
1839-
self.assertEqual(dfa.predecessor("000", max_length=1), "0")
1840-
self.assertEqual(dfa.predecessor("0", min_length=2), None)
1841-
self.assertEqual(dfa.predecessor("0000", min_length=2, max_length=3), "000")
18421839
self.assertEqual(dfa.predecessor("0100"), "010")
18431840
self.assertEqual(dfa.predecessor("1"), "010101111111101011010100")
18441841
self.assertEqual(
@@ -1875,10 +1872,6 @@ def test_successor(self, as_partial: bool) -> None:
18751872
self.assertIsNone(dfa.successor("110"))
18761873
self.assertIsNone(dfa.successor("111111110101011"))
18771874

1878-
self.assertEqual(dfa.successor("", min_length=3), "000")
1879-
self.assertEqual(dfa.successor("", min_length=4), "010101111111101011010100")
1880-
self.assertEqual(dfa.successor("010", max_length=6), "100")
1881-
18821875
infinite_dfa = DFA.from_nfa(NFA.from_regex("0*1*"))
18831876
self.assertEqual(infinite_dfa.successor(""), "0")
18841877
self.assertEqual(infinite_dfa.successor("0"), "00")
@@ -1889,10 +1882,6 @@ def test_successor(self, as_partial: bool) -> None:
18891882
self.assertEqual(infinite_dfa.successor("1"), "11")
18901883
self.assertEqual(infinite_dfa.successor(100 * "0"), 101 * "0")
18911884
self.assertEqual(infinite_dfa.successor(100 * "1"), 101 * "1")
1892-
self.assertEqual(infinite_dfa.successor("", min_length=5), "00000")
1893-
self.assertEqual(infinite_dfa.successor("000", min_length=5), "00000")
1894-
self.assertEqual(infinite_dfa.successor("1", min_length=5), "11111")
1895-
self.assertEqual(infinite_dfa.successor("1111", max_length=4), None)
18961885

18971886
@params(True, False)
18981887
def test_successor_and_predecessor(self, as_partial: bool) -> None:

0 commit comments

Comments
 (0)