def reltags(self, src, cache=None): ''' returns all the tags that are relevant at this state cache should be a dictionary and it is updated by the function ''' if not self._tag_assocs: return set() # f*****g python and it's terrible support for recursion makes this # far more complicated than it needs to be if cache == None: cache = {} q = _otq() q.append(src) updateq = _otq() while q: i = q.popleft() if i in cache: continue cache[i] = set() for (s, t) in self.transitions_to(i): q.append(s) if self.is_tagged(t, s, i): cache[i].add((self.tag(t, s, i), s, i)) updateq.appendleft((i, s)) while updateq: i = updateq.popleft() cache[i[0]].update(cache[i[1]]) return cache[src]
def reltags(self, src, cache=None): ''' returns all the tags that are relevant at this state cache should be a dictionary and it is updated by the function ''' if not self._tag_assocs: return set() # f*****g python and it's terrible support for recursion makes this # far more complicated than it needs to be if cache == None: cache = {} q = _otq() q.append(src) updateq = _otq() while q: i = q.popleft() if i in cache: continue cache[i] = set() for (s,t) in self.transitions_to(i): q.append(s) if self.is_tagged(t,s,i): cache[i].add((self.tag(t,s,i),s, i)) updateq.appendleft((i, s)) while updateq: i = updateq.popleft() cache[i[0]].update(cache[i[1]]) return cache[src]
def _add_epsilon_states(self, stateset, gathered_epsilons): ''' stateset is the list of initial states gathered_epsilons is a dictionary of (dst: src) epsilon dictionaries ''' for i in list(stateset): if i not in gathered_epsilons: gathered_epsilons[i] = {} q = _otq() q.append(i) while q: s = q.popleft() for j in self._transitions.setdefault(s, {}).setdefault(NFA.EPSILON, set()): gathered_epsilons[i][j] = s if j not in gathered_epsilons[i] else self.choose(s, j) q.append(j) stateset.update(gathered_epsilons[i].keys())
def _add_epsilon_states(self, stateset, gathered_epsilons): ''' stateset is the list of initial states gathered_epsilons is a dictionary of (dst: src) epsilon dictionaries ''' for i in list(stateset): if i not in gathered_epsilons: gathered_epsilons[i] = {} q = _otq() q.append(i) while q: s = q.popleft() for j in self._transitions.setdefault(s, {}).setdefault( NFA.EPSILON, set()): gathered_epsilons[i][ j] = s if j not in gathered_epsilons[ i] else self.choose(s, j) q.append(j) stateset.update(gathered_epsilons[i].keys())