True if the given sorting conforms to the given partial ordering.
(tuples, sorted_elements)
| 143 | |
| 144 | |
| 145 | def conforms_partial_ordering(tuples, sorted_elements): |
| 146 | """True if the given sorting conforms to the given partial ordering.""" |
| 147 | |
| 148 | deps = defaultdict(set) |
| 149 | for parent, child in tuples: |
| 150 | deps[parent].add(child) |
| 151 | for i, node in enumerate(sorted_elements): |
| 152 | for n in sorted_elements[i:]: |
| 153 | if node in deps[n]: |
| 154 | return False |
| 155 | else: |
| 156 | return True |
| 157 | |
| 158 | |
| 159 | def all_partial_orderings(tuples, elements): |