本文整理汇总了PHP中SplPriorityQueue::count方法的典型用法代码示例。如果您正苦于以下问题:PHP SplPriorityQueue::count方法的具体用法?PHP SplPriorityQueue::count怎么用?PHP SplPriorityQueue::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplPriorityQueue
的用法示例。
在下文中一共展示了SplPriorityQueue::count方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例3: 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'];
}
示例4: findNearestAttributesBruteForce
private function findNearestAttributesBruteForce(ElementInterface $query, array $dataSet, $count = 1)
{
$smallestDistance = INF;
$nearestElement = NULL;
$cycles = 0;
$nearestElsQueue = new \SplPriorityQueue();
$nearestElements = array();
foreach ($dataSet as $element) {
$distance = $this->node->distance($query, $element);
if ($distance < $smallestDistance) {
$smallestDistance = $distance;
$nearestElement = $element;
}
$priority = 1 / (1 + $distance);
$nearestElsQueue->insert($element, $priority);
$cycles++;
}
while ($count > 0 && $nearestElsQueue->count() > 0) {
$nearestElements[] = $nearestElsQueue->extract();
$count--;
}
return new \ArrayObject(array('distance' => $smallestDistance, 'element' => $nearestElement, 'elements' => $nearestElements, 'cycles' => $cycles));
}
示例5: cleanup
protected function cleanup(OutputInterface $output)
{
// Recursive directory iterator
$dir_it = function ($dir) {
return new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
};
// Recursive directory deletion
$rmdir = function ($dir) use(&$dir_it) {
foreach ($dir_it($dir) as $file) {
if ($file->isLink()) {
unlink($file->getPathname());
} elseif ($file->isDir()) {
rmdir($file->getPathname());
} else {
unlink($file->getPathname());
}
}
rmdir($dir);
};
$further_cleanup_required = FALSE;
$release_folder = $this->getReleaseDirectory();
$distributions = array_keys($this->getConfig('distribution_info'));
// First, release directory cleanup
foreach (new \DirectoryIterator($release_folder) as $file) {
if ($file->isDot() || !$file->isDir() || $file->isLink()) {
continue;
}
// Remove distributions which no longer exist (have been removed from the config file).
if (!in_array($file->getBasename(), $distributions)) {
$rmdir($file->getPathname());
$further_cleanup_required = TRUE;
} else {
// Clean up timestamped release directories within each distribution.
// The number to keep is specified by --dirs
$directories = new \SplPriorityQueue();
foreach (new \DirectoryIterator($file->getPathname()) as $dir) {
if ($dir->isDot() || !$dir->isDir() || $dir->isLink()) {
continue;
}
// Store directories keeping the last modified at the top.
$directories->insert($dir->getPathname(), $dir->getCTime());
}
// No further action is required for this directory.
if ($directories->count() <= $this->dirs) {
continue;
}
$further_cleanup_required = TRUE;
// Timestamped release directories we want to keep
for ($i = 0; $i < $this->dirs; $i++) {
$directories->extract();
}
// Delete all the others
$directories->top();
while ($directories->valid()) {
$dir = $directories->current();
$rmdir($dir);
$directories->next();
}
}
}
// No release directories were removed so no need to do any further cleanup.
// (all other assets should be in use)
if (FALSE == $further_cleanup_required) {
return FALSE;
}
// Get a list of all assets that are in use (in use counts as being linked to
// from a releases directory).
$find_symlinks = function ($dir) use(&$dir_it) {
$active_symlinks = [];
foreach ($dir_it($dir) as $file) {
// Ignore latest folder symlink
if ($file->getBasename() != 'latest' && $file->isLink()) {
$active_symlinks[] = basename($file->getRealPath());
}
}
return array_unique($active_symlinks);
};
// Find all assets that are in use
$active_symlinks = $find_symlinks($release_folder);
// Get a list of all assets that are downloaded
$downloads = [];
$base_download_dir = $this->getBaseDownloadDirectory();
$d_it = new \DirectoryIterator($base_download_dir);
foreach ($d_it as $file) {
if (!$file->isDot() && $file->isDir()) {
$downloads[] = $file->getBasename();
}
}
// Calculate which asset folders need to be removed from the downloads directory.
$to_delete = array_diff($downloads, $active_symlinks);
if (!empty($to_delete)) {
$assets = [];
foreach ($to_delete as $dir) {
$rmdir($base_download_dir . '/' . $dir);
$parts = explode('-', $dir);
if (count($parts) == 5) {
$assets[] = $parts[1] . '-' . $parts[2] . '-' . $parts[3];
} else {
$assets[] = $parts[1] . '-' . $parts[2];
}
//.........这里部分代码省略.........
示例6: SplPriorityQueue
<?php
$h = new SplPriorityQueue();
$h->count(1);
示例7: SplPriorityQueue
<?php
$queue = new SplPriorityQueue();
$queue->insert('first', 1);
$queue->insert('second', 2);
$queue->insert('third', 3);
$clone = clone $queue;
echo "Queue items: " . $queue->count() . PHP_EOL;
echo "Clone items: " . $clone->count() . PHP_EOL;
echo "Queue:" . PHP_EOL;
for ($i = 0; $i < 3; $i++) {
echo ' ' . $queue->extract() . PHP_EOL;
}
echo "Queue items: " . $queue->count() . PHP_EOL;
echo "Clone items: " . $clone->count() . PHP_EOL;
echo "Clone:" . PHP_EOL;
for ($i = 0; $i < 3; $i++) {
echo ' ' . $clone->extract() . PHP_EOL;
}
示例8: count
/**
* {@inheritdoc}
*/
public function count()
{
return $this->queue->count();
}
示例9: count
/**
* Returns the number of listeners in this queue.
*
* @return int
*/
public function count()
{
return $this->innerQueue->count();
}
示例10: extractNearestByCount
private function extractNearestByCount(\SplPriorityQueue $elementsQueue, $count)
{
if ($count == 1) {
return array($elementsQueue->extract()->getElement());
}
$elementsArray = array();
while ($count > 0 && $elementsQueue->count() > 0) {
$node = $elementsQueue->extract();
if ($node->isLeaf()) {
$elementsArray[] = $node->getElement();
$count--;
}
}
return $elementsArray;
}