Saturday, January 7, 2012

Row operations

A row operation (also known as rowop) in Triceps is an unit of work for a label. It's always destined for a particular label (which could also pass it to its chained labels), and has a row to process and an opcode. The defined opcodes are:


A row operation is constructed as:

$rowop = $label->makeRowop($opcode, $row);

The opcode may be specified as a Triceps constant or as one of the strings "OP_NOP", "OP_INSERT", "OP_DELETE". Historically, there is also an optional extra argument for enqueuing mode but it's already obsolete.

Since the labels are single-threaded, the rowops are single-threaded too. The rowops are immutable, just as the rows are.

The references to rowops can be compared as usual


returns true if both point to the same rowop object.

The rowop data can be extracted back:

$label = $rowop->getLabel();
$opcode = $rowop->getOpcode();
$row = $rowop->getRow();

A copy of rowop (not just another reference but an honest separate copied object) can be created with

$rowop2 = $rowop1->copy();

However, since the rowops are immutable, a reference is just as good as a copy. This method is historic and will likely be removed or modified.

There also are calls to directly check the meaning of the opcode:


The typical idiom for handling a label is:

if ($rowop->isInsert()) {
  # handle the insert logic ...
} elsif($rowop->isDelete()) {
  # handle the delete logic...

The NOPs get silently ignored in this idiom, as they should be. Generally there is no point in creation of the rowops with NOP opcode, unless you want to use them for some weird logic.

The main Triceps package also provides functions to check the extracted opcodes:


The same-named methods of Rowop are just the more convenient and efficient ways to say


The functions to convert between the opcode integer values and strings are

$opcode = &Triceps::stringOpcode($opcodeName);
$opcodeName = &Triceps::opcodeString($opcode); 

A Rowop can be printed (usually for debugging purposes) with

$string = $rowop->printP(); 

Just as with a row, printP() means that it's implemented in Perl. In the future a print() done right in C++ may be added, but for now I try to keep all the interpretation of the data on the Perl side. The following example gives an idea of the format in which the rowops get printed:

$lb = $unit->makeDummyLabel($rt, "lb");
$rowop = $lb->makeRowop(&Triceps::OP_INSERT, $row);
print $rowop->printP(), "\n";

would produce

lb OP_INSERT a="123" b="456" c="3000000000000000" d="3.14" e="text" 

The row contents is printed through Row::printP(), so it has the same format.

No comments:

Post a Comment