本文整理汇总了PHP中Queue::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::isEmpty方法的具体用法?PHP Queue::isEmpty怎么用?PHP Queue::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::isEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resume
public static function resume($coroutine)
{
$wrapCurrent = true;
$coKey = $coroutine->key();
if ($coKey && in_array($coKey, self::$_ioQueue)) {
//io中断,执行队列不为空则将当前协程入栈
if (!Queue::isEmpty($coKey)) {
Queue::push($coKey, $coroutine);
$wrapCurrent = false;
}
}
if ($wrapCurrent) {
//是否立即执行当前协程
self::wrap($coroutine);
}
}
示例2: isEmpty
}
public function isEmpty()
{
if ($this->front === null) {
return true;
} else {
return false;
}
}
public function isFull()
{
}
}
$q = new Queue(5);
// instantiates the Queue class with a maxSize attribute of 5
$q->isEmpty();
// returns true
$q->enqueue(100);
// Queue: 100
$q->rear();
// returns 100
$q->front();
// returns 100
$q->enqueue(20);
// Queue: 100, 20
$q->enqueue(2);
// Queue: 100, 20, 2
$q->dequeue();
// Queue: 20, 2
$q->enqueue(500);
// Queue: 20, 2, 500
示例3: formCluster
/**
* Forms the clusters by removing maximum weighted edges.
* performs breadth-first search to cluster the recipes.
*
* @param int $k queue size
* @param int $size number of recipes.
* @return array $cluster clusters of recipes.
*/
function formCluster($k, $size)
{
$this->cluster_heap->top();
$nodeQueue = new Queue($k);
$cluster_count = $size * CLUSTER_RATIO;
$cluster = array();
/*
Idea remove $cluster_count many weightiest edges from tree
to get a forest. As do this add to queue end points of
removed edges.
*/
for ($j = 0; $j < $cluster_count - 1; $j++) {
$max_edge = $this->cluster_heap->extract();
$cluster1_start = $max_edge->getStartVertex()->getLabel();
$cluster2_start = $max_edge->getEndVertex()->getLabel();
$this->adjMatrix[$cluster1_start][$cluster2_start] = -1;
$this->adjMatrix[$cluster2_start][$cluster1_start] = -1;
$nodeQueue->enqueue($cluster1_start);
$nodeQueue->enqueue($cluster2_start);
}
$queue = new Queue($k);
$i = 0;
// Now use Queue above to make clusters (trees in resulting forest)
while (!$nodeQueue->isEmpty()) {
$node = $nodeQueue->dequeue();
if ($this->vertices[$node]->isVisited() == false) {
$this->vertices[$node]->visited();
$cluster[$i][] = $this->vertices[$node]->getLabel();
$queue->enqueue($this->vertices[$node]->getLabel());
while (!$queue->isEmpty()) {
$node = $queue->dequeue();
while (($nextnode = $this->getNextVertex($node)) != -1) {
$this->vertices[$nextnode]->visited();
$cluster[$i][] = $this->vertices[$nextnode]->getLabel();
$queue->enqueue($this->vertices[$nextnode]->getLabel());
}
}
}
$i++;
}
return $cluster;
}
示例4: print
}
}
public function print()
{
echo "Queue: ";
$current = $this->front;
while ($current) {
echo $current->value . ", ";
$current = $current->next;
}
echo "<br>";
}
}
$q = new Queue(5);
// instantiates the Queue class with a maxSize attribute of 5
echo $q->isEmpty() . "<br>";
// returns true
$q->enqueue(100);
// Queue: 100
echo $q->rear() . "<br>";
// returns 100
echo $q->front() . "<br>";
// returns 100
$q->enqueue(20);
// Queue: 100, 20
$q->enqueue(2);
// Queue: 100, 20, 2
$q->dequeue();
// Queue: 20, 2
$q->enqueue(500);
// Queue: 20, 2, 500