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


PHP SplPriorityQueue::top方法代码示例

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


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

示例1: __construct

    public function __construct()
    {
        $this->queue = new \SplPriorityQueue();

        $this->timer = Loop\periodic(1, function () {
            $time = time();
            while (!$this->queue->isEmpty()) {
                $key = $this->queue->top();

                if (isset($this->expire[$key])) {
                    if ($time <= $this->expire[$key]) {
                        break;
                    }

                    unset($this->data[$key], $this->expire[$key], $this->ttl[$key]);
                }

                $this->queue->extract();
            }

            if ($this->queue->isEmpty()) {
                $this->timer->stop();
            }
        });

        $this->timer->stop();
        $this->timer->unreference();
    }
开发者ID:Nik-ADA,项目名称:concurrent,代码行数:28,代码来源:Environment.php

示例2: pop

 /**
  * @see QueueInterface::pop()
  */
 public function pop()
 {
     if (!$this->innerQueue->isEmpty()) {
         $eta = $this->innerQueue->top()->getEta();
         if (!$eta || $eta->getTimestamp() <= time()) {
             return $this->innerQueue->extract();
         }
     }
     return false;
 }
开发者ID:rybakit,项目名称:taskqueue,代码行数:13,代码来源:InMemoryQueue.php

示例3: pop

 /**
  * {@inheritdoc}
  */
 public function pop()
 {
     if (!$this->queue->isEmpty()) {
         $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_PRIORITY);
         $priority = $this->queue->top();
         if (time() + $priority[0] >= 0) {
             $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_DATA);
             return $this->queue->extract();
         }
     }
     throw new NoItemAvailableException($this);
 }
开发者ID:rybakit,项目名称:phive-queue,代码行数:15,代码来源:InMemoryQueue.php

示例4: pop

 /**
  * {@inheritdoc}
  */
 public function pop()
 {
     if ($this->queue->isEmpty()) {
         return;
     }
     $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_PRIORITY);
     $priority = $this->queue->top();
     if (time() + $priority[0] >= 0) {
         $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_DATA);
         return $this->queue->extract();
     }
 }
开发者ID:schedulee,项目名称:queue,代码行数:15,代码来源:InMemoryQueue.php

示例5: trigger

 /**
  * @param string $event
  * @param array  $params
  * @param string $context
  */
 public function trigger($event, $params = [], $context = '')
 {
     if (empty($this->events[$event])) {
         return;
     }
     $queue = new \SplPriorityQueue();
     foreach ($this->events[$event] as $index => $action) {
         $queue->insert($index, $action['prio']);
     }
     $queue->top();
     while ($queue->valid()) {
         $index = $queue->current();
         if (!empty($context)) {
             $contexts = explode(',', $this->events[$event][$index]['contexts']);
             $current_context = false;
             foreach ($contexts as $route) {
                 if (fnmatch(trim($route), $context)) {
                     $current_context = true;
                     break;
                 }
             }
         } else {
             $current_context = true;
         }
         if ($current_context && is_callable($this->events[$event][$index]['fn'])) {
             if (call_user_func_array($this->events[$event][$index]['fn'], $params) === false) {
                 break;
             }
         }
         $queue->next();
     }
 }
开发者ID:sydes,项目名称:sydes,代码行数:37,代码来源:Event.php

示例6: tick

 /**
  * 检查是否有可执行的定时任务,有的话执行
  * @return void
  */
 protected function tick()
 {
     while (!$this->_scheduler->isEmpty()) {
         $scheduler_data = $this->_scheduler->top();
         $timer_id = $scheduler_data['data'];
         $next_run_time = -$scheduler_data['priority'];
         $time_now = microtime(true);
         if ($time_now >= $next_run_time) {
             $this->_scheduler->extract();
             // 如果任务不存在,则是对应的定时器已经删除
             if (!isset($this->_task[$timer_id])) {
                 continue;
             }
             // 任务数据[func, args, flag, timer_interval]
             $task_data = $this->_task[$timer_id];
             // 如果是持续的定时任务,再把任务加到定时队列
             if ($task_data[2] === self::EV_TIMER) {
                 $next_run_time = $time_now + $task_data[3];
                 $this->_scheduler->insert($timer_id, -$next_run_time);
             }
             // 尝试执行任务
             try {
                 call_user_func_array($task_data[0], $task_data[1]);
             } catch (\Exception $e) {
                 echo $e;
             }
             continue;
         } else {
             // 设定超时时间
             $this->_selectTimeout = ($next_run_time - $time_now) * 1000000;
             return;
         }
     }
     $this->_selectTimeout = 100000000;
 }
开发者ID:hduwzy,项目名称:test,代码行数:39,代码来源:Select.php

示例7: tick

 /**
  * Executes any pending timers. Returns the number of timers executed.
  *
  * @return int
  *
  * @internal
  */
 public function tick() : int
 {
     $count = 0;
     $time = microtime(true);
     while (!$this->queue->isEmpty()) {
         list($timer, $timeout) = $this->queue->top();
         if (!$this->timers->contains($timer) || $timeout !== $this->timers[$timer]) {
             $this->queue->extract();
             // Timer was removed from queue.
             continue;
         }
         if ($this->timers[$timer] > $time) {
             // Timer at top of queue has not expired.
             return $count;
         }
         // Remove and execute timer. Replace timer if persistent.
         $this->queue->extract();
         if ($timer->isPeriodic()) {
             $timeout = $time + $timer->getInterval();
             $this->queue->insert([$timer, $timeout], -$timeout);
             $this->timers[$timer] = $timeout;
         } else {
             $this->timers->detach($timer);
         }
         // Execute the timer.
         $timer->call();
         ++$count;
     }
     return $count;
 }
开发者ID:viniciusferreira,项目名称:icicle,代码行数:37,代码来源:TimerManager.php

示例8: tick

 /**
  * Tick for timer.
  * @return void
  */
 protected function tick()
 {
     while (!$this->_scheduler->isEmpty()) {
         $scheduler_data = $this->_scheduler->top();
         $timer_id = $scheduler_data['data'];
         $next_run_time = -$scheduler_data['priority'];
         $time_now = microtime(true);
         if ($time_now >= $next_run_time) {
             $this->_scheduler->extract();
             if (!isset($this->_task[$timer_id])) {
                 continue;
             }
             // [func, args, flag, timer_interval]
             $task_data = $this->_task[$timer_id];
             if ($task_data[2] === self::EV_TIMER) {
                 $next_run_time = $time_now + $task_data[3];
                 $this->_scheduler->insert($timer_id, -$next_run_time);
             }
             call_user_func_array($task_data[0], $task_data[1]);
             if (isset($this->_task[$timer_id]) && $task_data[2] === self::EV_TIMER_ONCE) {
                 $this->del($timer_id, self::EV_TIMER_ONCE);
             }
             continue;
         } else {
             $this->_selectTimeout = ($next_run_time - $time_now) * 1000000;
             return;
         }
     }
     $this->_selectTimeout = 100000000;
 }
开发者ID:hackty,项目名称:Workerman,代码行数:34,代码来源:Select.php

示例9: nextTimeout

 /**
  * Get the number of microseconds until the next timer watcher is due.
  * 
  * @return int or null when no timers are pending.
  */
 protected function nextTimeout()
 {
     $time = \microtime(true);
     while (!$this->scheduler->isEmpty()) {
         list($watcher, $scheduled) = $this->scheduler->top();
         if ($watcher->enabled && $watcher->scheduled === $scheduled) {
             return (int) \max(0, ($watcher->due - $time) * 1000000);
         }
     }
 }
开发者ID:koolkode,项目名称:async,代码行数:15,代码来源:NativeLoop.php

示例10: __construct

 /**
  * Method to instantiate the view.
  *
  * @param   JModel            $model  The model object.
  * @param   SplPriorityQueue  $paths  The paths queue.
  *
  * @since   12.1
  */
 public function __construct(JModel $model, SplPriorityQueue $paths = null)
 {
     parent::__construct($model);
     // Setup dependencies.
     $this->paths = isset($paths) ? $paths : $this->loadPaths();
     /* T3: Add T3 html path to the priority paths of component view */
     // T3 html path
     $component = JApplicationHelper::getComponentName();
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
     $t3Path = T3_PATH . '/html/' . $component . '/' . $this->getName();
     // Setup the template path
     $this->paths->top();
     $defaultPath = $this->paths->current();
     $this->paths->next();
     $templatePath = $this->paths->current();
     // add t3 path
     $this->paths->insert($t3Path, 3);
     $this->_path['template'] = array($defaultPath, $t3Path, $templatePath);
     /* //T3 */
 }
开发者ID:grlf,项目名称:eyedock,代码行数:28,代码来源:viewhtml.php

示例11: getTimeout

 /**
  * @return int Milliseconds until next timer expires or -1 if there are no pending times.
  */
 private function getTimeout()
 {
     while (!$this->timerQueue->isEmpty()) {
         list($watcher, $expiration) = $this->timerQueue->top();
         $id = $watcher->id;
         if (!isset($this->timerExpires[$id]) || $expiration !== $this->timerExpires[$id]) {
             $this->timerQueue->extract();
             // Timer was removed from queue.
             continue;
         }
         $expiration -= (int) (\microtime(true) * self::MILLISEC_PER_SEC);
         if ($expiration < 0) {
             return 0;
         }
         return $expiration;
     }
     return -1;
 }
开发者ID:amphp,项目名称:loop,代码行数:21,代码来源:NativeLoop.php

示例12: apply

 public function apply($filter, $value, $args = [])
 {
     if (!isset($this->filters[$filter])) {
         return $value;
     }
     if (!count($this->filters[$filter])) {
         return $this;
     }
     $queue = new \SplPriorityQueue();
     foreach ($this->filters[$filter] as $index => $action) {
         $queue->insert($index, $action["prio"]);
     }
     $queue->top();
     while ($queue->valid()) {
         $index = $queue->current();
         if (is_callable($this->filters[$filter][$index]["fn"])) {
             $value = call_user_func_array($this->filters[$filter][$index]["fn"], [$value, $args]);
         }
         $queue->next();
     }
     return $value;
 }
开发者ID:arshanam,项目名称:Autopilot,代码行数:22,代码来源:Filters.php

示例13: microtime

$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $top = $slist->first();
}
printf("\ntop slist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $alist->asort();
    $top = key($alist);
}
printf("\ntop alist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $top = $plist->top();
}
printf("\ntop plist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $item = $slist->get($i);
}
printf("\nget slist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
$memory = memory_get_usage(1);
$time = microtime(1);
for ($i = 0; $i < 1000; $i++) {
    $item = $alist[$i];
}
printf("\nget alist: time: %f, memory: %d KB\n", microtime(1) - $time, round((memory_get_usage(1) - $memory) / 1000, 2));
开发者ID:php-ion,项目名称:php-ion,代码行数:31,代码来源:skiplist.php

示例14: SplPriorityQueue

<?php

$priorityQueue = new SplPriorityQueue();
try {
    $priorityQueue->top();
} catch (RuntimeException $e) {
    echo "Exception: " . $e->getMessage() . PHP_EOL;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:spl_pq_top_error_empty.php

示例15: split

        $school_same = split(";", $school);
        $response = json_decode(file_get_contents('http://maps.googleapis.com/maps/api/distancematrix/json?origins=' . urlencode($home) . '&destinations=' . urlencode($school_same[0]) . '&mode=driving&language=nl-BE&sensor=false'));
        $distance = -(int) $response->rows[0]->elements[0]->distance->text;
        $pq->insert($school, $distance);
        $pref_array2[$id][$school] = $distance;
    }
    $pref_array[$id] = $pq;
}
$engage_array = [];
$avn_array = [];
$id_enagage = [];
while (count($engage_array) < count($school_array)) {
    foreach ($pref_array as $id => $pq) {
        if (!isset($id_enagage[$id]) || !$id_enagage[$id]) {
            if (!$pq->isEmpty()) {
                $top = $pq->top();
                if (!isset($engage_array[$top])) {
                    $engage_array[$top] = $id;
                    $id_enagage[$id] = true;
                    //echo "$top***$id<br>";
                } else {
                    $old = $engage_array[$top];
                    if (!isset($avnarray[$old])) {
                        $avnarray[$old] = avn($old, $conn, $pref_array2, $id_home);
                        //echo "###$avnarray[$old]<br>";
                    }
                    if (!isset($avnarray[$id])) {
                        $avnarray[$id] = avn($id, $conn, $pref_array2, $id_home);
                        //echo "!!!!!$avnarray[$id]<br>";
                    }
                    if ($avnarray[$old] > $avnarray[$id]) {
开发者ID:ayushv,项目名称:teacher-transfer,代码行数:31,代码来源:solve.php


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