mstar.utils.containers#

Small generic containers with no engine or worker knowledge

Classes

ParallelList(keys, values)

Struct-of-arrays pairing, so a batch crosses a language boundary as two flat lists instead of a dict of objects.

RecentSet(maxlen)

Set of the maxlen most recently added items: O(1) add / in, FIFO eviction.

class mstar.utils.containers.ParallelList(keys, values)[source]#

Bases: NamedTuple, Generic[TK, TV]

Struct-of-arrays pairing, so a batch crosses a language boundary as two flat lists instead of a dict of objects.

Two sharp edges come from the field names plus the custom __iter__:

  • dict(pl) does NOT work. dict probes for a .keys() method to decide whether it was handed a mapping; here keys is a list attribute, so it raises 'list' object is not callable. Use dict(iter(pl)).

  • k, v = pl does not give the two lists – see __iter__.

Parameters:
classmethod from_dict(d)[source]#
Parameters:

d (dict[TK, TV])

Return type:

ParallelList[TK, TV]

keys: list[TK]#

Alias for field number 0

values: list[TV]#

Alias for field number 1

class mstar.utils.containers.RecentSet(maxlen)[source]#

Bases: Generic[T]

Set of the maxlen most recently added items: O(1) add / in, FIFO eviction. Readding a present item is a no-op (age not refreshed).

Parameters:

maxlen (int)

add(item)[source]#
Parameters:

item (T)

Return type:

None

maxlen#