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


PHP SplPriorityQueue::setExtractFlags方法代码示例

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


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

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

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

示例3: __construct

 /**
  * Class constructor
  *
  * @param array $processorConfiguration Configuration array, parsed from app/config/services.yml
  * @param KernelInterface $kernel The Symfony HttpKernel.
  */
 public function __construct(array $processorConfiguration, KernelInterface $kernel)
 {
     $this->kernel = $kernel;
     $this->interval = $processorConfiguration['interval'];
     $this->port = $processorConfiguration['port'];
     $this->host = $processorConfiguration['host'];
     $this->timeout = $processorConfiguration['timeout'];
     $this->queue = new \SplPriorityQueue();
     $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_DATA);
     $this->workers = new \SplFixedArray($processorConfiguration['workers']);
     $this->phpPath = (new PhpExecutableFinder())->find();
     $this->eventDispatcher = $kernel->getContainer()->get('event_dispatcher');
 }
开发者ID:naroga,项目名称:foreman,代码行数:19,代码来源:Processor.php

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

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

 private function findNeighbors($type, $keywords, $id)
 {
     $queue = new SplPriorityQueue();
     $queue->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
     $cursor = $this->m->websites->find([]);
     foreach ($cursor as $doc) {
         if ($doc['_id'] != new MongoId($id)) {
             $d = $this->distance($type, $keywords, $doc['type'], $doc['keywords']);
             $queue->insert($doc, $d);
         }
     }
     $res = [];
     for ($i = 0; $i < 20 && !$queue->isEmpty(); $i++) {
         $res[] = $queue->extract();
     }
     return $res;
 }
开发者ID:jbgtmartin,项目名称:rich,代码行数:17,代码来源:Controller.php

示例7: deactive

 public static function deactive(Block $source, $updateLevel)
 {
     $queue = new \SplPriorityQueue();
     $queue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
     if (!$source->isPowerSource()) {
         return;
     }
     self::addToDeactiveQueue($queue, $source, $updateLevel);
     while (!$queue->isEmpty()) {
         $ex = $queue->extract();
         $updating = $ex["data"];
         $power = $ex["priority"];
         /** @var Block $updating */
         $updating->setPowerLevel(0);
         $updating->level->setBlock($updating, $updating, true);
         self::addToDeactiveQueue($queue, $updating, $power);
     }
 }
开发者ID:robozeri,项目名称:Yuriko-MP,代码行数:18,代码来源:Redstone.php

示例8: remove

 /**
  * {@inheritdoc}
  */
 public function remove($type, $handler)
 {
     // Handle variable type errors
     if (!is_string($type)) {
         throw new Exception("Event type must be a string");
     }
     if (!is_object($handler)) {
         throw new Exception("Event handler must be an object");
     }
     // Proceed if type exists
     if (isset($this->events[$type])) {
         $priorityQueue = $this->events[$type];
         if (is_object($priorityQueue)) {
             // Create a temporary queue
             $tmpPriorityQueue = new \SplPriorityQueue();
             $tmpPriorityQueue->setExtractFlags(\SplPriorityQueue::EXTR_DATA);
             // Prepare the current queue
             $priorityQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
             $priorityQueue->top();
             // Recreate a queue without the handle
             while ($priorityQueue->valid()) {
                 $data = $priorityQueue->current();
                 $priorityQueue->next();
                 if ($data["data"] !== $handler) {
                     $tmpPriorityQueue->insert($data["data"], $data["priority"]);
                 }
             }
             // Replace the event queue with the new one
             $this->events[$type] = $tmpPriorityQueue;
         } else {
             // Search array for the handler and remove it
             if (array_search($handler, $priorityQueue, true) !== false) {
                 unset($priorityQueue[$key]);
             }
             // Replace the event queue with the new one
             $this->events[$type] = $priorityQueue;
         }
     }
 }
开发者ID:nicholasc,项目名称:blink,代码行数:42,代码来源:Manager.php

示例9: SplPriorityQueue

}
echo "EXTR_BOTH\n";
$pq1 = new SplPriorityQueue();
$pq1->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
$pq1->insert("a", 1);
$pq1->insert("b", 2);
$pq1->insert("c", 0);
foreach ($pq1 as $k => $v) {
    echo "{$k}=>" . print_r($v, 1) . "\n";
}
echo "EXTR_DATA\n";
$pq2 = new SplPriorityQueue();
$pq2->setExtractFlags(SplPriorityQueue::EXTR_DATA);
$pq2->insert("a", 1);
$pq2->insert("b", 2);
$pq2->insert("c", 0);
foreach ($pq2 as $k => $v) {
    echo "{$k}=>" . print_r($v, 1) . "\n";
}
echo "EXTR_PRIORITY\n";
$pq3 = new SplPriorityQueue();
$pq3->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
$pq3->insert("a", 1);
$pq3->insert("b", 2);
$pq3->insert("c", 0);
foreach ($pq3 as $k => $v) {
    echo "{$k}=>" . print_r($v, 1) . "\n";
}
?>
===DONE===
开发者ID:gleamingthecube,项目名称:php,代码行数:30,代码来源:ext_spl_tests_pqueue_001.php

示例10: clearAllTimer

 /**
  * @see Events\EventInterface::clearAllTimer()
  */
 public function clearAllTimer()
 {
     $this->_scheduler = new \SplPriorityQueue();
     $this->_scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
     $this->_task = array();
 }
开发者ID:hackty,项目名称:Workerman,代码行数:9,代码来源:Select.php

示例11: SplPriorityQueue

<?php

$pq = new SplPriorityQueue();
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
// This line causes extract() to return both the data and priority (in an associative array),
// Otherwise it would just return the data
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
    print_r($pq->extract());
}
开发者ID:Gecko136,项目名称:RosettaCodeData,代码行数:14,代码来源:priority-queue-1.php

示例12: detach

 public function detach($eventType, $handler)
 {
     if (!is_string($eventType) || !is_object($handler)) {
         throw new Exception("Invalid parameter!", 1);
     }
     if (isset($this->_events[$eventType])) {
         $priorityQueue = $this->_events[$eventType];
         if (is_object($priorityQueue)) {
             # 有SplPriorityQueue无法删除元素,因此我们需要创建一个新的
             $newPriorityQueue = new PriorityQueue();
             $newPriorityQueue->setExtractFlags(PriorityQueue::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);
             if ($key !== false) {
                 unset($priorityQueue[$key]);
             }
             $this->_events[$eventType] = $priorityQueue;
         }
     }
 }
开发者ID:yiqingfeng,项目名称:Phalcon-Record,代码行数:32,代码来源:Manager.php

示例13: SplPriorityQueue

<?php

$priorityQueue = new SplPriorityQueue();
var_dump($priorityQueue->getExtractFlags());
$priorityQueue->insert("a", 1);
$priorityQueue->insert("b", 2);
$priorityQueue->insert("c", 0);
echo "EXTR DEFAULT", PHP_EOL;
echo "value: ", $priorityQueue->top(), PHP_EOL;
$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
var_dump($priorityQueue->getExtractFlags() & SplPriorityQueue::EXTR_PRIORITY);
echo "EXTR_PRIORITY", PHP_EOL;
echo "priority: ", $priorityQueue->top(), PHP_EOL;
$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
echo "EXTR_BOTH", PHP_EOL;
print_r($priorityQueue->top());
echo "EXTR_DATA", PHP_EOL;
$priorityQueue->setExtractFlags(SplPriorityQueue::EXTR_DATA);
echo "value: ", $priorityQueue->top(), PHP_EOL;
开发者ID:gleamingthecube,项目名称:php,代码行数:19,代码来源:ext_spl_tests_spl_pq_top_basic.php

示例14: SplPriorityQueue

<?php

$sp = new SplPriorityQueue();
$sp->setExtractFlags(1, 1);
// Should throw a warning as setExtractFlags expects only 1 argument
开发者ID:badlamer,项目名称:hhvm,代码行数:5,代码来源:splpriorityqueue_setextractflags.php

示例15: calculate_score

function calculate_score()
{
    global $score_board;
    global $TOTAL_P_SCORE;
    global $score_P_ratio;
    $qCur = new SplPriorityQueue();
    $qExpire = new SplPriorityQueue();
    $total_p_score = $TOTAL_P_SCORE;
    $multiplier = 0.01;
    $qCur->setExtractFlags(SplPriorityQueue::EXTR_DATA);
    $qExpire->setExtractFlags(SplPriorityQueue::EXTR_DATA);
    foreach ($score_board as $k => $r) {
        ///// f_score
        if (IsValidScoreboardEntry($k)) {
            $score_board[$k]["func"] = $score_board[$k]["check_pattern"] * pow(0.9, $score_board[$k]["mem_error"]);
            if ($score_board[$k]["mem_heap"] > 0) {
                $score_board[$k]["func"] *= ($score_board[$k]["mem_heap"] - $score_board[$k]["heap_lost"]) / $score_board[$k]["mem_heap"];
            }
            if ($r["priority"] > 0) {
                $qCur->insert($k, $r["priority"]);
            }
        } else {
            $score_board[$k]["func"] = 0;
        }
        ////// init p_score
        $score_board[$k]["p_score"] = 0;
    }
    while ($qCur->valid() && $total_p_score > 0) {
        while ($qCur->valid()) {
            $idx = $qCur->extract();
            $s = $score_board[$idx]["priority"] * $multiplier;
            // alloted score in the scheduling cycle
            if ($s > 100 - $score_board[$idx]["p_score"]) {
                $s = 100 - $score_board[$idx]["p_score"];
            }
            $score_board[$idx]["p_score"] += $s;
            $total_p_score -= $s;
            if ($score_board[$idx]["p_score"] < 100) {
                $qExpire->insert($idx, $score_board[$idx]["priority"]);
            }
        }
        $qCur = $qExpire;
        $qExpire = new SplPriorityQueue();
        $qExpire->setExtractFlags(SplPriorityQueue::EXTR_DATA);
    }
    foreach ($score_board as $k => $r) {
        $score_board[$k]["score"] = 100 * $score_board[$k]["func"] * (1 - $score_P_ratio + $score_board[$k]["p_score"] * $score_P_ratio / 100);
    }
    ////////sort by score
    $tmp = array();
    foreach ($score_board as &$ma) {
        $tmp[] =& $ma["score"];
    }
    array_multisort($tmp, SORT_DESC, $score_board);
}
开发者ID:senselab,项目名称:CodeSensor,代码行数:55,代码来源:CreateScoreboard_release.php


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