gigl.common.collections.sorted_dict#

Attributes#

KT

VT

Classes#

SortedDict

A dictionary that maintains sorted order of keys during iteration.

Module Contents#

class gigl.common.collections.sorted_dict.SortedDict(*args, **kwargs)[source]#

Bases: collections.abc.Mapping[KT, VT]

A dictionary that maintains sorted order of keys during iteration.

This class extends the standard dictionary behavior by automatically sorting keys whenever the dictionary is iterated over or represented as a string. The sorting is lazy and only performed when needed for efficiency.

Type Parameters:
KT: The type of keys in the dictionary. Must support comparison operations

(implement __lt__) for sorting to work correctly.

VT: The type of values in the dictionary

Example

>>> sd = SortedDict({'z': 1, 'a': 2, 'b': 3})
>>> list(sd.keys())
['a', 'b', 'z']

Initialize a SortedDict with the same arguments as a standard dict.

Parameters:
  • *args (Any) – Positional arguments passed to dict constructor

  • **kwargs (Any) – Keyword arguments passed to dict constructor

gigl.common.collections.sorted_dict.KT[source]#
gigl.common.collections.sorted_dict.VT[source]#