system.playground.partitioning module

Toy train-network simulation exploring uniform load partitioning in a DBMS.

class system.playground.partitioning.RailElement[source]

Bases: ABC

A rail element is either a Gate or a Platform. It has an id and can find a reachable platform.

id_counter: int = 0
abstractmethod find_reachable_platform() → Platform[source]

Finds a reachable platform, i.e. this is the platform we end up at if we follow the current positions of the gates recursively.

abstractmethod show(rec_depth: int = 0)[source]

Shows the content of this element.

class system.playground.partitioning.Gate(left: RailElement = None, right: RailElement = None)[source]

Bases: RailElement

A gate has a position (“left” or “right”) and two children RailElements (left and right).

switch()[source]

Switches the position of the gate.

find_reachable_platform() → Platform[source]

Follows the current position into the corresponding child.

Returns:

the platform reached by recursing into the left or right child according to this gate’s current position.

show(rec_depth: int = 0)[source]

Prints this gate, then recursively both children one level deeper.

Parameters:

rec_depth – indentation depth in tab stops for this gate.

class system.playground.partitioning.Platform(visit_counter: int = 0)[source]

Bases: RailElement

A platform has a counter that is increased every time a train visits it.

find_reachable_platform() → Platform[source]

Returns self.

increase_visit_counter()[source]

Increases the visit counter by one.

show(rec_depth: int = 0)[source]

Prints this platform.

Parameters:

rec_depth – indentation depth in tab stops for this platform.

class system.playground.partitioning.GateTree(number_of_gate_levels: int)[source]

Bases: object

A complete binary tree of gates (inner nodes) and platforms (leaves).

The tree has number_of_gate_levels levels of gates and therefore 2 ** number_of_gate_levels platforms as leaves. Flat lists of all gates and all platforms are kept alongside the root for random access.

show()[source]

Prints the whole tree starting at the root.

find_reachable_platform() → Platform[source]

Follows the current gate positions from the root.

Returns:

the platform reached from the root given the gates’ positions.