sc3nb.sc_objects.allocators

Classes for managing ID allocations.

Module Contents

Class List

Allocator

Helper class that provides a standard way to create an ABC using

NodeAllocator

Allows allocating ids for Nodes.

BlockAllocator

Allows allocating blocks of ids / indexes

Content

class sc3nb.sc_objects.allocators.Allocator[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Overview:

allocate

free

abstract allocate(num: int = 1) Sequence[int][source]
abstract free(ids: Sequence[int]) None[source]
class sc3nb.sc_objects.allocators.NodeAllocator(client_id: int)[source]

Bases: Allocator

Allows allocating ids for Nodes.

Overview:

allocate

free

allocate(num: int = 1) Sequence[int][source]
free(ids: Sequence[int]) None[source]
class sc3nb.sc_objects.allocators.BlockAllocator(num_ids: int, offset: int)[source]

Bases: Allocator

Allows allocating blocks of ids / indexes

Overview:

allocate

Allocate the next free ids

free

Mark ids as free again.

allocate(num: int = 1) Sequence[int][source]

Allocate the next free ids

Returns:
int

free ids

Raises:
RuntimeError

When out of free ids or not enough ids are in order.

free(ids: Sequence[int]) None[source]

Mark ids as free again.

Parameters:
idssequence of int

ids that are not used anymore.