def _bfs_sort(self, start):
        """
        maintain a map of states distance using BFS
        Args:
            start (fst state): The initial DFA state
        Returns:
            list: An ordered list of DFA states
                  using path distance
        """
        pathstates = {}
        # maintain a queue of nodes to be visited. Both current and previous
        # node must be included.
        queue = []
        # push the first path into the queue
        queue.append([0, start])
        pathstates[start.stateid] = 0
        while queue:
            # get the first node from the queue
            leaf = queue.pop(0)
            node = leaf[1]
            pathlen = leaf[0]
            # enumerate all adjacent nodes, construct a new path and push it
            # into the queue
            for arc in node.arcs:
                next_state = self.mma[arc.nextstate]
                if next_state.stateid not in pathstates:
                    queue.append([pathlen + 1, next_state])
                    pathstates[next_state.stateid] = pathlen + 1
        orderedstatesdict = OrderedDict(
            sorted(
                pathstates.items(),
                key=lambda x: x[1],
                reverse=False))
        for state in self.mma.states:
            orderedstatesdict[state.stateid] = state
        orderedstates = [x[1] for x in list(orderedstatesdict.items())]
        return orderedstates
def _bfs_sort ( self , start ) : pathstates = { } queue = [ ] queue . append ( [ 0 , start ] ) pathstates [ start . stateid ] = 0 while queue : leaf = queue . pop ( 0 ) node = leaf [ 1 ] pathlen = leaf [ 0 ] for arc in node . arcs : next_state = self . mma [ arc . nextstate ] if next_state . stateid not in pathstates : queue . append ( [ pathlen + 1 , next_state ] ) pathstates [ next_state . stateid ] = pathlen + 1 orderedstatesdict = OrderedDict ( sorted ( pathstates . items ( ) , key = lambda x : x [ 1 ] , reverse = False ) ) for state in self . mma . states : orderedstatesdict [ state . stateid ] = state orderedstates = [ x [ 1 ] for x in list ( orderedstatesdict . items ( ) ) ] return orderedstates
maintain a map of states distance using BFS
        Args:
            start (fst state): The initial DFA state
        Returns:
            list: An ordered list of DFA states
                  using path distance