cottax.core.frozen.ordered_map module

Frozen ordered mapping.

Order is needed for tiebreaks in networkx algorithms: this requires the order to be stable and part of the equality. Two graphs with different orderings execute differently and thus they shouldn’t hash equivalently.

class OrderedMap[K: Hashable, V](entries: Mapping[K, V] | Iterable[tuple[K, V]] = ())[source]

Bases: Mapping[K, V], Generic[K, V]

A frozen mapping in the order it was written. Two tuples; the lookup table is built on first use and cached, the hash on first call.

keys()[source]
Return type:

tuple[K, ...]

values()[source]
Return type:

tuple[V, ...]

items()[source]
Return type:

tuple[tuple[K, V], ...]

classmethod trusted(keys: tuple[K, ...], values: Iterable[V])[source]

Built without the duplicate check, keys already distinct: a dict’s, or a flatten’s.

Return type:

OrderedMap[K, V]