Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
jan | 8e8fee5238 | 2 months ago |
jan | ee2ee955eb | 2 months ago |
jan | d814f3372d | 2 months ago |
jan | 70a9c2a8ef | 2 months ago |
jan | 1b07a50e4a | 2 months ago |
jan | 38ccc3ebab | 2 months ago |
jan | b46c1bd2a6 | 2 months ago |
jan | aec708db33 | 2 months ago |
@ -0,0 +1,106 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from .types import annotations_t, layer_t
|
||||||
|
from ..ports import Port
|
||||||
|
from ..repetition import Repetition
|
||||||
|
|
||||||
|
|
||||||
|
def annotation2key(aaa: int | float | str) -> tuple[bool, Any]:
|
||||||
|
return (isinstance(aaa, str), aaa)
|
||||||
|
|
||||||
|
|
||||||
|
def annotations_lt(aa: annotations_t, bb: annotations_t) -> bool:
|
||||||
|
if aa is None:
|
||||||
|
return bb is not None
|
||||||
|
elif bb is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(aa) != len(bb):
|
||||||
|
return len(aa) < len(bb)
|
||||||
|
|
||||||
|
keys_a = tuple(sorted(aa.keys()))
|
||||||
|
keys_b = tuple(sorted(bb.keys()))
|
||||||
|
if keys_a != keys_b:
|
||||||
|
return keys_a < keys_b
|
||||||
|
|
||||||
|
for key in keys_a:
|
||||||
|
va = aa[key]
|
||||||
|
vb = bb[key]
|
||||||
|
if len(va) != len(vb):
|
||||||
|
return len(va) < len(vb)
|
||||||
|
|
||||||
|
for aaa, bbb in zip(va, vb):
|
||||||
|
if aaa != bbb:
|
||||||
|
return annotation2key(aaa) < annotation2key(bbb)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def annotations_eq(aa: annotations_t, bb: annotations_t) -> bool:
|
||||||
|
if aa is None:
|
||||||
|
return bb is None
|
||||||
|
elif bb is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(aa) != len(bb):
|
||||||
|
return False
|
||||||
|
|
||||||
|
keys_a = tuple(sorted(aa.keys()))
|
||||||
|
keys_b = tuple(sorted(bb.keys()))
|
||||||
|
if keys_a != keys_b:
|
||||||
|
return keys_a < keys_b
|
||||||
|
|
||||||
|
for key in keys_a:
|
||||||
|
va = aa[key]
|
||||||
|
vb = bb[key]
|
||||||
|
if len(va) != len(vb):
|
||||||
|
return False
|
||||||
|
|
||||||
|
for aaa, bbb in zip(va, vb):
|
||||||
|
if aaa != bbb:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def layer2key(layer: layer_t) -> tuple[bool, bool, Any]:
|
||||||
|
is_int = isinstance(layer, int)
|
||||||
|
is_str = isinstance(layer, str)
|
||||||
|
layer_tup = (layer) if (is_str or is_int) else layer
|
||||||
|
tup = (
|
||||||
|
is_str,
|
||||||
|
not is_int,
|
||||||
|
layer_tup,
|
||||||
|
)
|
||||||
|
return tup
|
||||||
|
|
||||||
|
|
||||||
|
def rep2key(repetition: Repetition | None) -> tuple[bool, Repetition | None]:
|
||||||
|
return (repetition is None, repetition)
|
||||||
|
|
||||||
|
|
||||||
|
def ports_eq(aa: dict[str, Port], bb: dict[str, Port]) -> bool:
|
||||||
|
if len(aa) != len(bb):
|
||||||
|
return False
|
||||||
|
|
||||||
|
keys = sorted(aa.keys())
|
||||||
|
if keys != sorted(bb.keys()):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return all(aa[kk] == bb[kk] for kk in keys)
|
||||||
|
|
||||||
|
|
||||||
|
def ports_lt(aa: dict[str, Port], bb: dict[str, Port]) -> bool:
|
||||||
|
if len(aa) != len(bb):
|
||||||
|
return len(aa) < len(bb)
|
||||||
|
|
||||||
|
aa_keys = tuple(sorted(aa.keys()))
|
||||||
|
bb_keys = tuple(sorted(bb.keys()))
|
||||||
|
if aa_keys != bb_keys:
|
||||||
|
return aa_keys < bb_keys
|
||||||
|
|
||||||
|
for key in aa_keys:
|
||||||
|
pa = aa[key]
|
||||||
|
pb = bb[key]
|
||||||
|
if pa != pb:
|
||||||
|
return pa < pb
|
||||||
|
return False
|
Loading…
Reference in New Issue