• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP SplPriorityQueue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了SplPriorityQueue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: process

 public function process(ContainerBuilder $container)
 {
     if ($container->hasDefinition('templating')) {
         return;
     }
     if ($container->hasDefinition('templating.engine.php')) {
         $helpers = array();
         foreach ($container->findTaggedServiceIds('templating.helper') as $id => $attributes) {
             if (isset($attributes[0]['alias'])) {
                 $helpers[$attributes[0]['alias']] = $id;
             }
         }
         $definition = $container->getDefinition('templating.engine.php');
         $arguments = $definition->getArguments();
         $definition->setArguments($arguments);
         if (count($helpers) > 0) {
             $definition->addMethodCall('setHelpers', array($helpers));
         }
     }
     if ($container->hasDefinition('templating.engine.delegating')) {
         $queue = new \SplPriorityQueue();
         foreach ($container->findTaggedServiceIds('templating.engine') as $id => $attributes) {
             $queue->insert($id, isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0);
         }
         $engines = array();
         foreach ($queue as $engine) {
             $engines[] = $engine;
         }
         $container->getDefinition('templating.engine.delegating')->addMethodCall('setEngineIds', array($engines));
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:31,代码来源:TemplatingPass.php


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


示例5: detach

 /**
  * Detach the listener from the events manager
  *
  * @param string eventType
  * @param object handler
  */
 public function detach($eventType, $handler)
 {
     if (!is_object($handler)) {
         throw new \Exception("Event handler must be an Object");
     }
     if (isset($this->_events[$eventType])) {
         if (is_object($this->_events[$eventType])) {
             // SplPriorityQueue hasn't method for element deletion, so we need to rebuild queue
             $newPriorityQueue = new PriorityQueue();
             $newPriorityQueue->setExtractFlags(\SplPriorityQueue::EXTR_DATA);
             $priorityQueue->setExtractFlags(PriorityQueue::EXTR_BOTH);
             $priorityQueue->top();
             while ($priorityQueue->valid()) {
                 $data = $priorityQueue->current();
                 $priorityQueue->next();
                 if ($data['data'] !== $handler) {
                     $newPriorityQueue->insert($data['data'], $data['priority']);
                 }
             }
             $this->_events[$eventType] = $newPriorityQueue;
         } else {
             $key = array_search($handler, $priorityQueue, true);
             if ($key !== false) {
                 unset($priorityQueue[$key]);
             }
             $this->_events[$eventType] = $priorityQueue;
         }
     }
 }
开发者ID:Bushzhao,项目名称:rvbwebsite,代码行数:35,代码来源:Manager.php


示例6: process

 /**
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  *
  * @throws \InvalidArgumentException
  */
 public function process(ContainerBuilder $container)
 {
     // configure the profiler service
     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));
             }
             if (!isset($attributes[0]['title'])) {
                 throw new \InvalidArgumentException(sprintf('Data collector service "%s" must have a title attribute', $id));
             }
             $template = [$attributes[0]['id'], $attributes[0]['template'], $attributes[0]['title']];
         }
         $collectors->insert([$id, $template], [-$priority, --$order]);
     }
     $templates = [];
     foreach ($collectors as $collector) {
         $definition->addMethodCall('add', [new Reference($collector[0])]);
         $templates[$collector[0]] = $collector[1];
     }
     $container->setParameter('data_collector.templates', $templates);
     // set parameter to store the public folder path
     $path = 'file:' . DRUPAL_ROOT . '/' . PublicStream::basePath() . '/profiler';
     $container->setParameter('data_collector.storage', $path);
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:38,代码来源:ProfilerPass.php


示例7: execute

 public function execute()
 {
     // Get the application
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_ddcbalanceit');
     if ($params->get('required_account') == 1) {
         $user = JFactory::getUser();
         if ($user->get('guest')) {
             $app->redirect('index.php', JText::_('COM_DDCBALANCEIT_ACCOUNT_REQUIRED_MSG'));
         }
     }
     // Get the document object.
     $document = JFactory::getDocument();
     $viewName = $app->input->getWord('view', 'dashboard');
     $viewFormat = $document->getType();
     $layoutName = $app->input->getWord('layout', 'default');
     $app->input->set('view', $viewName);
     // Register the layout paths for the view
     $paths = new SplPriorityQueue();
     $paths->insert(JPATH_COMPONENT . '/views/' . $viewName . '/tmpl', 'normal');
     $viewClass = 'DdcbalanceitViews' . ucfirst($viewName) . ucfirst($viewFormat);
     $modelClass = 'DdcbalanceitModels' . ucfirst($viewName);
     if (false === class_exists($modelClass)) {
         $modelClass = 'DdcbalanceitModelsDefault';
     }
     $view = new $viewClass(new $modelClass(), $paths);
     $view->setLayout($layoutName);
     // Render our view.
     echo $view->render();
     return true;
 }
开发者ID:redbluesquare,项目名称:com_ddcbalanceit,代码行数:31,代码来源:default.php


示例8: process

 public function process(ContainerBuilder $container)
 {
     $definitions = new \SplPriorityQueue();
     $order = PHP_INT_MAX;
     foreach ($container->getDefinitions() as $id => $definition) {
         if (!($decorated = $definition->getDecoratedService())) {
             continue;
         }
         $definitions->insert(array($id, $definition), array($decorated[2], --$order));
     }
     foreach ($definitions as list($id, $definition)) {
         list($inner, $renamedId) = $definition->getDecoratedService();
         $definition->setDecoratedService(null);
         if (!$renamedId) {
             $renamedId = $id . '.inner';
         }
         // we create a new alias/service for the service we are replacing
         // to be able to reference it in the new one
         if ($container->hasAlias($inner)) {
             $alias = $container->getAlias($inner);
             $public = $alias->isPublic();
             $container->setAlias($renamedId, new Alias((string) $alias, false));
         } else {
             $definition = $container->getDefinition($inner);
             $public = $definition->isPublic();
             $definition->setPublic(false);
             $container->setDefinition($renamedId, $definition);
         }
         $container->setAlias($inner, new Alias($id, $public));
     }
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:31,代码来源:DecoratorServicePass.php


示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('gremo_buzz')) {
         return;
     }
     // Build listeners queue from tagged services
     $listeners = new \SplPriorityQueue();
     foreach ($container->findTaggedServiceIds('gremo_buzz.listener') as $id => $attrs) {
         $class = $container->getDefinition($id)->getClass();
         $class = $container->getParameterBag()->resolveValue($class);
         $reflector = new \ReflectionClass($class);
         $interface = 'Buzz\\Listener\\ListenerInterface';
         // Check if the service implements the above interface
         if (!$reflector->isSubclassOf($interface)) {
             throw new InvalidArgumentException(sprintf("Service '%s' must implement '%s'.", $id, $interface));
         }
         // Add a reference to the listeners queue providing a default priority
         $listeners->insert(new Reference($id), isset($attrs[0]['priority']) ? $attrs[0]['priority'] : 0);
     }
     if (!empty($listeners)) {
         $browser = $container->getDefinition('gremo_buzz');
         // Add listeners starting from those with higher priority
         foreach ($listeners as $listener) {
             $browser->addMethodCall('addListener', array($listener));
         }
     }
 }
开发者ID:javiervivanco,项目名称:GremoBuzzBundle,代码行数:30,代码来源:AddListenersPass.php


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


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


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


示例13: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = null)
 {
     if (is_array($options) && !array_intersect(array_keys($options), array('constraints', 'stopOnError'))) {
         $options = array('constraints' => $options);
     }
     parent::__construct($options);
     // convert array of constraints into SplPriorityQueue
     if (is_array($this->constraints)) {
         $queue = new \SplPriorityQueue();
         $constraints = $this->constraints;
         $constraints = array_reverse($constraints);
         foreach ($constraints as $index => $constraint) {
             $queue->insert($constraint, $index);
         }
         $this->constraints = $queue;
     }
     if (!$this->constraints instanceof \SplPriorityQueue) {
         throw new ConstraintDefinitionException('The option "constraints" is expected to be a SplPriorityQueue in constraint ' . __CLASS__ . '.');
     }
     $constraintsCopy = $this->getConstraints();
     // set extraction mode to both priority and data
     $constraintsCopy->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
     // loop through the priority chain for options validation
     while ($constraintsCopy->valid()) {
         $constraint = $constraintsCopy->current();
         // fail if the constraint is not actually a constraint
         if (!$constraint['data'] instanceof Constraint) {
             throw new ConstraintDefinitionException('The option "constraints" (priority: ' . $constraint['priority'] . ') is not a Constraint, in ' . __CLASS__ . '.');
         }
         // move to next constraint
         $constraintsCopy->next();
     }
 }
开发者ID:markwilson,项目名称:symfony2-validator-priority-chain,代码行数:36,代码来源:PriorityChain.php


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


示例15: getEngine

 /**
  * getEngine
  *
  * @return  PhpEngine
  */
 protected function getEngine()
 {
     $engine = new PhpEngine();
     $paths = new \SplPriorityQueue();
     $paths->insert(__DIR__ . '/tmpl', 0);
     $engine->setLayout('default');
     $engine->setPaths($paths);
     return $engine;
 }
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:14,代码来源:PhpEngineTest.php


示例16: getRequestedContentTypes

 private function getRequestedContentTypes(ResponseInterface $response) : \SplPriorityQueue
 {
     preg_match_all('#(?:^|(?:, ?))(?P<type>[^/,;]+/[^/,;]+)[^,]*?(?:;q=(?P<weight>[01]\\.[0-9]+))?#uiD', $response->getContentType(), $matches);
     $types = new \SplPriorityQueue();
     foreach ($matches['type'] as $idx => $type) {
         $types->insert($type, $matches['weight'][$idx] ?: 1.0);
     }
     return $types;
 }
开发者ID:WebspotCode,项目名称:SpotApi,代码行数:9,代码来源:GeneratorBus.php


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


示例18: __construct

 /**
  * Method to instantiate the view.
  *
  * @param   JModel            $model  The model object.
  * @param   SplPriorityQueue  $paths  The paths queue.
  *
  * @since   3.2
  */
 public function __construct(JModel $model, SplPriorityQueue $paths = null)
 {
     $app = JFactory::getApplication();
     $component = JApplicationHelper::getComponentName();
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
     if (isset($paths)) {
         $paths->insert(JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName(), 2);
     }
     parent::__construct($model, $paths);
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:18,代码来源:html.php


示例19: process

 public function process(ContainerBuilder $container)
 {
     $extensions = new \SplPriorityQueue();
     foreach ($container->findTaggedServiceIds('symedit_menu.menu_extension') as $id => $tag) {
         $priority = isset($tag[0]['priority']) ? $tag[0]['priority'] : 0;
         $extensions->insert(new Reference($id), $priority);
     }
     $sortedExtensions = iterator_to_array($extensions);
     $menuProviderDefinition = $container->getDefinition('symedit_menu.provider.symedit');
     $menuProviderDefinition->replaceArgument(2, $sortedExtensions);
 }
开发者ID:symedit,项目名称:symedit,代码行数:11,代码来源:MenuExtensionCompilerPass.php


示例20: process

 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $loaders = new \SplPriorityQueue();
     foreach ($container->findTaggedServiceIds('symedit_theme.template_loader') as $id => $attributes) {
         $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
         $loaders->insert(new Reference($id), $priority);
     }
     $loaders = iterator_to_array($loaders);
     ksort($loaders);
     $container->getDefinition('symedit_theme.template.loader')->replaceArgument(0, array_values($loaders));
 }
开发者ID:symedit,项目名称:symedit,代码行数:14,代码来源:TemplateLoaderPass.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP SplQueue类代码示例发布时间:2022-05-23
下一篇:
PHP SplObjectStorage类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap