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


PHP SplPriorityQueue::insert方法代码示例

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


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

示例1: find_routes

 private function find_routes($org, $dest, &$flights)
 {
     $result = array();
     $queue = new SplPriorityQueue();
     foreach ($flights as $flight) {
         if ($flight['org_id'] == $org) {
             $route = new Route($this->route_opts);
             $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user);
             $route->add_flight($flight, $num_seats);
             $queue->insert($route, $route->get_joy());
         }
     }
     //BFS to find all routes that take < 10 hours
     $count = 0;
     while ($queue->count() > 0 && $count < $this->opts['max_results']) {
         $cur_route = $queue->extract();
         if ($cur_route->get_dest() == $dest) {
             $result[] = $cur_route;
             $count++;
             continue;
         }
         foreach ($flights as $flight) {
             if (!array_key_exists($flight['dest_id'], $cur_route->visited) && $flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) {
                 $new_route = $cur_route->copy();
                 $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user);
                 $new_route->add_flight($flight, $num_seats);
                 if ($new_route->get_trip_time() < 24 * 60 * 60 && $new_route->seats >= $this->opts['passengers']) {
                     $queue->insert($new_route, $new_route->get_joy());
                 }
             }
         }
     }
     return $result;
 }
开发者ID:NLP-Project,项目名称:GatorAirlines,代码行数:34,代码来源:search.class.php

示例2: find_routes

 private function find_routes($org, $dest, &$flights)
 {
     $result = array();
     $queue = new SplPriorityQueue();
     foreach ($flights as $flight) {
         if ($flight['org_id'] == $org) {
             $route = new Route($this->route_opts);
             $route->add_flight($flight);
             array_push($this->id, $flight['flight_id']);
             $queue->insert($route, $route->get_joy());
         }
     }
     //BFS to find all routes that take < 10 hours
     $count = 0;
     while ($queue->count() > 0 && $count < $this->opts['max_results']) {
         $cur_route = $queue->extract();
         if ($cur_route->get_dest() == $dest) {
             $result[] = $cur_route;
             $count++;
             continue;
         }
         foreach ($flights as $flight) {
             if ($flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) {
                 $new_route = $cur_route->copy();
                 $new_route->add_flight($flight);
                 array_push($this->id, $flight['flight_id']);
                 if ($new_route->get_trip_time() < 24 * 60 * 60) {
                     $queue->insert($new_route, $new_route->get_joy());
                 }
             }
         }
     }
     return $result;
 }
开发者ID:NLP-Project,项目名称:GatorAirlines,代码行数:34,代码来源:Search_F_ID.class.php

示例3: loadConfiguration

 protected function loadConfiguration()
 {
     $sources = new \SplPriorityQueue();
     foreach ($this->getKomponents() as $komponent) {
         foreach ($komponent->getConfigurationSources($this->getContextName()) as $source) {
             $sources->insert($source, $source->getPriority());
         }
     }
     $cfg = new TestConfigLoader();
     $this->testLoader->loadConfigurationSources($cfg);
     foreach ($this->testLoader->findRules() as $rule) {
         $rule->loadConfigurationSources($cfg);
     }
     foreach ($cfg as $source) {
         $sources->insert($source, $source->getPriority());
     }
     $loader = new ConfigurationLoader();
     $loader->registerLoader(new PhpConfigurationLoader());
     $loader->registerLoader(new YamlConfigurationLoader());
     $config = new Configuration();
     $params = $this->getContainerParams();
     foreach ($sources as $source) {
         $config = $config->mergeWith($source->loadConfiguration($loader, $params));
     }
     foreach ($this->testLoader->findRules() as $rule) {
         $config = $config->mergeWith($rule->loadConfiguration());
     }
     return $config->mergeWith($this->testLoader->loadConfiguration());
 }
开发者ID:koolkode,项目名称:k2,代码行数:29,代码来源:TestKernel.php

示例4: execute

 public function execute()
 {
     // Get the document object.
     $document = $this->getApplication()->getDocument();
     $viewFormat = $this->getInput()->getWord('format', 'html');
     $viewName = $this->getInput()->getWord('view', 'dashboard');
     $layoutName = $this->getInput()->getWord('layout', 'default');
     $this->getInput()->set('view', $viewName);
     // Register the layout paths for the view
     $paths = new \SplPriorityQueue();
     $themeOverride = JPATH_THEMES . '/' . $this->getApplication()->get('theme') . '/html/' . strtolower($viewName);
     if (is_dir($themeOverride)) {
         $paths->insert($themeOverride, 'normal');
     }
     $paths->insert(JPATH_COBALT . '/View/' . ucfirst($viewName) . '/tmpl', 'normal');
     $viewClass = 'Cobalt\\View\\' . ucfirst($viewName) . '\\' . ucfirst($viewFormat);
     $modelClass = ucfirst($viewName);
     if (class_exists('Cobalt\\Model\\' . $modelClass) === false) {
         $modelClass = 'DefaultModel';
     }
     $model = $this->getModel($modelClass);
     /** @var $view \Joomla\View\AbstractHtmlView **/
     $view = new $viewClass($model, $paths);
     $view->setLayout($layoutName);
     $view->document = $document;
     // Render our view.
     echo $view->render();
     return true;
 }
开发者ID:houzhenggang,项目名称:cobalt,代码行数:29,代码来源:DefaultController.php

示例5: addStep

 /**
  * Add a step to the current workflow
  *
  * @param Step         $step
  * @param integer|null $priority
  *
  * @return $this
  */
 public function addStep(Step $step, $priority = null)
 {
     $priority = null === $priority && $step instanceof PriorityStep ? $step->getPriority() : $priority;
     $priority = null === $priority ? 0 : $priority;
     $this->steps->insert($step, $priority);
     return $this;
 }
开发者ID:ddeboer,项目名称:data-import,代码行数:15,代码来源:StepAggregator.php

示例6: encode

function encode($symb2freq)
{
    $heap = new SplPriorityQueue();
    // Instancia fila de prioridades utilizando max heap.
    $heap->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
    // define o modo de extração no caso extrai array com a prioridade
    foreach ($symb2freq as $sym => $wt) {
        $heap->insert(array($sym => ''), -$wt);
    }
    while ($heap->count() > 1) {
        $lo = $heap->extract();
        // extraio o minimo
        $hi = $heap->extract();
        // extraio o minimo
        foreach ($lo['data'] as &$x) {
            $x = '0' . $x;
        }
        foreach ($hi['data'] as &$x) {
            $x = '1' . $x;
        }
        $heap->insert($lo['data'] + $hi['data'], $lo['priority'] + $hi['priority']);
    }
    $result = $heap->extract();
    return $result['data'];
}
开发者ID:takaki10,项目名称:PAA,代码行数:25,代码来源:huffman-ajax.php

示例7: getView

 public static function getView($viewName, $layoutName = 'default', $viewFormat = 'html', $vars = null)
 {
     // Get the application
     $app = \Cobalt\Container::fetch('app');
     $document = $app->getDocument();
     $app->input->set('view', $viewName);
     // Register the layout paths for the view
     $paths = new \SplPriorityQueue();
     $themeOverride = JPATH_THEMES . '/' . $app->get('theme') . '/html/' . strtolower($viewName);
     if (is_dir($themeOverride)) {
         $paths->insert($themeOverride, 'normal');
     }
     $paths->insert(JPATH_COBALT . '/View/' . ucfirst($viewName) . '/tmpl', 'normal');
     $viewClass = 'Cobalt\\View\\' . ucfirst($viewName) . '\\' . ucfirst($viewFormat);
     $modelClass = ucfirst($viewName);
     if (class_exists('Cobalt\\Model\\' . $modelClass) === false) {
         $modelClass = 'DefaultModel';
     }
     $model = self::getModel($modelClass);
     /** @var $view \Joomla\View\AbstractHtmlView **/
     $view = new $viewClass($model, $paths);
     $view->setLayout($layoutName);
     $view->document = $document;
     if (isset($vars)) {
         $view->bypass = true;
         foreach ($vars as $varName => $var) {
             $view->{$varName} = $var;
         }
     }
     return $view;
 }
开发者ID:houzhenggang,项目名称:cobalt,代码行数:31,代码来源:ViewHelper.php

示例8: refreshQueue

 /**
  * 刷新监听者队列
  */
 protected function refreshQueue()
 {
     $this->storage->rewind();
     $this->queue = new \SplPriorityQueue();
     foreach ($this->storage as $listener) {
         $priority = $this->storage->getInfo();
         $this->queue->insert($listener, $priority);
     }
 }
开发者ID:slince,项目名称:event,代码行数:12,代码来源:ListenerPriorityQueue.php

示例9: getQueueWithLittleData

function getQueueWithLittleData()
{
    $q = new SplPriorityQueue();
    $q->insert('dux', 4);
    $q->insert('legati', 3);
    $q->insert('centurion', 2);
    $q->insert('munifex', 1);
    return $q;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:SplPriorityQueueClone.php

示例10: loadPaths

 /**
  * Method to load the paths queue.
  *
  * @return  \SplPriorityQueue  The paths queue.
  *
  * @since   1.0.0
  */
 protected function loadPaths()
 {
     $app = \JFactory::getApplication();
     $theme = $app->get('theme');
     $option = $app->input->getString('option');
     $tmplPaths = new \SplPriorityQueue();
     $tmplPaths->insert(JPATH_COMPONENT . '/views/' . $this->name . '/tmpl', 0);
     $tmplPaths->insert(JPATH_THEMES . '/' . $theme . '/html/' . $option . '/' . $this->name, 1);
     return $tmplPaths;
 }
开发者ID:alexva24,项目名称:classes,代码行数:17,代码来源:viewhtml.php

示例11: setUp

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $paths = new \SplPriorityQueue();
     $paths->insert('libraries/windwalker/resource/asset/{type}', 800);
     $paths->insert('libraries/windwalker/test/Asset/Stub/{type}', 500);
     $paths->insert('media/jui/{type}', 300);
     $paths->insert('media/{name}/{type}', 100);
     $this->instance = new AssetManager('test', $paths);
     $this->instance->setDoc($this->doc = new MockHtmlDocument());
     $this->doc->reset();
 }
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:17,代码来源:AssetManagerTest.php

示例12: attach

 /**
  * Attach a filter to the chain
  *
  * @param  callable|FilterInterface $callback
  * @param  int $priority
  * @throws \InvalidArgumentException
  * @return FilterChain
  */
 public function attach($callback, $priority = self::DEFAULT_PRIORITY)
 {
     if (!is_callable($callback)) {
         if (!$callback instanceof FilterInterface) {
             throw new \InvalidArgumentException(sprintf('Expected a valid PHP callback; received "%s"', is_object($callback) ? get_class($callback) : gettype($callback)));
         }
         $callback = [$callback, 'filter'];
     }
     $this->filters->insert($callback, $priority);
     return $this;
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:19,代码来源:FilterChain.php

示例13: spl_priority_queue_is_useful_for_custom_priorities

 public function spl_priority_queue_is_useful_for_custom_priorities()
 {
     $priority_queue = new SplPriorityQueue();
     $priority_queue->insert('o', 1);
     $priority_queue->insert('i', 3);
     $priority_queue->insert('S', 4);
     $priority_queue->insert('n', 0);
     $priority_queue->insert('m', 2);
     $result = [];
     foreach ($priority_queue as $value) {
         $result[] = $value;
     }
     assert_that(implode($result))->is_identical_to(__);
 }
开发者ID:mtvillwock,项目名称:php-inferno,代码行数:14,代码来源:Fraud.php

示例14: process

 public function process(ContainerBuilder $container)
 {
     if (false === $container->hasDefinition('profiler')) {
         return;
     }
     $definition = $container->getDefinition('profiler');
     $collectors = new \SplPriorityQueue();
     $order = PHP_INT_MAX;
     foreach ($container->findTaggedServiceIds('data_collector') as $id => $attributes) {
         $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
         $template = null;
         if (isset($attributes[0]['template'])) {
             if (!isset($attributes[0]['id'])) {
                 throw new \InvalidArgumentException(sprintf('Data collector service "%s" must have an id attribute in order to specify a template', $id));
             }
             $template = array($attributes[0]['id'], $attributes[0]['template']);
         }
         $collectors->insert(array($id, $template), array($priority, --$order));
     }
     $templates = array();
     foreach ($collectors as $collector) {
         $definition->addMethodCall('add', array(new Reference($collector[0])));
         $templates[$collector[0]] = $collector[1];
     }
     $container->setParameter('data_collector.templates', $templates);
 }
开发者ID:skelpo,项目名称:framework,代码行数:26,代码来源:ProfilerPass.php

示例15: 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


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