本文整理汇总了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);
}
示例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();
}
}
示例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');
}
示例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'];
}
示例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;
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
}
示例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===
示例10: clearAllTimer
/**
* @see Events\EventInterface::clearAllTimer()
*/
public function clearAllTimer()
{
$this->_scheduler = new \SplPriorityQueue();
$this->_scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$this->_task = array();
}
示例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());
}
示例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;
}
}
}
示例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;
示例14: SplPriorityQueue
<?php
$sp = new SplPriorityQueue();
$sp->setExtractFlags(1, 1);
// Should throw a warning as setExtractFlags expects only 1 argument
示例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);
}