Beispiel #1
0
 /**
  * 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);
 }
 /**
  * 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
 }
Beispiel #3
0
 /**
  * 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);
 }
<?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);
}
Beispiel #5
0
// 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()) {
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());
Beispiel #7
0
 /**
  * Prepend cell
  * 
  * @param Cell $cell
  */
 public function prependCell(Cell $cell)
 {
     $cell->setRow($this);
     $this->cells->unshift($cell);
 }
 /**
  * {@inheritdoc}
  */
 public function prependHandler($handler)
 {
     $this->checkHandler($handler);
     $this->handlers->unshift($handler);
 }
Beispiel #9
0
 /**
  * Prepend cell
  * 
  * @param Cell $cell
  */
 public function prependCell(Cell $cell)
 {
     $this->cells->unshift($cell);
 }
// 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";
?>
<?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";
<?php

$dll = new SplDoublyLinkedList();
var_dump($dll->unshift());
<?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;
Beispiel #14
0
    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));
Beispiel #15
0
 /**
  * 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);
 }