Exemple #1
0
 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);
     }
 }
Exemple #2
0
    }
    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
Exemple #3
0
 /**
  * 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;
 }
Exemple #4
0
        }
    }
    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