1
0
Fork 0

Add documentation to RuleWatchChain and RuleWatchNode

pull/715/head
Nils Adermann 2012-05-21 18:26:18 +02:00
parent 76d3950992
commit 7f9c5ffeef
2 changed files with 50 additions and 1 deletions

View File

@ -13,18 +13,36 @@
namespace Composer\DependencyResolver;
/**
* An extension of SplDoublyLinkedList with seek and removal of current element
*
* SplDoublyLinkedList only allows deleting a particular offset and has no
* method to set the internal iterator to a particular offset.
*
* @author Nils Adermann <naderman@naderman.de>
*/
class RuleWatchChain extends \SplDoublyLinkedList
{
protected $offset = 0;
/**
* Moves the internal iterator to the specified offset
*
* @param int $offset The offset to seek to.
*/
public function seek($offset)
{
$this->rewind();
for ($i = 0; $i < $offset; $i++, $this->next());
}
/**
* Removes the current element from the list
*
* As SplDoublyLinkedList only allows deleting a particular offset and
* incorrectly sets the internal iterator if you delete the current value
* this method sets the internal iterator back to the following element
* using the seek method.
*/
public function remove()
{
$offset = $this->key();

View File

@ -13,6 +13,10 @@
namespace Composer\DependencyResolver;
/**
* Wrapper around a Rule which keeps track of the two literals it watches
*
* Used by RuleWatchGraph to store rules in two RuleWatchChains.
*
* @author Nils Adermann <naderman@naderman.de>
*/
class RuleWatchNode
@ -22,6 +26,11 @@ class RuleWatchNode
protected $rule;
/**
* Creates a new node watching the first and second literals of the rule.
*
* @param Rule $rule The rule to wrap
*/
public function __construct($rule)
{
$this->rule = $rule;
@ -33,7 +42,12 @@ class RuleWatchNode
}
/**
* Put watch2 on rule's literal with highest level
* Places the second watch on the rule's literal, decided at the highest level
*
* Useful for learned rules where the literal for the highest rule is most
* likely to quickly lead to further decisions.
*
* @param SplFixedArray $decisionMap A package to decision lookup table
*/
public function watch2OnHighest($decisionMap)
{
@ -56,11 +70,22 @@ class RuleWatchNode
}
}
/**
* Returns the rule this node wraps
*
* @return Rule
*/
public function getRule()
{
return $this->rule;
}
/**
* Given one watched literal, this method returns the other watched literal
*
* @param int The watched literal that should not be returned
* @return int A literal
*/
public function getOtherWatch($literal)
{
if ($this->watch1 == $literal) {
@ -70,6 +95,12 @@ class RuleWatchNode
}
}
/**
* Moves a watch from one literal to another
*
* @param int $from The previously watched literal
* @param int $to The literal to be watched now
*/
public function moveWatch($from, $to)
{
if ($this->watch1 == $from) {