예제 #1
1
파일: Tree.php 프로젝트: phpml/phpml
 public function addText(SimpleToken $text, $parent = null)
 {
     if ($parent) {
         $parent->addChild($text->getValue());
     } else {
         parent::push($text->getValue());
     }
 }
예제 #2
0
function test(SplDoublyLinkedList $l)
{
    $l->push("a");
    $l->push("b");
    $l->push("c");
    echo "ArrayAccess Unset:", PHP_EOL;
    unset($l[0]);
    var_dump($l[0]);
    echo PHP_EOL;
}
예제 #3
0
파일: ApiGenTest.php 프로젝트: jjok/Robo
 public function testPHPUnitCommand()
 {
     // need an explicit Traversable
     $skippedPaths = new \SplDoublyLinkedList();
     $skippedPaths->push('a');
     $skippedPaths->push('b');
     // going for 'bang for the buck' here re: test converage
     $task = (new \Robo\Task\ApiGen\ApiGen('apigen'))->config('./apigen.neon')->source('src')->extensions('php')->exclude(array('test', 'tmp'))->skipDocPath($skippedPaths)->charset(array('utf8', 'iso88591'))->internal('no')->php(true)->tree('Y')->debug('n');
     $cmd = 'apigen --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset \'utf8,iso88591\' --internal no --php yes --tree yes --debug no';
     verify($task->getCommand())->equals($cmd);
     $task->run();
     $this->apigen->verifyInvoked('executeCommand', [$cmd]);
 }
예제 #4
0
파일: index.php 프로젝트: erackson/samu
function resetCreateGlobalVars()
{
    global $v0, $v1, $v2, $v3, $v4, $v5, $list0, $list1, $list2, $list3, $list4, $list5, $adjacencyList;
    $v0 = new vertex(0);
    $v1 = new vertex(1);
    $v2 = new vertex(2);
    $v3 = new vertex(3);
    $v4 = new vertex(4);
    $v5 = new vertex(5);
    $list0 = new SplDoublyLinkedList();
    $list0->push(array('vertex' => $v1, 'distance' => 3));
    $list0->push(array('vertex' => $v3, 'distance' => 1));
    $list0->rewind();
    $list1 = new SplDoublyLinkedList();
    $list1->push(array('vertex' => $v0, 'distance' => 3));
    $list1->push(array('vertex' => $v2, 'distance' => 7));
    $list1->rewind();
    $list2 = new SplDoublyLinkedList();
    $list2->push(array('vertex' => $v1, 'distance' => 7));
    $list2->push(array('vertex' => $v3, 'distance' => 8));
    $list2->push(array('vertex' => $v4, 'distance' => 12));
    $list2->rewind();
    $list3 = new SplDoublyLinkedList();
    $list3->push(array('vertex' => $v0, 'distance' => 1));
    $list3->push(array('vertex' => $v2, 'distance' => 8));
    $list3->rewind();
    $list4 = new SplDoublyLinkedList();
    $list4->push(array('vertex' => $v2, 'distance' => 12));
    $list4->push(array('vertex' => $v5, 'distance' => 3));
    $list4->rewind();
    $list5 = new SplDoublyLinkedList();
    $list5->push(array('vertex' => $v4, 'distance' => 3));
    $list5->rewind();
    $adjacencyList = array($list0, $list1, $list2, $list3, $list4, $list5);
}
예제 #5
0
 /**
  * Reads a stream and decodes the byte character by character. This method
  * will return the remainder of the stream.
  *
  * @param  string $stream The stream to be decoded.
  * @return string         The remainder of the stream, if any.
  */
 public function decode($stream)
 {
     $stream = str_split($stream);
     $buffer = '';
     $size = count($stream);
     $sizeList = new \SplDoublyLinkedList();
     $bufList = new \SplDoublyLinkedList();
     // read the size of the byte from the stream
     for ($i = 0; $i < count($stream); $i++) {
         $temp = $stream[$i];
         unset($stream[$i]);
         if ($temp === ':') {
             break;
         }
         $sizeList->push($temp);
     }
     $stream = array_values($stream);
     $size = 0;
     foreach ($sizeList as $sl) {
         $size .= $sl;
     }
     // read the length of the byte from the stream
     for ($i = 0; $i < $size; $i++) {
         $bufList->push($stream[$i]);
         unset($stream[$i]);
     }
     // read the byte into the buffer
     foreach ($bufList as $bl) {
         $buffer .= $bl;
     }
     $this->_buffer = $buffer;
     return implode('', array_values($stream));
 }
예제 #6
0
 /**
  * @todo make recursive
  * 
  * Reads a stream character for character until the suffix ('e') is found
  * and returns the remainder of the string.
  *
  * @param string $stream Reads the stream into the buffer.
  *
  * @throws Bencode\Exceptions\IntegerException
  */
 public function decode($stream)
 {
     $flag = false;
     $stream = str_split($stream);
     $buffer = '';
     $size = count($stream);
     $stack = new \SplDoublyLinkedList();
     for ($i = 0; $i < $size - 1; $i++) {
         if ($flag) {
             if (is_numeric($stream[$i]) || $stream[$i] === '-') {
                 $stack->push($stream[$i]);
             }
         }
         if ($stream[$i] === 'i') {
             $flag = true;
         }
         if ($stream[$i] === 'e') {
             $flag = false;
             unset($stream[$i]);
             break;
         }
         unset($stream[$i]);
     }
     foreach ($stack as $s) {
         $buffer .= $s;
     }
     $this->_buffer = $buffer;
     return implode('', array_values($stream));
 }
예제 #7
0
 function __construct()
 {
     $this->listClients = new SplDoublyLinkedList();
     //=========================load file===============================//
     $read = new ReadCsv();
     $lisClient = $read->get2DArrayFromCsv('files/clientes.csv', ',');
     foreach ($lisClient as $row => $data) {
         $listProductByClient = new SplDoublyLinkedList();
         $contLines = 0;
         $codeProduct = 0;
         foreach ($data as $rowL => $dataL) {
             if ($rowL > 1 && $dataL != "") {
                 if ($contLines == 0) {
                     $codeProduct = $dataL;
                     $contLines++;
                 } else {
                     $listProdCliente = new ListaProductosPorCliente();
                     $listProdCliente->setIdProducto($codeProduct);
                     $listProdCliente->setProducto($dataL);
                     $listProductByClient->push($listProdCliente);
                     $contLines--;
                 }
             }
         }
         $client1 = new Clientes();
         $client1->setName($data[0]);
         $client1->setId($data[1]);
         $client1->setListPruductByClient($listProductByClient);
         $this->listClients->push($client1);
     }
     //=========================//load file=============================//
     $this->listClients->serialize();
     //$this->loadFile();
 }
예제 #8
0
function get_result($t, $ladders, $snakes)
{
    fill_graph($t, $ladders);
    fill_graph($t, $snakes);
    $len = count($t);
    $vertices = array();
    for ($k = 0; $k < $len; $k++) {
        $vertices[$k] = new vertex($k);
    }
    $adjacencyList = array();
    for ($u = 0; $u < $len; $u++) {
        $list = new SplDoublyLinkedList();
        for ($v = 0; $v < $len; $v++) {
            if ($t[$u][$v] != 0) {
                $list->push(array('vertex' => $vertices[$v], 'distance' => $t[$u][$v]));
            }
        }
        $list->rewind();
        $adjacencyList[] = $list;
    }
    calcShortestPaths($vertices[0], $adjacencyList);
    $path = end($vertices)->path;
    $result = $p = 0;
    for ($n = 0; $n < count($path); $n++) {
        $p++;
        if (@$path[$n + 1] - $path[$n] != 1) {
            $result = $result + ceil(($p - 1) / 6);
            $p = 0;
        }
    }
    //echo "[" . implode(', ', $path) . "]\n\n";
    return $result;
}
예제 #9
0
 /**
  * Appends the new listener to the list of item listeners.
  *
  * @param Opf_EventListener $listener The listener.
  */
 public function appendListener(Opf_EventListener $listener)
 {
     if ($this->_listeners === null) {
         $this->_listeners = new SplDoublyLinkedList();
     }
     $this->_listeners->push($listener);
 }
 /**
  * @param $vertex
  * @return \SplDoublyLinkedList
  */
 public function createTransitionsList($vertex)
 {
     $list = new \SplDoublyLinkedList();
     $list->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
     $list->push($vertex);
     return $list;
 }
예제 #11
0
 public function resolve($obj)
 {
     $result = new \SplDoublyLinkedList();
     foreach ($obj as $value) {
         $result->push($value);
     }
     return $result;
 }
 /**
  * @param VisitAction $futureVisitAction
  * @param Expression $lastVisitedExpression
  * @return \SplDoublyLinkedList
  */
 protected function prepareQueueForFutureVisits(VisitAction $futureVisitAction = null, Expression $lastVisitedExpression)
 {
     $stackForExpressions = new \SplDoublyLinkedList();
     if ($lastVisitedExpression instanceof ExpressionIterable) {
         foreach ($lastVisitedExpression as $futureVisit) {
             $stackForExpressions->push($futureVisit);
         }
     } else {
         if ($lastVisitedExpression instanceof ExpressionAggregate) {
             $futureVisit = $lastVisitedExpression->getExpression();
             $stackForExpressions->push($futureVisit);
         }
     }
     if ($futureVisitAction instanceof VisitAction) {
         $stackForExpressions->push($futureVisitAction);
     }
     return $stackForExpressions;
 }
 /**
  * {@inheritdoc}
  */
 public function tokenize($userAgent)
 {
     $iterator = new \SplDoublyLinkedList();
     $iterator->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO);
     foreach ($this->getTokens($userAgent) as $position => $token) {
         $token = trim($token);
         $iterator->push(new Node($token, $position, $this->resolveType($token)));
     }
     return $iterator;
 }
 /**
  * {@inheritdoc}
  */
 public function mergeSets($x, $y)
 {
     $setx = $this->findSet($x);
     $sety = $this->findSet($y);
     if ($setx === Null || $sety === Null) {
         return;
     }
     // create a new linked list from both sets
     $setxy = new SplDoublyLinkedList();
     foreach ($this->_sets[$x] as $e) {
         $setxy->push($e);
     }
     foreach ($this->_sets[$y] as $e) {
         $setxy->push($e);
     }
     unset($this->_sets[$x]);
     unset($this->_sets[$y]);
     $this->_sets[$x] = $setxy;
 }
예제 #15
0
function test(SplDoublyLinkedList $l)
{
    $l->push("a");
    $l->push("b");
    $l->push("c");
    echo "Foreach:", PHP_EOL;
    foreach ($l as $key => $val) {
        echo $key, '=>', $val, PHP_EOL;
    }
    echo PHP_EOL;
    echo "ArrayAccess:", PHP_EOL;
    var_dump($l[0]);
    var_dump($l[1]);
    var_dump($l[2]);
    echo PHP_EOL;
    echo "ArrayAccess Set:", PHP_EOL;
    $l[2] = "two";
    var_dump($l[2]);
    try {
        $l[3] = "five";
        // 3 would be the next element
    } catch (OutOfRangeException $e) {
        echo "OutOfRangeException caught", PHP_EOL;
    }
    echo PHP_EOL;
    echo "ArrayAccess Exists:", PHP_EOL;
    var_dump(isset($l[0]), isset($l[2]), isset($l[3]));
    // true, true, false
    echo PHP_EOL;
    echo "ArrayAccess Unset:", PHP_EOL;
    unset($l[0]);
    var_dump($l->offsetGet(0));
    echo PHP_EOL;
    echo "Foreach:", PHP_EOL;
    foreach ($l as $key => $val) {
        echo $key, '=>', $val, PHP_EOL;
    }
    echo PHP_EOL;
}
예제 #16
0
파일: Node.php 프로젝트: tebru/tree
 /**
  * Add a child node
  *
  * If position if set on the node, add the child at that position.  This
  * will bump any node at that current position and all subsequent nodes
  * down in the list.
  *
  * This method also gives the user the ability to override the current
  * position set on the node.
  *
  * @param Node $node
  * @param int|null $position
  */
 public function addChild(Node $node, $position = null)
 {
     // if position was passed in, override current position
     if (null !== $position) {
         $node->setPosition($position);
     }
     // if the node doesn't have a position, just add it to the end
     $nodePosition = $node->getPosition();
     if (null === $nodePosition) {
         $this->children->push($node);
         return;
     }
     $this->children->add($nodePosition, $node);
 }
예제 #17
0
 /**
  * Returns whether or not the iterator has more elements
  *
  * @return bool
  */
 public function valid()
 {
     if ($this->_buffer->offsetExists($this->_index)) {
         $current = $this->_buffer->offsetGet($this->_index);
         $this->_current = $current['value'];
         $this->_key = $current['key'];
         return true;
     }
     $valid = parent::valid();
     if ($valid) {
         $this->_current = parent::current();
         $this->_key = parent::key();
         $this->_buffer->push(['key' => $this->_key, 'value' => $this->_current]);
     }
     $this->_finished = !$valid;
     return $valid;
 }
예제 #18
0
 /**
  * Perform a depth-first traversal on the provided graph.
  *
  * @param Digraph $graph
  *   The graph on which to perform the depth-first search.
  * @param DepthFirstVisitorInterface $visitor
  *   The visitor object to use during the traversal.
  * @param object|\SplDoublyLinkedList $start
  *   A vertex, or vertices, to use as start points for the traversal. There
  *   are a few sub-behaviors here:
  *     - If an SplDoublyLinkedList, SplQueue, or SplStack is provided, the
  *       traversal will deque and visit vertices contained therein.
  *     - If a single vertex object is provided, it will be the sole
  *       originating point for the traversal.
  *     - If no value is provided, DepthFirst::find_sources() is called to
  *       search the graph for source vertices. These are place into an
  *       SplQueue in the order in which they are discovered, and traversal
  *       is then run over that queue in the same manner as if calling code
  *       had provided a queue directly. This method *guarantees* that all
  *       vertices in the graph will be visited.
  *
  * @throws RuntimeException
  *   Thrown if an invalid $start parameter is provided.
  */
 public static function traverse(Digraph $graph, DepthFirstVisitorInterface $visitor, $start = NULL)
 {
     if ($start === NULL) {
         $queue = self::find_sources($graph, $visitor);
     } else {
         if ($start instanceof \SplDoublyLinkedList) {
             $queue = $start;
         } else {
             if (is_object($start)) {
                 $queue = new \SplDoublyLinkedList();
                 $queue->push($start);
             }
         }
     }
     if ($queue->isEmpty()) {
         throw new RuntimeException('No start vertex or vertices were provided, and no source vertices could be found in the provided graph.', E_WARNING);
     }
     $visiting = new \SplObjectStorage();
     $visited = new \SplObjectStorage();
     $visitor->beginTraversal();
     $visit = function ($vertex) use($graph, $visitor, &$visit, $visiting, $visited) {
         if ($visiting->contains($vertex)) {
             $visitor->onBackEdge($vertex, $visit);
         } else {
             if (!$visited->contains($vertex)) {
                 $visiting->attach($vertex);
                 $visitor->onStartVertex($vertex, $visit);
                 foreach ($graph->successorsOf($vertex) as $head) {
                     $visitor->onExamineEdge($vertex, $head, $visit);
                     $visit($head);
                 }
                 $visitor->onFinishVertex($vertex, $visit);
                 $visiting->detach($vertex);
                 $visited->attach($vertex);
             }
         }
     };
     // TODO experiment with adding a generator-producing visitor method that yields the queue here
     while (!$queue->isEmpty()) {
         $vertex = $queue->shift();
         $visit($vertex);
     }
     $visitor->endTraversal();
 }
예제 #19
0
 /**
  * Perform a depth-first traversal on the provided graph.
  *
  * @param DirectedGraph $graph
  *   The graph on which to perform the depth-first search.
  * @param DepthFirstVisitorInterface $visitor
  *   The visitor object to use during the traversal.
  * @param object|\SplDoublyLinkedList $start
  *   A vertex, or vertices, to use as start points for the traversal. There
  *   are a few sub-behaviors here:
  *     - If an SplDoublyLinkedList, SplQueue, or SplStack is provided, the
  *       traversal will deque and visit vertices contained therein.
  *     - If a single vertex object is provided, it will be the sole
  *       originating point for the traversal.
  *     - If no value is provided, DepthFirst::find_sources() is called to
  *       search the graph for source vertices. These are place into an
  *       SplQueue in the order in which they are discovered, and traversal
  *       is then run over that queue in the same manner as if calling code
  *       had provided a queue directly. This method *guarantees* that all
  *       vertices in the graph will be visited.
  *
  * @throws RuntimeException
  *   Thrown if an invalid $start parameter is provided.
  */
 public static function traverse(DirectedGraph $graph, DepthFirstVisitorInterface $visitor, $start = NULL)
 {
     if ($start === NULL) {
         $queue = self::find_sources($graph, $visitor);
     } else {
         if ($start instanceof \SplDoublyLinkedList) {
             $queue = $start;
         } else {
             if (is_object($start)) {
                 $queue = new \SplDoublyLinkedList();
                 $queue->push($start);
             }
         }
     }
     if ($queue->isEmpty()) {
         throw new RuntimeException('No start vertex or vertices were provided, and no source vertices could be found in the provided graph.', E_WARNING);
     }
     $visiting = new \SplObjectStorage();
     $visited = new \SplObjectStorage();
     $visitor->beginTraversal();
     $visit = function ($vertex) use($graph, $visitor, &$visit, $visiting, $visited) {
         if ($visiting->contains($vertex)) {
             $visitor->onBackEdge($vertex, $visit);
         } else {
             if (!$visited->contains($vertex)) {
                 $visiting->attach($vertex);
                 $visitor->onStartVertex($vertex, $visit);
                 $graph->eachAdjacent($vertex, function ($to) use($vertex, &$visit, $visitor) {
                     $visitor->onExamineEdge($vertex, $to, $visit);
                     $visit($to);
                 });
                 $visitor->onFinishVertex($vertex, $visit);
                 $visiting->detach($vertex);
                 $visited->attach($vertex);
             }
         }
     };
     while (!$queue->isEmpty()) {
         $vertex = $queue->shift();
         $visit($vertex);
     }
     $visitor->endTraversal();
 }
예제 #20
0
 public function __construct()
 {
     $listLink = new SplDoublyLinkedList();
     $listLink->push('Albin');
     $listLink->push('to');
     $listLink->push('the');
     $listLink->push('interface;');
     $listLink->push('not');
     $listLink->push('the');
     $listLink->push('Sandi');
     echo "<strong>Free good advice :</strong><br />";
     $listLink->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($listLink->rewind(); $listLink->valid(); $listLink->next()) {
         echo $listLink->current() . " ";
     }
     echo "<br /><br /><strong>Yoda talk: last in first out:</strong><br />";
     $listLink->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
     for ($listLink->rewind(); $listLink->valid(); $listLink->next()) {
         echo $listLink->current() . " ";
     }
 }
예제 #21
0
 public function testVertex()
 {
     $v0 = new vertex(0);
     $v1 = new vertex(1);
     $v2 = new vertex(2);
     $v3 = new vertex(3);
     $v4 = new vertex(4);
     $v5 = new vertex(5);
     $list0 = new SplDoublyLinkedList();
     $list0->push($v1);
     $list0->push($v3);
     $list0->rewind();
     $list1 = new SplDoublyLinkedList();
     $list1->push($v0);
     $list1->push($v2);
     $list1->rewind();
     $list2 = new SplDoublyLinkedList();
     $list2->push($v1);
     $list2->push($v3);
     $list2->push($v4);
     $list2->rewind();
     $list3 = new SplDoublyLinkedList();
     $list3->push($v1);
     $list3->push($v2);
     $list3->rewind();
     $list4 = new SplDoublyLinkedList();
     $list4->push($v2);
     $list4->push($v5);
     $list4->rewind();
     $list5 = new SplDoublyLinkedList();
     $list5->push($v4);
     $list5->rewind();
     $adjacencyList = array($list0, $list1, $list2, $list3, $list4, $list5);
     calcDistances($v0, $adjacencyList);
     print_r($adjacencyList);
 }
예제 #22
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testNotTraversableOfStrings()
 {
     $list = new \SplDoublyLinkedList();
     $list->push('one string');
     $list->push(array());
     $list->push(new \stdClass());
     new UriValidator($list);
 }
예제 #23
0
<?php

/**
 * Láncolt lista
 *
 * Sorrendezett lista készítésére
 */
$list = new SplDoublyLinkedList();
# Sorban belerakja
$list->push(1);
$list->push(2);
$list->push(3);
$list->push(4);
# az elejére rakja
$list->unshift(5);
$list->unshift(6);
$list->unshift(7);
foreach ($list as $key => $value) {
    echo sprintf("%s => %s\n", $key, $value);
}
예제 #24
0
<?php

/**
 * spl数据结构demo
 * 双向链表 SplDoublyLinkedList
 * 栈SplStack
 * 队列SplQueue
 *
 * 栈和队列都是继承于双向链表,所以,所有双向链表的方法都可以被栈和队列使用。调用方法也一致。
 */
$list = new SplDoublyLinkedList();
// push($value)
// 在结尾插入一个新值
$list->push('value1');
$list->push('value2');
$list->push('value3');
$list->push('value4');
$list->push('value5');
// pop()
// 抛出结尾的一个元素,会使得链表结构减少一个
$list->pop();
// key()
// 获得当前节点的索引值
$list->key();
// count()
// 获得链表的数量
$list->count();
// rewind()
// 将指针返回至初始节点
$list->rewind();
// current()
예제 #25
0
<?php

$list = new SplDoublyLinkedList();
$list->push('o');
$list->push('o');
$list->push('f');
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
$list->rewind();
while ($tmp = $list->current()) {
    echo $tmp;
    $list->next();
}
<?php

$a = new SplDoublyLinkedList();
$a->push(1);
$a->push(2);
$a->push(3);
$a[] = "foo";
$a[3] = 4;
var_dump($a[0]);
var_dump($a[1]);
var_dump($a[2]);
var_dump($a[3]);
echo "Unsetting..\n";
var_dump($a[2]);
unset($a[2]);
var_dump($a[2]);
try {
    var_dump($a["1"]);
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
try {
    var_dump($a["a"]);
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
try {
    var_dump($a["0"]);
} catch (OutOfRangeException $e) {
    echo "Exception: " . $e->getMessage() . "\n";
}
예제 #27
0
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
$listPasilloSession = unserialize($_SESSION['listPasillo']);
$listPasilloTP = $listPasilloSession->offsetGet($_GET['pas']);
$listPa = $listPasilloTP->getTypeProducts();
$listProducts2 = $listPa->offsetGet($_GET['type']);
$listProducts3 = $listProducts2->getListProduct();
$listProductsTP2 = $listProducts3->offsetGet($_GET['prods']);
$listProducts = $listProductsTP2->getListProducts();
$listPila = new SplDoublyLinkedList();
$listProducts->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($listProducts->rewind(); $listProducts->valid(); $listProducts->next()) {
    $data = $listProducts->current();
    $listPila->push($data);
}
$listPila->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($listPila->rewind(); $listPila->valid(); $listPila->next()) {
    $dataPila = $listPila->current();
    ?>
                                    <tr>
                                        <td class="center"><?php 
    echo $dataPila->getIdProduct();
    ?>
</td>
                                        <td><?php 
    echo $dataPila->getProduct();
    ?>
</td>
                                        <td class="center">
예제 #28
0
 unset($array[102]);
 var_dump($array[100]);
 var_dump($array[102]);
 $e = microtime(true);
 echo "Count: " . count($array) . "\n";
 echo "Elapsed time: " . ($e - $s) . " sec.\n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 unset($array);
 echo "\n-- SplDoublyLinkedList \n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 $s = microtime(true);
 $spl = new SplDoublyLinkedList();
 for ($i = 0; $i < $v; $i++) {
     $spl->push($i);
 }
 try {
     $spl->offsetUnset(102);
     var_dump($spl->offsetGet(100));
     var_dump($spl->offsetGet(102));
 } catch (OutOfRangeException $e) {
     echo $e;
 }
 $e = microtime(true);
 echo "Count: " . $spl->count() . "\n";
 echo "Elapsed time: " . ($e - $s) . " sec.\n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 try {
     for ($i = 0; $i < $v; $i++) {
 public function getOtherChildrenIDs($obj, $mainID, $prop)
 {
     $list = new SplDoublyLinkedList();
     //echo "<br/>-----getOtherChildrenIDs:".$prop;
     if (!is_null($obj)) {
         foreach ($obj->edges as $edge) {
             if (strcmp($prop, $edge->pred) == 0) {
                 /*if(strcmp($mainID,$edge->obj)==0)
                                             {
                                                     $list->push($edge->sub);
                 
                                             }*/
                 if (strcmp($mainID, $edge->sub) == 0) {
                     $list->push($edge->obj);
                 }
             }
         }
     }
     return $list;
 }
예제 #30
0
$list1->rewind();
$list2 = new SplDoublyLinkedList();
$list2->push($v1);
$list2->push($v3);
$list2->push($v4);
$list2->rewind();
$list3 = new SplDoublyLinkedList();
$list3->push($v1);
$list3->push($v2);
$list3->rewind();
$list4 = new SplDoublyLinkedList();
$list4->push($v2);
$list4->push($v5);
$list4->rewind();
$list5 = new SplDoublyLinkedList();
$list5->push($v4);
$list5->rewind();
$adjacencyList = array($list0, $list1, $list2, $list3, $list4, $list5);
function calcShortestPaths(vertex $start, &$adjLists)
{
    // define an empty queue
    $q = array();
    // push the starting vertex into the queue
    array_push($q, $start);
    // color it gray
    $start->color = 'gray';
    // mark the distance to it 0
    $start->distance = 0;
    // the path to the starting vertex
    $start->path = new SplDoublyLinkedList();
    $start->path->push($start->key);