-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordering.py
More file actions
25 lines (17 loc) · 705 Bytes
/
Copy pathordering.py
File metadata and controls
25 lines (17 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Deterministic ordering checks for replay sequences."""
from __future__ import annotations
from collections.abc import Iterable, Sequence
Edge = tuple[str, str]
def find_order_violations(
sequence: Sequence[str],
required_before: Iterable[Edge],
) -> tuple[Edge, ...]:
"""Return lexicographically sorted order violations."""
positions = {node: index for index, node in enumerate(sequence)}
violations: set[Edge] = set()
for before, after in required_before:
if before not in positions or after not in positions:
continue
if positions[before] > positions[after]:
violations.add((before, after))
return tuple(sorted(violations))