当前位置: 首页>>代码示例>>PHP>>正文


PHP SplDoublyLinkedList::unshift方法代码示例

本文整理汇总了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);
 }
开发者ID:OPL,项目名称:Open-Power-Forms,代码行数:12,代码来源:Item.php

示例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
 }
开发者ID:matthewstyler,项目名称:php-automobile-maintenence-tracker,代码行数:27,代码来源:MaintenanceTracker.php

示例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);
 }
开发者ID:coderstephen,项目名称:blog,代码行数:20,代码来源:ArticleStore.php

示例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);
}
开发者ID:Eldahar,项目名称:PHP_Library,代码行数:20,代码来源:SplDoublyLinkedList1.php

示例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()) {
开发者ID:ray0916,项目名称:learn,代码行数:31,代码来源:splDoublyLinkedList.php

示例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());
开发者ID:zaky-92,项目名称:php-1,代码行数:31,代码来源:ext_spl_tests_dllist_001.php

示例7: prependCell

 /**
  * Prepend cell
  * 
  * @param Cell $cell
  */
 public function prependCell(Cell $cell)
 {
     $cell->setRow($this);
     $this->cells->unshift($cell);
 }
开发者ID:mikemirten,项目名称:zgrid,代码行数:10,代码来源:Row.php

示例8: prependHandler

 /**
  * {@inheritdoc}
  */
 public function prependHandler($handler)
 {
     $this->checkHandler($handler);
     $this->handlers->unshift($handler);
 }
开发者ID:autarky,项目名称:framework,代码行数:8,代码来源:ErrorHandlerManager.php

示例9: prependCell

 /**
  * Prepend cell
  * 
  * @param Cell $cell
  */
 public function prependCell(Cell $cell)
 {
     $this->cells->unshift($cell);
 }
开发者ID:mikemirten,项目名称:ConstructorCMS,代码行数:9,代码来源:Row.php

示例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";
?>
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_spl_tests_dllist_013.php

示例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";
开发者ID:daniel-ac-martin,项目名称:php-seids,代码行数:24,代码来源:SplDoublyLinkedList.php

示例12: SplDoublyLinkedList

<?php

$dll = new SplDoublyLinkedList();
var_dump($dll->unshift());
开发者ID:badlamer,项目名称:hhvm,代码行数:4,代码来源:SplDoublyLinkedList_unshift_missing_parameter.php

示例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;
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:SplDoublyLinkedList_unshift.php

示例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));
开发者ID:php-ds,项目名称:benchmarks,代码行数:31,代码来源:config.php

示例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);
 }
开发者ID:mohiva,项目名称:common,代码行数:10,代码来源:TokenStream.php


注:本文中的SplDoublyLinkedList::unshift方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。