1
0
Fork 0

Make decisions countable and use foreach to iterate them in solver

pull/779/head
Nils Adermann 2012-06-06 15:39:41 +02:00
parent bc7e983b1e
commit 2fbc04b950
2 changed files with 7 additions and 12 deletions

View File

@ -17,7 +17,7 @@ namespace Composer\DependencyResolver;
* *
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
*/ */
class Decisions implements \Iterator class Decisions implements \Iterator, \Countable
{ {
const DECISION_LITERAL = 0; const DECISION_LITERAL = 0;
const DECISION_REASON = 1; const DECISION_REASON = 1;
@ -178,9 +178,9 @@ class Decisions implements \Iterator
array_pop($this->decisionQueue); array_pop($this->decisionQueue);
} }
public function getMaxOffset() public function count()
{ {
return count($this->decisionQueue) - 1; return count($this->decisionQueue);
} }
public function rewind() public function rewind()

View File

@ -48,7 +48,7 @@ class Solver
// aka solver_makeruledecisions // aka solver_makeruledecisions
private function makeAssertionRuleDecisions() private function makeAssertionRuleDecisions()
{ {
$decisionStart = $this->decisions->getMaxOffset(); $decisionStart = count($this->decisions) - 1;
for ($ruleIndex = 0; $ruleIndex < count($this->rules); $ruleIndex++) { for ($ruleIndex = 0; $ruleIndex < count($this->rules); $ruleIndex++) {
$rule = $this->rules->ruleById($ruleIndex); $rule = $this->rules->ruleById($ruleIndex);
@ -242,7 +242,7 @@ class Solver
} }
$this->decisions->revertLast(); $this->decisions->revertLast();
$this->propagateIndex = $this->decisions->getMaxOffset() + 1; $this->propagateIndex = count($this->decisions);
} }
while (!empty($this->branches)) { while (!empty($this->branches)) {
@ -343,7 +343,7 @@ class Solver
$seen = array(); $seen = array();
$learnedLiterals = array(null); $learnedLiterals = array(null);
$decisionId = $this->decisions->getMaxOffset() + 1; $decisionId = count($this->decisions);
$this->learnedPool[] = array(); $this->learnedPool[] = array();
@ -483,12 +483,7 @@ class Solver
$seen[abs($literal)] = true; $seen[abs($literal)] = true;
} }
$decisionId = $this->decisions->getMaxOffset() + 1; foreach ($this->decisions as $decision) {
while ($decisionId > 0) {
$decisionId--;
$decision = $this->decisions->atOffset($decisionId);
$literal = $decision[Decisions::DECISION_LITERAL]; $literal = $decision[Decisions::DECISION_LITERAL];
// skip literals that are not in this rule // skip literals that are not in this rule