當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SplStack類代碼示例

本文整理匯總了PHP中SplStack的典型用法代碼示例。如果您正苦於以下問題:PHP SplStack類的具體用法?PHP SplStack怎麽用?PHP SplStack使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SplStack類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 public function parse($code)
 {
     $ary = new BrainDog_OpArray();
     $pst = new SplStack();
     foreach (str_split($code) as $op) {
         $idx = count($ary);
         switch ($op) {
             case self::OP_GT:
             case self::OP_LT:
             case self::OP_ADD:
             case self::OP_SUB:
             case self::OP_DOT:
             case self::OP_COM:
                 $ary[$idx] = new BrainDog_OpCode($op);
                 break;
             case self::OP_LBR:
                 $pst->push($idx);
                 $ary[$idx] = new BrainDog_OpCode($op);
                 break;
             case self::OP_RBR:
                 $pos = $pst->pop();
                 $ary[$pos]->jmp = $idx;
                 $ary[$idx] = new BrainDog_OpCode($op, $pos - 1);
                 break;
         }
     }
     return $ary;
 }
開發者ID:rsky,項目名稱:phpkansai-party-lt,代碼行數:28,代碼來源:BrainDog.php

示例2: LoadV2

 /**
  * 加載指定目錄下的配置並生成[絕對路徑=>配置]
  * (備用)
  *
  * @param        $filePath
  * @param string $ext
  */
 private function LoadV2($filePath, $ext = '.php')
 {
     $resConfig = [];
     $split = '.';
     if (file_exists($filePath)) {
         $key = basename($filePath, $ext);
         $configs = (include $filePath);
         $keyStack = new \SplStack();
         $keyStack->push([$key, $configs]);
         $whileCount = 0;
         //防止意外進入死循環,限製最多循環1024層
         while (!$keyStack->isEmpty() && $whileCount < 1024) {
             $whileCount++;
             $pair = $keyStack->pop();
             foreach ($pair[1] as $pairKey => $pairVal) {
                 if (is_array($pairVal)) {
                     $keyStack->push([$pair[0] . $split . $pairKey, $pairVal]);
                 } else {
                     $resConfig[$pair[0] . $split . $pairKey] = $pairVal;
                 }
             }
         }
     }
     return $resConfig;
 }
開發者ID:szyhf,項目名稱:DIServer,代碼行數:32,代碼來源:Base.php

示例3: evaluateRPN

 /**
  * Evaluate array sequence of tokens in Reverse Polish notation (RPN)
  * representing mathematical expression.
  * 
  * @param array $expressionTokens
  * @return float
  * @throws \InvalidArgumentException
  */
 private function evaluateRPN(array $expressionTokens)
 {
     $stack = new \SplStack();
     foreach ($expressionTokens as $token) {
         $tokenValue = $token->getValue();
         if (is_numeric($tokenValue)) {
             $stack->push((double) $tokenValue);
             continue;
         }
         switch ($tokenValue) {
             case '+':
                 $stack->push($stack->pop() + $stack->pop());
                 break;
             case '-':
                 $n = $stack->pop();
                 $stack->push($stack->pop() - $n);
                 break;
             case '*':
                 $stack->push($stack->pop() * $stack->pop());
                 break;
             case '/':
                 $n = $stack->pop();
                 $stack->push($stack->pop() / $n);
                 break;
             case '%':
                 $n = $stack->pop();
                 $stack->push($stack->pop() % $n);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Invalid operator detected: %s', $tokenValue));
                 break;
         }
     }
     return $stack->top();
 }
開發者ID:aboyadzhiev,項目名稱:php-math-parser,代碼行數:43,代碼來源:Parser.php

示例4: testPrintTraversable

 function testPrintTraversable()
 {
     $stack = new \SplStack();
     $stack->push('foo');
     $stack->push('bar');
     $this->assertEquals("<SplStack>['bar', 'foo']", ValuePrinter::serialize($stack));
 }
開發者ID:watoki,項目名稱:reflect,代碼行數:7,代碼來源:PrintValuesTest.php

示例5: run

 /**
  * Run the pathfinder algorithm
  *
  * @return \SplStack
  */
 public function run()
 {
     $start = $this->start;
     $goal = $this->goal;
     $open = new Set([$start], function (NodeInterface $node) use($goal) {
         return $this->getHeuristic($goal, $node);
     });
     $closed = new Set();
     $open->add($start);
     $path = new \SplStack();
     $step = null;
     while (!$open->isEmpty()) {
         $current = $open->current();
         $path->push($current->getNode());
         $step = new Step($current->getNode(), $step);
         if ($current->getNode() == $goal) {
             break;
         }
         $closed->add($current->getNode());
         $neighbours = $current->getNode()->getNeighbours();
         foreach ($neighbours as $neighbour) {
             if ($closed->has($neighbour)) {
                 continue;
             }
             if (!$open->has($neighbour)) {
                 $open->add($neighbour, $this->getHeuristic($current->getNode(), $neighbour) + $neighbour->getCost());
             }
         }
     }
     return $path;
 }
開發者ID:choccybiccy,項目名稱:pathfinder,代碼行數:36,代碼來源:Path.php

示例6: stackedCoroutine

 /**
  * Resolves yield calls tree
  * and gives a return value if outcome of yield is CoroutineReturnValue instance
  *
  * @param \Generator $coroutine nested coroutine tree
  * @return \Generator
  */
 private static function stackedCoroutine(\Generator $coroutine)
 {
     $stack = new \SplStack();
     while (true) {
         $value = $coroutine->current();
         // nested generator/coroutine
         if ($value instanceof \Generator) {
             $stack->push($coroutine);
             $coroutine = $value;
             continue;
         }
         // coroutine end or value is a value object instance
         if (!$coroutine->valid() || $value instanceof CoroutineReturnValue) {
             // if till this point, there are no coroutines in a stack thatn stop here
             if ($stack->isEmpty()) {
                 return;
             }
             $coroutine = $stack->pop();
             $value = $value instanceof CoroutineReturnValue ? $value->getValue() : null;
             $coroutine->send($value);
             continue;
         }
         $coroutine->send((yield $coroutine->key() => $value));
     }
 }
開發者ID:zavalit,項目名稱:corouser,代碼行數:32,代碼來源:StackedCoroutineTrait.php

示例7: notify

 /**
  * @return \SplStack
  */
 public function notify()
 {
     $pilhaNotificacoes = new \SplStack();
     foreach ($this->observers as $value) {
         $pilhaNotificacoes->push($value->update($this));
     }
     return $pilhaNotificacoes;
 }
開發者ID:he--,項目名稱:liquidaJp,代碼行數:11,代碼來源:Item.php

示例8: stack

 private function stack($items)
 {
     $stack = new \SplStack();
     foreach ($items as $item) {
         $stack->push($item);
     }
     return $stack;
 }
開發者ID:rtens,項目名稱:mockster3,代碼行數:8,代碼來源:MatchArgumentsTest.php

示例9: firstrun

 protected function firstrun()
 {
     $data = new \SplStack();
     foreach ($this->source as $val) {
         $data->push($val);
     }
     parent::__construct($data);
 }
開發者ID:halfnelson,項目名稱:LINQ4PHP,代碼行數:8,代碼來源:ReverseIterator.php

示例10: testSend

 /**
  * @depends testGetStack
  * @covers Versionable\Ration\Client\Pipeline::send
  * @covers Versionable\Ration\Client\Pipeline::getStack
  */
 public function testSend()
 {
     $request = $this->getMock('Versionable\\Ration\\Request\\Request');
     $stack = new \SplStack();
     $stack->push($request);
     $this->object->send($request);
     $this->assertEquals($stack, $this->object->getStack());
 }
開發者ID:versionable,項目名稱:ration,代碼行數:13,代碼來源:PipelineTest.php

示例11: shortestPath

 public function shortestPath($source, $target)
 {
     // array of best estimates of shortest path to each
     // vertex
     $dist = array();
     // array of predecessors for each vertex
     $prev = array();
     $vertex = array();
     foreach ($this->graph as $v => $adj) {
         $vertex[$v] = 1;
         foreach ($adj as $w => $cost) {
             $vertex[$w] = 1;
         }
     }
     foreach ($vertex as $v => $value) {
         $dist[$v] = 1;
         $prev[$v] = null;
     }
     $dist[$source] = -1;
     while (!empty($vertex)) {
         $min = 2;
         $u = null;
         foreach ($vertex as $v => $value) {
             if ($dist[$v] < $min) {
                 $min = $dist[$v];
                 $u = $v;
             }
         }
         unset($vertex[$u]);
         if (isset($this->graph[$u])) {
             foreach ($this->graph[$u] as $n => $cost) {
                 $alt = -abs($dist[$u] * $cost);
                 if ($alt < $dist[$n]) {
                     $dist[$n] = $alt;
                     $prev[$n] = $u;
                 }
             }
         }
     }
     // we can now find the shortest path using reverse
     // iteration
     $S = new \SplStack();
     // shortest path with a stack
     $u = $target;
     $dist = 1;
     // traverse from target to source
     while (isset($prev[$u]) && $prev[$u] && $u != $source) {
         $S->push($u);
         $dist *= $this->graph[$prev[$u]][$u];
         // add distance to predecessor
         $u = $prev[$u];
     }
     if ($u != $source) {
         return 0;
     }
     return $dist;
 }
開發者ID:quanyang,項目名稱:cs3219-project,代碼行數:57,代碼來源:Dijkstra.php

示例12: getParamsStack

 public function getParamsStack()
 {
     if (null === $this->paramsStack) {
         $this->paramsStack = new \SplStack();
         if ($this->getParentCommand() instanceof CommandInterface) {
             $this->paramsStack->push($this->getParentCommand()->getParams());
         }
     }
     return $this->paramsStack;
 }
開發者ID:deltaphp,項目名稱:operator,代碼行數:10,代碼來源:PreCommand.php

示例13: solve

 private function solve($formula)
 {
     $findSubFormula = false;
     $stringStart = 0;
     $stringLength = 0;
     $stack = new \SplStack();
     $subFormulas = [];
     for ($i = 0; $i < strlen($formula); $i++) {
         $char = $formula[$i];
         if ($this->isBracketOpen($char)) {
             if ($findSubFormula == false && $stack->count() == 0) {
                 $stringStart = $i;
             }
             $stack->push(1);
             $findSubFormula = true;
         }
         if ($findSubFormula) {
             $stringLength++;
         }
         if ($this->isBracketClose($char)) {
             $stack->pop();
             if ($stack->count() === 0 && $findSubFormula) {
                 $subFormulas[substr($formula, $stringStart, $stringLength)] = substr($formula, $stringStart, $stringLength);
                 $findSubFormula = false;
                 $stringLength = 0;
             }
         }
     }
     if (count($subFormulas) > 0) {
         foreach ($subFormulas as &$subFormula) {
             $temp = trim(substr($subFormula, 1, strlen($subFormula) - 2));
             $subFormula = $this->solve($temp);
         }
         $formula = str_replace(array_keys($subFormulas), array_values($subFormulas), $formula);
     }
     $elems = new \SplDoublyLinkedList();
     array_map(function ($item) use($elems) {
         if ($item != ' ') {
             $elems->push($item);
         }
     }, explode(' ', $formula));
     while ($elems->count() > 1) {
         $maxPriority = 0;
         $index = 0;
         foreach ($elems as $i => $el) {
             if (isset(static::$symbols[$el]) && static::$symbols[$el] > $maxPriority) {
                 $maxPriority = static::$symbols[$el];
                 $index = $i;
             }
         }
         $this->process($index, $elems);
     }
     return $elems->pop();
 }
開發者ID:ygto,項目名稱:calculator,代碼行數:54,代碼來源:Calculator.php

示例14: pushProcessor

 /**
  * @inheritdoc
  */
 public function pushProcessor(ProcessorInterface ...$processors)
 {
     $this->initProcessors();
     foreach ($processors as $processor) {
         $this->processors->push($processor);
     }
 }
開發者ID:oqq,項目名稱:minc-log,代碼行數:10,代碼來源:ProcessorContainerTrait.php

示例15: pushHandler

 /**
  * @inheritdoc
  */
 public function pushHandler(HandlerInterface ...$handlers)
 {
     $this->initHandlers();
     foreach ($handlers as $handler) {
         $this->handlers->push($handler);
     }
 }
開發者ID:oqq,項目名稱:minc-log,代碼行數:10,代碼來源:HandlerContainerTrait.php


注:本文中的SplStack類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。