Sets

The galactic.algebras.set module defines several set classes.

class FIFOSet(*args: Iterable[galactic.algebras.set._main._T])

The FIFOSet is a kind of set that remembers the order of its entries.

Examples

>>> from galactic.algebras.set import FIFOSet
>>> a = FIFOSet[int]([3, 5, 1, 2, 6, 2])
>>> list(a)
[3, 5, 1, 2, 6]
>>> list(a | FIFOSet[int]([1, 5, 7 ,8, 9]))
[3, 5, 1, 2, 6, 7, 8, 9]
__init__(*args: Iterable[galactic.algebras.set._main._T]) None

Initialise a FIFOSet instance.

The initializer can take 0 or 1 argument that should be iterable.

Raises:
  • TypeError – If two or more arguments are given.

  • TypeError – If the argument is not iterable.

add(value: galactic.algebras.set._main._T, last: bool = True) None

Add value to the set.

Parameters:
  • value (_T) – The value to add.

  • last (bool) – Where to add.

clear() None

Clear the FIFOSet.

discard(value: galactic.algebras.set._main._T) None

Discard value from the set if it is present.

Parameters:

value (_T) – The value to remove.

isdisjoint(other)

Return True if two sets have a null intersection.

move_to_end(value: galactic.algebras.set._main._T, last: bool = True) None

Move an existing value to either end of a FIFOSet.

The value is moved to the right end if last is True (the default) or to the beginning if last is False.

Parameters:
  • value (_T) – The value to move

  • last (bool) – Where to move

Raises:

KeyError – if the value does not exist.

pop(last: bool = False) galactic.algebras.set._main._T

Remove and return an existing value from either end of a FIFOSet.

Returns:

The value removed.

Return type:

_T

Parameters:

last (bool) – Where to remove

Raises:

KeyError – if the FIFOSet is empty.

remove(value: galactic.algebras.set._main._T) None

Remove value from the set if it is present.

Parameters:

value (_T) – The value to remove.

Raises:

KeyError – if the value does not exist.

class FIFOSetFactory(*args, **kwds)

The FIFOSetFactory class provides a _from_iterable() class methods.

This method is used by builtin set classes when set operations are executed.

class IterableSet(*args, **kwds)

The IterableSet class implements some basic operations.

This allow sub-classes to only implement the __iter__() method.

isdisjoint(other)

Return True if two sets have a null intersection.