当前位置: 首页>>代码示例>>PHP>>正文


PHP SplQueue::bottom方法代码示例

本文整理汇总了PHP中SplQueue::bottom方法的典型用法代码示例。如果您正苦于以下问题:PHP SplQueue::bottom方法的具体用法?PHP SplQueue::bottom怎么用?PHP SplQueue::bottom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplQueue的用法示例。


在下文中一共展示了SplQueue::bottom方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: write

 /**
  * {@inheritDoc}
  */
 public function write($messageContent)
 {
     $writer = new Awaitable();
     $message = new Message($messageContent);
     $this->writersQueue->enqueue($writer);
     $this->messageQueue->enqueue($message);
     if ($this->buffer) {
         while ($this->messageQueue->bottom() !== $message || !$this->buffer->isWriteable()) {
             (yield $writer->await());
         }
         $this->buffer->write($this->messageQueue->dequeue());
         $this->notifyAwaiting($this->readersQueue);
         return;
     }
     $this->notifyAwaiting($this->readersQueue);
     while ($this->readersQueue->count() <= $this->indexOf($message, $this->messageQueue)) {
         (yield $writer->await());
     }
 }
开发者ID:crystalplanet,项目名称:redshift,代码行数:22,代码来源:Channel.php

示例2: __invoke

 /**
  * @inheritDoc
  */
 public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
 {
     if ($this->scheduler !== null) {
         $scheduler = $this->scheduler;
     }
     if ($scheduler === null) {
         throw new \Exception("You must use a scheduler that support non-zero delay.");
     }
     /** @var AnonymousObservable $observable */
     $disp = $observable->materialize()->timestamp()->map(function (Timestamped $x) {
         return new Timestamped($x->getTimestampMillis() + $this->delayTime, $x->getValue());
     })->subscribe(new CallbackObserver(function (Timestamped $x) use($scheduler, $observer) {
         if ($x->getValue() instanceof Notification\OnErrorNotification) {
             $x->getValue()->accept($observer);
             return;
         }
         $this->queue->enqueue($x);
         if ($this->schedulerDisposable === null) {
             $doScheduledStuff = function () use($observer, $scheduler, &$doScheduledStuff) {
                 while (!$this->queue->isEmpty() && $scheduler->now() >= $this->queue->bottom()->getTimestampMillis()) {
                     /** @var Timestamped $item */
                     $item = $this->queue->dequeue();
                     /** @var Notification $materializedValue */
                     $materializedValue = $item->getValue();
                     $materializedValue->accept($observer);
                 }
                 if ($this->queue->isEmpty()) {
                     $this->schedulerDisposable = null;
                     return;
                 }
                 $this->schedulerDisposable = $scheduler->schedule($doScheduledStuff, $this->queue->bottom()->getTimestampMillis() - $scheduler->now());
             };
             $doScheduledStuff();
         }
     }, [$observer, 'onError']), $scheduler);
     return new CallbackDisposable(function () use($disp) {
         if ($this->schedulerDisposable) {
             $this->schedulerDisposable->dispose();
         }
         $disp->dispose();
     });
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:45,代码来源:DelayOperator.php

示例3: leastHops

 public function leastHops($origin, $destination)
 {
     // mark all nodes as unvisited
     foreach ($this->graph as $key => $vertex) {
         $this->visited[$key] = false;
     }
     // create an empty queue
     $q = new SplQueue();
     // enqueue the origin vertex and mark as visited
     $q->enqueue($origin);
     $this->visited[$origin] = true;
     // an array stack to track the path back from each node
     $path = array();
     $path[$origin] = new SplDoublyLinkedList();
     $path[$origin]->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);
     $path[$origin]->push($origin);
     $found = false;
     // while queue is not empty and destination not found
     while (!$q->isEmpty() && $q->bottom() != $destination) {
         $t = $q->dequeue();
         if (!empty($this->graph[$t])) {
             // for each adjacent neighbor
             foreach ($this->graph[$t] as $vertex) {
                 if (!$this->visited[$vertex]) {
                     // if not yet visited, enqueue vertex and mark as visited
                     $q->enqueue($vertex);
                     $this->visited[$vertex] = true;
                     // add vertex to current node path
                     $path[$vertex] = clone $path[$t];
                     $path[$vertex]->push($vertex);
                 }
             }
         }
     }
     if (isset($path[$destination])) {
         echo "{$origin} to {$destination} in ", count($path[$destination]) - 1, " hops\n";
         $sep = '';
         foreach ($path[$destination] as $vertex) {
             echo $sep, $vertex;
             $sep = '->';
         }
         echo "\n";
     } else {
         echo "No route from {$origin} to {$destination}\n";
     }
 }
开发者ID:Brother-Simon,项目名称:DataStructuresForPHPDevs,代码行数:46,代码来源:graph-leasthops.php

示例4: receive

 /**
  * {@inheritdoc}
  */
 public function receive(int $length = 0, float $timeout = 0) : \Generator
 {
     while (!$this->readQueue->isEmpty()) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         $delayed = $this->readQueue->bottom();
         (yield $delayed);
         // Wait for previous read to complete.
     }
     if (!$this->isOpen()) {
         throw new UnavailableException('The datagram is no longer readable.');
     }
     $this->length = (int) $length;
     if (0 > $this->length) {
         throw new InvalidArgumentError('The length must be a non-negative integer.');
     } elseif (0 === $this->length) {
         $this->length = self::MAX_PACKET_SIZE;
     }
     $this->readQueue->push($delayed = new Delayed($this->onReceiveCancelled));
     $this->poll->listen($timeout);
     return (yield $delayed);
 }
开发者ID:icicleio,项目名称:socket,代码行数:24,代码来源:BasicDatagram.php

示例5: accept

 /**
  * {@inheritdoc}
  */
 public function accept(bool $autoClose = true) : \Generator
 {
     while (!$this->queue->isEmpty()) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         $delayed = $this->queue->bottom();
         (yield $delayed);
         // Wait for previous accept to complete.
     }
     if (!$this->isOpen()) {
         throw new UnavailableException('The server has been closed.');
     }
     // Error reporting suppressed since stream_socket_accept() emits E_WARNING on client accept failure.
     $socket = @stream_socket_accept($this->getResource(), 0);
     // Timeout of 0 to be non-blocking.
     if ($socket) {
         return $this->createSocket($socket, $autoClose);
     }
     $this->queue->push($delayed = new Delayed($this->onCancelled));
     $this->poll->listen();
     return $this->createSocket((yield $delayed), $autoClose);
 }
开发者ID:icicleio,项目名称:socket,代码行数:24,代码来源:BasicServer.php

示例6: poll

 /**
  * @coroutine
  *
  * Returns a coroutine fulfilled when there is data available to read in the internal stream buffer. Note that
  * this method does not consider data that may be available in the internal buffer. This method can be used to
  * implement functionality that uses the stream socket resource directly.
  *
  * @param float|int $timeout Number of seconds until the returned coroutine is rejected with a TimeoutException
  *     if no data is received. Use 0 for no timeout.
  *
  * @return \Generator
  *
  * @resolve string Empty string.
  *
  * @throws \Icicle\Awaitable\Exception\TimeoutException If the operation times out.
  * @throws \Icicle\Stream\Exception\FailureException If the stream buffer is not empty.
  * @throws \Icicle\Stream\Exception\UnreadableException If the stream is no longer readable.
  * @throws \Icicle\Stream\Exception\ClosedException If the stream has been closed.
  */
 public function poll(float $timeout = 0) : \Generator
 {
     while (!$this->queue->isEmpty()) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         $delayed = $this->queue->bottom();
         (yield $delayed);
         // Wait for previous read to complete.
     }
     if (!$this->isReadable()) {
         throw new UnreadableException('The stream is no longer readable.');
     }
     if ('' !== $this->buffer) {
         throw new FailureException('Stream buffer is not empty. Perform another read before polling.');
     }
     $this->queue->push($delayed = new Delayed($this->onCancelled));
     $this->poll->listen($timeout);
     (yield $delayed);
     if ('' !== $this->buffer) {
         throw new FailureException('Data unshifted to stream buffer while polling.');
     }
     return '';
     // Resolve with empty string.
 }
开发者ID:icicleio,项目名称:stream,代码行数:42,代码来源:ReadablePipe.php

示例7: constructAST

 private function constructAST(Queue $tokens) : AST\Node
 {
     if ($tokens->isEmpty()) {
         throw new ParseException("Unexpected end of file");
     }
     $stack = new Stack();
     while (!$tokens->isEmpty()) {
         $token = $tokens->bottom();
         if ($this->isNumber($token)) {
             $tokens->dequeue();
             $stack->push(new AST\Constant($token->getLine(), (double) $token->getContent()));
         } else {
             if ($this->isVariable($token)) {
                 $tokens->dequeue();
                 $stack->push(new AST\Variable($token->getLine(), $token->getContent()));
             } else {
                 if ($this->isOperator($token)) {
                     $tokens->dequeue();
                     $right = $stack->pop();
                     $left = $stack->pop();
                     $stack->push(new AST\Operator($left->getLine(), $token->getId(), $left, $right));
                 } else {
                     if ($this->isFunctionName($token)) {
                         $tokens->dequeue();
                         $arguments = [];
                         for ($i = 0; $i < FUNCTIONS[$token->getContent()]['arity']; $i++) {
                             if ($stack->isEmpty()) {
                                 throw new ParseException("Not enough arguments on stack for '{$token->getContent()}', some function is missing an argument");
                             }
                             $arguments[] = $stack->pop();
                         }
                         // sin(1,2) would be [2 1 sin] on the stack
                         $arguments = \array_reverse($arguments);
                         $stack->push(new AST\FunctionCall($token->getLine(), $token->getContent(), $arguments));
                     } else {
                         throw new ParseException("Unexpected token {$token->getName()} on line {$token->getLine()}");
                     }
                 }
             }
         }
     }
     if ($stack->isEmpty()) {
         throw new ParseException("??????");
     }
     if ($stack->count() !== 1) {
         throw new ParseException("Missing operator");
     }
     return $stack->pop();
 }
开发者ID:TazeTSchnitzel,项目名称:pico8bot.php,代码行数:49,代码来源:Parser.php

示例8: getIndirectConversion

 /**
  * Convert over a number of hops if possible
  *
  * Breadth-first search from http://www.sitepoint.com/data-structures-4/
  *
  * @return SplDoublyLinkedList|array
  */
 protected function getIndirectConversion(Unit $from, Unit $to)
 {
     $origin = $from->getAbbr();
     $destination = $to->getAbbr();
     // Mark all nodes as unvisited
     $visited = array();
     foreach ($this->conversions as $vertex => $adj) {
         $visited[$vertex] = false;
     }
     // Create a queue
     $q = new \SplQueue();
     // Enqueue the origin vertex and mark as visited
     $q->enqueue($origin);
     $visited[$origin] = true;
     // Create a path that can be back-tracked
     $path = array();
     $path[$origin] = new \SplDoublyLinkedList();
     $path[$origin]->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
     $found = false;
     while (!$q->isEmpty() && $q->bottom() != $destination) {
         $t = $q->dequeue();
         if (!empty($this->conversions[$t])) {
             // For each adjacent neighbour,
             foreach ($this->conversions[$t] as $vertex => $conv) {
                 if (!array_key_exists($vertex, $visited) || !$visited[$vertex]) {
                     // Mark as visited and enqueue
                     $q->enqueue($vertex);
                     $visited[$vertex] = true;
                     // Add to current path
                     $path[$vertex] = clone $path[$t];
                     $path[$vertex]->push($conv);
                 }
             }
         }
     }
     if (isset($path[$destination])) {
         return $path[$destination];
     } else {
         return array();
     }
 }
开发者ID:rmasters,项目名称:units,代码行数:48,代码来源:Convert.php

示例9: createAwait

 /**
  * @param resource $resource
  * @param \SplQueue $writeQueue
  *
  * @return \Icicle\Loop\Watcher\Io
  */
 private function createAwait($resource, \SplQueue $writeQueue) : Io
 {
     return Loop\await($resource, static function ($resource, bool $expired, Io $await) use($writeQueue) {
         /** @var \Icicle\Awaitable\Delayed $delayed */
         list($data, $previous, $timeout, $delayed) = $writeQueue->shift();
         if ($expired) {
             $delayed->reject(new TimeoutException('Writing to the socket timed out.'));
             return;
         }
         $length = strlen($data);
         if (0 === $length) {
             $delayed->resolve($previous);
         } else {
             // Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
             $written = @fwrite($resource, $data, self::CHUNK_SIZE);
             if (false === $written || 0 === $written) {
                 $message = 'Failed to write to stream.';
                 if ($error = error_get_last()) {
                     $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
                 }
                 $delayed->reject(new FailureException($message));
                 return;
             }
             if ($length <= $written) {
                 $delayed->resolve($written + $previous);
             } else {
                 $data = substr($data, $written);
                 $written += $previous;
                 $writeQueue->unshift([$data, $written, $timeout, $delayed]);
             }
         }
         if (!$writeQueue->isEmpty()) {
             list(, , $timeout) = $writeQueue->bottom();
             $await->listen($timeout);
         }
     });
 }
开发者ID:icicleio,项目名称:stream,代码行数:43,代码来源:WritablePipe.php

示例10: stateStatement

 public function stateStatement(Token $token)
 {
     $lval = strtolower($token->value);
     switch ($token->type) {
         case Token::LCURLY:
         case Token::RCURLY:
             $this->curlyLevel += $token->type === Token::LCURLY ? +1 : -1;
         case Token::SEMICOLON:
             $this->appendStatement($token);
             $this->dumpStatement();
             $this->transition(self::PHP);
             return false;
         case Token::DOT:
             // check if it' just before a "should" token
             $next = $this->skip(Token::WHITESPACE, Token::EOL);
             if ($next->type === Token::IDENT && strtolower($next->value) === 'should') {
                 // Replace it with a single whitespace
                 $token = new Token(Token::WHITESPACE, ' ');
                 $this->appendStatement($token);
                 return $next;
             }
             $this->appendStatement($token);
             return $next;
         case $token->value === '__DIR__':
             $token->value = self::SPEC_CLASS . '::dir(__DIR__)';
             $this->appendStatement($token);
             return false;
         case $lval === 'should':
             // Flush captured non-statement tokens
             while (!$this->statement->isEmpty()) {
                 $token = $this->statement->bottom();
                 if ($token->type === Token::COMMENT || $token->type === Token::WHITESPACE || $token->type === Token::EOL) {
                     $this->write($token->value);
                     $this->statement->shift();
                 } else {
                     break;
                 }
             }
             // Define the expectation wrapper
             $this->write(self::SPEC_CLASS . '::expect(');
             $this->dumpStatement();
             $this->write(')->');
             $this->transition(self::SHOULD);
             return false;
         case $lval === '$this':
             switch (strtoupper($this->blocks->top())) {
                 case 'DESCRIBE':
                 case 'BEFORE':
                 case 'AFTER':
                     $token->value = self::SPEC_CLASS . '::suite()';
                     break;
                 case 'BEFORE_EACH':
                 case 'AFTER_EACH':
                 case 'IT':
                     $token->value = self::SPEC_CLASS . '::test()';
                     break;
             }
         default:
             if ($token->token === T_CLOSE_TAG) {
                 $this->dumpStatement();
                 $this->transition(self::PHP);
                 return $token;
             }
             $this->appendStatement($token);
             return false;
     }
 }
开发者ID:rafeca,项目名称:Spec-PHP,代码行数:67,代码来源:Transform.php

示例11: updateLimitQueue

 private function updateLimitQueue(SplQueue $queue, $interval, $call_limit)
 {
     while (!$queue->isEmpty()) {
         /* Three possibilities here.
         			1: There are timestamps outside the window of the interval,
         			which means that the requests associated with them were long
         			enough ago that they can be removed from the queue.
         			2: There have been more calls within the previous interval
         			of time than are allowed by the rate limit, in which case
         			the program blocks to ensure the rate limit isn't broken.
         			3: There are openings in window, more requests are allowed,
         			and the program continues.*/
         $timeSinceOldest = time() - $queue->bottom();
         // I recently learned that the "bottom" of the
         // queue is the beginning of the queue. Go figure.
         // Remove timestamps from the queue if they're older than
         // the length of the interval
         if ($timeSinceOldest > $interval) {
             $queue->dequeue();
         } elseif ($queue->count() >= $call_limit) {
             if ($timeSinceOldest < $interval) {
                 //order of ops matters
                 echo "sleeping for" . ($interval - $timeSinceOldest + 1) . " seconds\n";
                 sleep($interval - $timeSinceOldest);
             }
         } else {
             break;
         }
     }
     // Add current timestamp to back of queue; this represents
     // the current request.
     $queue->enqueue(time());
 }
开发者ID:tulanowski,项目名称:php-riot-api,代码行数:33,代码来源:php-riot-api.php

示例12: notReached

 /**
  * @param $toVertex
  * @param \SplQueue $queue
  * @return bool
  */
 private function notReached($toVertex, $queue)
 {
     return !$queue->isEmpty() && $queue->bottom() != $toVertex;
 }
开发者ID:ne0h12,项目名称:word-transformer,代码行数:9,代码来源:BreadthFirstSearchAlgorithm.php

示例13: peekBottom

 /**
  * peek at bottom of queue
  *
  * @return mixed
  */
 public function peekBottom()
 {
     return $this->queue->bottom();
 }
开发者ID:pbergman,项目名称:event-loop,代码行数:9,代码来源:Loop.php

示例14: current

 /**
  * Return a current result.
  *
  * @see     Iterator
  * @return  mixed
  */
 public function current()
 {
     return $this->results->bottom();
 }
开发者ID:umanari145,项目名称:phptips,代码行数:10,代码来源:Parallel.php


注:本文中的SplQueue::bottom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。