本文整理汇总了PHP中SplDoublyLinkedList::unshift方法的典型用法代码示例。如果您正苦于以下问题:PHP SplDoublyLinkedList::unshift方法的具体用法?PHP SplDoublyLinkedList::unshift怎么用?PHP SplDoublyLinkedList::unshift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplDoublyLinkedList
的用法示例。
在下文中一共展示了SplDoublyLinkedList::unshift方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prependListener
/**
* Prepends the new listener to the list of item listeners.
*
* @param Opf_EventListener $listener The listener.
*/
public function prependListener(Opf_EventListener $listener)
{
if ($this->_listeners === null) {
$this->_listeners = new SplDoublyLinkedList();
}
$this->_listeners->unshift($listener);
}
示例2: addMaintenanceTaskEntry
/**
* Adds a new maintenance task entry to the maintenance task entry list
* @param $maintenanceTaskEntry The entry to add
* @return bool If the addition was successful
* @throws InvalidArgumentException if the provided argument is not set or of correct type
*/
public function addMaintenanceTaskEntry($maintenanceTaskEntry)
{
if (!isset($maintenanceTaskEntry)) {
//argument check
throw new InvalidArgumentException("Missing Argument");
} else {
if (!is_a($maintenanceTaskEntry, MaintenanceTaskEntry::class)) {
throw new InvalidArgumentException("Maintenance Task Entry is not of the right class");
}
}
//argument check
if ($this->retrieveMaintenanceTaskEntry($maintenanceTaskEntry->getTaskEntryIdentifier()) == null) {
$this->maintenanceTaskList->unshift($maintenanceTaskEntry);
//task not found, add to list
return true;
//successful
} else {
return false;
}
//task was found already to be list already
}
示例3: getIterator
/**
* Gets an iterator that iterates over each article.
*
* This list is never cached.
*
* @param bool $unpublished Whether articles not yet published should be fetched.
*/
public function getIterator($unpublished = false) : \Iterator
{
$articles = new \SplDoublyLinkedList();
foreach (new \GlobIterator($this->path . '/*.md') as $file) {
if ($file->isFile()) {
$article = $this->getArticleFromFile($file->getFilename());
if ($unpublished || !$article->date()->isFuture()) {
$articles->unshift($article);
}
}
}
return new \IteratorIterator($articles);
}
示例4: SplDoublyLinkedList
<?php
/**
* Láncolt lista
*
* Sorrendezett lista készítésére
*/
$list = new SplDoublyLinkedList();
# Sorban belerakja
$list->push(1);
$list->push(2);
$list->push(3);
$list->push(4);
# az elejére rakja
$list->unshift(5);
$list->unshift(6);
$list->unshift(7);
foreach ($list as $key => $value) {
echo sprintf("%s => %s\n", $key, $value);
}
示例5:
// offsetGet($index)
// 返回参数索引的节点值
$list->offsetGet(2);
// offsetSet($index, $newValue)
// 设置参数索引的节点值, $index必须在链表的键范围中。
// 当一个节点用offsetUnset删掉时时,并不能用offsetSet重新给已删掉的节点设置值,只能对当前可见的节点的值进行修改
$list->offsetSet(3, 'value6');
// offsetUnset($index)
// 删除参数索引的节点
$list->offsetUnset(3);
// add($index, $value);
// 对指定的索引新增一个新值。 当一个节点用offsetUnset时,并没有直接删除,该节点还仍然会保存在内存中。用add可以重新给该节点设置值
$list->add(3, 'first');
// unshift($value)
// 在链表的开始节点插入value作为新的开始节点
$list->unshift('second');
// shift()
// 将链表的第一个移除
$list->shift();
// setIteratorMode(int $mode)
// 设置链表的模式。等价于下面的情况:
// IT_MODE_LIFO: 栈模式,先进后出;IT_MODE_FIFO:队列模式,先进先出
// IT_MODE_DELETE; IT_MODE_KEEP
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
// getIteratorMode()
// 获得链表的模式
$list->getIteratorMode();
echo "example: \n";
echo "FIFO (First In First Out): \n";
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($list->rewind(); $list->valid(); $list->next()) {
示例6: count
try {
$dll->pop();
} catch (RuntimeException $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
try {
$dll->shift();
} catch (RuntimeException $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
// data consistency
$a = 2;
$dll->push($a);
echo $dll->pop() . "\n";
$a = 2;
$dll->unshift($a);
echo $dll->shift() . "\n";
// peakable
$dll->push(1);
$dll->push(2);
echo $dll->top() . "\n";
echo $dll->bottom() . "\n";
$dll->pop();
$dll->pop();
// countable
$dll->push(NULL);
$dll->push(NULL);
echo count($dll) . "\n";
echo $dll->count() . "\n";
var_dump($dll->pop());
var_dump($dll->pop());
示例7: prependCell
/**
* Prepend cell
*
* @param Cell $cell
*/
public function prependCell(Cell $cell)
{
$cell->setRow($this);
$this->cells->unshift($cell);
}
示例8: prependHandler
/**
* {@inheritdoc}
*/
public function prependHandler($handler)
{
$this->checkHandler($handler);
$this->handlers->unshift($handler);
}
示例9: prependCell
/**
* Prepend cell
*
* @param Cell $cell
*/
public function prependCell(Cell $cell)
{
$this->cells->unshift($cell);
}
示例10: count
// errors
try {
$dll->add(2, 5);
} catch (OutOfRangeException $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
$dll->add(0, 6);
// 6
$dll->add(0, 3);
// 3 6
// Insert in the middle of the DLL
$dll->add(1, 4);
// 3 4 6
$dll->add(2, 5);
// 3 4 5 6
$dll->unshift(2);
// 2 3 5 4 6
// Insert at the beginning and end of the DLL
$dll->add(0, 1);
// 1 2 3 4 5 6
$dll->add(6, 7);
// 1 2 3 4 5 6 7
echo count($dll) . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
echo $dll->pop() . "\n";
?>
示例11: LinkedList
<?php
//==============================================================================
// PHP SEIDS: Supplementary, Easily Interchangeable Data Structures
//
// Copyright 2015, Daniel A.C. Martin
// Distributed under the MIT License.
// (See LICENSE file for details.)
//==============================================================================
define('DS_SIZE', 10000);
////////////////////////////////////////////////////////////////////////////////
use SplDoublyLinkedList as LinkedList;
// Take initial memory usage
$initial_memory = memory_get_usage();
// Build data structure
$ds = new LinkedList();
$n = 0;
while ($n++ < DS_SIZE) {
$ds->unshift(mt_rand());
}
// Calculate memory usage of data structure
$memory_usage = memory_get_usage() - $initial_memory;
// Output results
echo 'Memory usage: ' . $memory_usage . ' bytes' . "\n";
示例12: SplDoublyLinkedList
<?php
$dll = new SplDoublyLinkedList();
var_dump($dll->unshift());
示例13: SplDoublyLinkedList
<?php
$dll = new SplDoublyLinkedList();
$dll->unshift('foo');
$dll->unshift('bar');
echo $dll->shift(), PHP_EOL;
$dll->rewind();
echo $dll->current(), PHP_EOL;
$dll->prev();
echo $dll->current(), PHP_EOL;
示例14: range
global $a;
$a = range(1, $n);
}, function ($i) {
global $a;
array_unshift($a, rand());
}, function () {
global $a;
$a = null;
}], SPL_DLL => [function ($n) {
global $a;
$a = new SplDoublyLinkedList();
for (; $n--; $a[] = rand()) {
}
}, function ($i) {
global $a;
$a->unshift(rand());
}, function () {
global $a;
$a = null;
}], VECTOR => [function ($n) {
global $a;
$a = new Vector(range(1, $n));
}, function ($i) {
global $a;
$a->unshift(rand());
}, function () {
global $a;
$a = null;
}], DEQUE => [function ($n) {
global $a;
$a = new Deque(range(1, $n));
示例15: unshift
/**
* Prepends the list with an `Token`.
*
* @param Token $token The token to unshift.
* @link http://www.php.net/manual/en/spldoublylinkedlist.unshift.php
*/
public function unshift(Token $token)
{
$this->tokens->unshift($token);
}