Skip to content
campadrenalin edited this page Sep 14, 2011 · 4 revisions

ConcurrenTree.model.instruction

Instruction

A subclass of ConcurrenTree.model.ModelBase, which provides the function __str__ and the property hash, which are a strict string of the protocol representation and the checksum of the protocol representation, respectively.

The base class of all instructions, defines mostly placeholder functions that raise NotImplementedErrors when the subclass doesn't override them and someone tries to call them.

Methods:
* apply(tree, address=None) # Apply instruction to a tree, optionally overriding the address
* sanitycheck(tree) # Raise exception if this instruction cannot be applied. Override required.
* _apply(tree) # Does the actual class-dependent application algorithm. Override required.
* proto() # Return protocol representation (list). Override required.

Properties:
* address_object # is root node if self.address is not set
* address # optional

Insertion

Subclass of instruction, overriding sanitycheck, _apply, and proto, as well as providing an init function. Yes, the base class leaves that totally up to subclasses.

As the name would imply, Insertion instructions create subnodes off of existing nodes, one per instruction.

Methods:
* __init__(self, address, position, value) # Creates a subnode from the node addressed, at index "position", with value "value"

Deletion

Another subclass of Instruction, overriding the same functions. Deletes a range of characters from a single node. Note that a deletion instruction in the protocol will result in one or more deletion instructions in the library, because the protocol version is more flexible, and it may take multiple library instructions to perform the same result in complex cases.

Methods:
* __init__(self, address, range) # Deletes from the node addressed. Range may be an int, or tuple of two ints.

Functions

validatepos(tree, pos)

Tests a node index for existing in the node, raising an IndexError otherwise. Used in the sanitycheck functions of Insertion and Deletion.

set(array)

Takes a list of protocol instructions, returns a list of library instructions, using the deproto function.

deproto(instr)

Turns a protocol instruction into one or more library instructions. instr must be either a library instruction already, or a protocol instruction in list form.

Python Library

Clone this wiki locally