@@ -338,7 +338,7 @@ def minify(self, retain_names: bool = False) -> DFA:
338
338
"""
339
339
340
340
# Compute reachable states and final states
341
- bfs_states = DFA ._bfs_states (
341
+ bfs_states = self . __class__ ._bfs_states (
342
342
self .initial_state , lambda state : iter (self .transitions [state ].items ())
343
343
)
344
344
reachable_states = {* bfs_states }
@@ -456,7 +456,7 @@ def union_function(state_pair: Tuple[DFAStateT, DFAStateT]) -> bool:
456
456
q_a , q_b = state_pair
457
457
return q_a in self .final_states or q_b in other .final_states
458
458
459
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
459
+ initial_state , expand_state_fn = self . __class__ ._cross_product (self , other )
460
460
461
461
return self .__class__ ._expand_dfa (
462
462
union_function ,
@@ -480,7 +480,7 @@ def intersection_function(state_pair: Tuple[DFAStateT, DFAStateT]) -> bool:
480
480
q_a , q_b = state_pair
481
481
return q_a in self .final_states and q_b in other .final_states
482
482
483
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
483
+ initial_state , expand_state_fn = self . __class__ ._cross_product (self , other )
484
484
485
485
return self .__class__ ._expand_dfa (
486
486
intersection_function ,
@@ -504,7 +504,7 @@ def difference_function(state_pair: Tuple[DFAStateT, DFAStateT]) -> bool:
504
504
q_a , q_b = state_pair
505
505
return q_a in self .final_states and q_b not in other .final_states
506
506
507
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
507
+ initial_state , expand_state_fn = self . __class__ ._cross_product (self , other )
508
508
509
509
return self .__class__ ._expand_dfa (
510
510
difference_function ,
@@ -530,7 +530,7 @@ def symmetric_difference_function(
530
530
q_a , q_b = state_pair
531
531
return (q_a in self .final_states ) ^ (q_b in other .final_states )
532
532
533
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
533
+ initial_state , expand_state_fn = self . __class__ ._cross_product (self , other )
534
534
535
535
return self .__class__ ._expand_dfa (
536
536
symmetric_difference_function ,
@@ -545,7 +545,7 @@ def complement(self, *, retain_names: bool = False, minify: bool = True) -> DFA:
545
545
"""Return the complement of this DFA."""
546
546
547
547
if minify :
548
- bfs_states = DFA ._bfs_states (
548
+ bfs_states = self . __class__ ._bfs_states (
549
549
self .initial_state , lambda state : iter (self .transitions [state ].items ())
550
550
)
551
551
reachable_states = {* bfs_states }
@@ -612,8 +612,9 @@ def _bfs_states(
612
612
visited_set .add (tgt_state )
613
613
queue .append (tgt_state )
614
614
615
- @staticmethod
615
+ @classmethod
616
616
def _expand_dfa (
617
+ cls ,
617
618
final_state_fn : IsFinalStateFn ,
618
619
initial_state : DFAStateT ,
619
620
expand_state_fn : ExpandStateFn ,
@@ -645,7 +646,7 @@ def get_name_original(state):
645
646
states = {initial_state_name }
646
647
final_states = {initial_state_name } if final_state_fn (initial_state ) else set ()
647
648
648
- for cur_state , chr , tgt_state in DFA ._bfs_edges (initial_state , expand_state_fn ):
649
+ for cur_state , chr , tgt_state in cls ._bfs_edges (initial_state , expand_state_fn ):
649
650
cur_state_name = get_name (cur_state )
650
651
tgt_state_name = get_name (tgt_state )
651
652
@@ -660,7 +661,7 @@ def get_name_original(state):
660
661
661
662
if minify :
662
663
# From the construction, the states/final states are reachable
663
- return DFA ._minify (
664
+ return cls ._minify (
664
665
reachable_states = states ,
665
666
input_symbols = input_symbols ,
666
667
transitions = transitions ,
@@ -676,8 +677,9 @@ def get_name_original(state):
676
677
final_states = final_states ,
677
678
)
678
679
679
- @staticmethod
680
+ @classmethod
680
681
def _find_state (
682
+ cls ,
681
683
target_state_fn : TargetStateFn ,
682
684
initial_state : DFAStateT ,
683
685
expand_state_fn : ExpandStateFn ,
@@ -688,7 +690,7 @@ def _find_state(
688
690
searched for. The expand_state_fn should return an iterator with the
689
691
successors of each state in the product.
690
692
"""
691
- bfs_states = DFA ._bfs_states (initial_state , expand_state_fn )
693
+ bfs_states = cls ._bfs_states (initial_state , expand_state_fn )
692
694
return any (target_state_fn (state ) for state in bfs_states )
693
695
694
696
@staticmethod
@@ -718,8 +720,10 @@ def subset_state_fn(state_pair: Tuple[DFAStateT, DFAStateT]) -> bool:
718
720
q_a , q_b = state_pair
719
721
return q_a in self .final_states and q_b not in other .final_states
720
722
721
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
722
- return not DFA ._find_state (subset_state_fn , initial_state , expand_state_fn )
723
+ initial_state , expand_state_fn = self .__class__ ._cross_product (self , other )
724
+ return not self .__class__ ._find_state (
725
+ subset_state_fn , initial_state , expand_state_fn
726
+ )
723
727
724
728
def issuperset (self , other : DFA ) -> bool :
725
729
"""Return True if this DFA is a superset of another DFA."""
@@ -733,12 +737,14 @@ def disjoint_state_fn(state_pair: Tuple[DFAStateT, DFAStateT]) -> bool:
733
737
q_a , q_b = state_pair
734
738
return q_a in self .final_states and q_b in other .final_states
735
739
736
- initial_state , expand_state_fn = DFA ._cross_product (self , other )
737
- return not DFA ._find_state (disjoint_state_fn , initial_state , expand_state_fn )
740
+ initial_state , expand_state_fn = self .__class__ ._cross_product (self , other )
741
+ return not self .__class__ ._find_state (
742
+ disjoint_state_fn , initial_state , expand_state_fn
743
+ )
738
744
739
745
def isempty (self ) -> bool :
740
746
"""Return True if this DFA is completely empty."""
741
- return not DFA ._find_state (
747
+ return not self . __class__ ._find_state (
742
748
lambda state : state in self .final_states ,
743
749
self .initial_state ,
744
750
lambda state : iter (self .transitions [state ].items ()),
@@ -1376,7 +1382,7 @@ def from_finite_language(
1376
1382
SignatureT = Tuple [bool , FrozenSet [Tuple [str , str ]]]
1377
1383
1378
1384
if not language :
1379
- return DFA .empty_language (input_symbols )
1385
+ return cls .empty_language (input_symbols )
1380
1386
1381
1387
transitions : Dict [DFAStateT , Dict [str , DFAStateT ]] = {}
1382
1388
back_map : Dict [str , Set [str ]] = {"" : set ()}
0 commit comments