system.interfaces.queues module

Abstract queue interfaces (read, write, read-write) and the queue factory.

class system.interfaces.queues.ReadQueue[source]

Bases: ABC, Iterator, Generic

ReadQueue is an API for queues you can read data from. This is an Iterator that can directly be used in for-loops.

abstractmethod pop() → ObjectType[source]

Removes and returns the first element of the queue

abstractmethod close() → None[source]

Closes the queue

abstractmethod set_memory_limit(memory_limit: int) → None[source]

Sets the memory limit for the queue. This is useful for queues that are disk-based and can use a buffer in memory to speed up access. If the memory limit is set to 0, the queue should not use any memory buffer.

Parameters:

memory_limit – The memory limit in bytes to use for the queue.

class system.interfaces.queues.WriteQueue[source]

Bases: ABC, Generic

WriteQueue is an API for queues you can write data to.

abstractmethod insert(entry: ObjectType) → None[source]

Inserts an entry into the queue. Corresponds to the add() and put() methods of a container, also next(entry) in a push-based iterator.

abstractmethod flush() → int[source]

Flushes the contents of the queue, e.g. to a file, i.e. writes the contents of the buffer to the file.

Returns:

The number of objects written to the file for this call to flush()

abstractmethod close() → None[source]

Closes the queue and potentially any file(s) backing the queue.

abstractmethod size() → int[source]

Returns the number of elements inserted into this queue so far.

Returns:

The number of elements inserted into this queue so far.

abstractmethod set_memory_limit(memory_limit: int) → None[source]

Sets the memory limit for the queue. This is useful for queues that are disk-based and can use a buffer in memory to speed up access. If the memory limit is set to 0, the queue should not use any memory buffer.

Parameters:

memory_limit – The memory limit in bytes to use for the queue.

class system.interfaces.queues.ReadWriteQueue(memory_limit: int = 10000)[source]

Bases: ReadQueue, WriteQueue, ABC, Generic

ReadWriteQueue is an API for queues that can be read from and can be written to.

reset() → None[source]

Resets the queue to the initial state.

set_memory_limit(memory_limit: int) → None[source]

See WriteQueue.set_memory_limit().

class system.interfaces.queues.QueueFactory[source]

Bases: ABC, Generic

QueueFactory is an abstract factory class to create readwrite queues. You can use this class to create instances of the different queues and in particular to create queues that are either disk or memory based. This allows you to configure queue-based algorithms with different types of code, e.g. run merge sort either in memory or disk or on a key-value store or ….

abstractmethod get_queue_instance() → ReadWriteQueue[source]

Returns a ReadWriteQueue instance.

Returns:

An instance of a subclass of ReadWriteQueue.