/** * Percolates the object at position <empy>i</code> * in this heap down into the correct position. * * @param integer $i The position of the object to be percolated down. * @param integer $length The length of the heap. */ protected function percolateDown($i, $length) { while (2 * $i <= $length) { $j = 2 * $i; if ($j < $length && gt($this->array[$j + 1], $this->array[$j])) { $j = $j + 1; } if (ge($this->array[$i], $this->array[$j])) { break; } $this->swap($i, $j); $i = $j; } }
/** * Sorts the array of comparable objects. */ protected function doSort() { for ($i = 1; $i < $this->n; ++$i) { $tmp = $this->array[$i]; $left = 0; $right = $i; while ($left < $right) { $middle = intval(($left + $right) / 2); if (ge($tmp, $this->array[$middle])) { $left = $middle + 1; } else { $right = $middle; } } for ($j = $i; $j > $left; --$j) { $this->swap($j - 1, $j); } } }
/** * Dequeues and returns the "largest" object in this deap. * The largest object in this deap is the object * which is larger than or equal to all other objects in this deap. * * @return object IComparable The "largest" object in this deap. */ public function dequeueMax() { if ($this->count == 0) { throw new ContainerEmptyException(); } if ($this->count == 1) { --$this->count; return $this->array[2]; } elseif ($this->count == 2) { --$this->count; return $this->array[3]; } else { $result = $this->array[3]; $last = $this->array[$this->count + 1]; --$this->count; $i = 3; while (2 * $i < $this->count + 2) { $child = 2 * $i; if ($child + 1 < $this->count + 2 && gt($this->array[$child + 1], $this->array[$child])) { $child += 1; } $this->array[$i] = $this->array[$child]; $i = $child; } $j = $this->dual($i); if (ge($last, $this->array[$j])) { $this->insertMax($i, $last); } else { $this->array[$i] = $this->array[$j]; $this->insertMin($j, $last); } return $result; } }
public function ge($other) { return ge($this, $other); }
public function findElement($obj) { for ($ptr = $this->list->getHead(); $ptr !== NULL; $ptr = $ptr->getNext()) { if (ge($ptr->getDatum(), $obj)) { return $ptr; } } return NULL; }
public function ge($column, $value) { $this->model->setCondition(ge($column, $value)); return $this; }