plastid.util.unique_fifo module

class plastid.util.unique_fifo.UniqueFIFO(size)[source]

Bases: object

FIFO of unique objects. In other words, if an element already present in the FIFO is appended to the FIFO, it is moved to the right end and no element is removed from the FIFO. Elements are only removed when a element not present in the FIFO is appended to the right end, and when the number of elements in the FIFO exceeds self.max_size.

Parameters:
idx : int

Index of item to fetch

Returns:
object

Nth item in the UniqueFIFO

Attributes:
max_size : int

Maximum size of UniqueFIFO

Methods

append(el) Append an item to the UniqueFIFO.
append(el)[source]

Append an item to the UniqueFIFO. If the item is already present in the UniqueFIFO, it is moved to the right end of the FIFO, and the length of the UniqueFIFO is unchanged. Otherwise, the element is appended to the right end. If the length of the UniqueFIFO then exceeds self.max_size, the fist element is popped.

Parameters:
el : hashable

Any hashable object