Coverage for /home/marcofavorito/workfolder/pythomata/pythomata/_internal_utils.py : 67%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""Internal utility functions, not supposed to be used by the users."""
3from copy import deepcopy
4from typing import Set, Callable, Any, Iterable
7def least_fixpoint(starting_set: Set, step: Callable[[Set], Iterable]) -> Set:
8 """Do a least fixpoint algorithm."""
9 z_current = None
10 z_next = starting_set
12 while z_current != z_next:
13 z_current = z_next
14 z_next = deepcopy(z_current)
15 z_next = z_next.union(step(z_current))
17 return z_current if z_current is not None else set()
20def greatest_fixpoint(starting_set: Set, condition: Callable[[Any, Set], bool]) -> Set:
21 """Do a greatest fixpoint algorithm."""
22 z_current = None
23 z_next = starting_set
25 while z_current != z_next:
26 z_current = z_next
27 z_next = deepcopy(z_current)
29 for e in z_current:
30 if condition(e, z_current):
31 z_next.remove(e)
33 return z_current if z_current is not None else set()