Skip to content
campadrenalin edited this page Feb 15, 2012 · 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.

A single atomic modification instruction for CTree nodes, consisting of an address and an instruction type at the very least, and often containing additional information.

Methods:
* apply(node) # Apply instruction to a node
* fromother(inst) # Sets properties based on another instruction
* fromproto(list) # Sets properties based on a protocol rep of an instruction
* sanitycheck(node) # Raise exception if this instruction cannot be applied.
* proto() # Return protocol representation (list).

Properties:
* code # Integer representing instruction type
* address # Address of the node this instruction will affect
* deletions # List of deletion positions and ranges for deletion instructions
* isinsert # Boolean. If it's not an insert, it's a delete
* position # Position for insertions
* value # Same as the "value" property in the protocol rep
* value_node # A node based on self.value

Functions

Delete(addr, *positions)

Creates an Instruction that deletes the given positions in a node.

[0, addr, pos0, pos1 ... posN]

InsertText(addr, pos, value)

Inserts text as a child to the given node, at position pos and with contents value.

[1, addr, pos, value]

InsertMap(addr, pos)

Inserts a blank map as the child of the given node at position pos.

[2, addr, pos]

InsertList(addr, pos, value)

Inserts a list as a child to the given node, at position pos and with contents value. Inserting ListA into ListB, where ListB is the parent, has the effect of adding the contents of ListA to the flat representation of ListB at the given position. Inceptioning the lists to get a literal one can break your brain if you're not careful, let the library do it.

[3, addr, pos, value]

InsertNumber(addr, pos, value, unique)

NumberNodes require a "unique" variable to prevent unintended merges. As long as different users use different uniques for their numbers, no increment collisions will happen. The unique can be any 32-bit int.

[4, addr, pos, value, unique]

InsertSingle(addr, pos)

SingleNodes have no immutable value.

[5, addr, pos]

InsertTrinary(addr, pos, value)

True, False, and None.

[6, addr, pos, value, unique]

InsertNode(addr, pos, node)

Takes an existing library node, and where it's supposed to be inserted, and returns the result of the appropriate Insert* function.

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.

Python Library

Clone this wiki locally