Пример #1
0
 private function nextTick()
 {
     $this->future->rewind();
     while ($this->future->valid() && ($task = $this->future->current())) {
         if (!$task->isBlocked() || !$task->isStarted()) {
             $this->tick->enqueue($task);
             $this->future->offsetUnset($this->future->key());
             $this->future->prev();
         }
         $this->future->next();
     }
 }
 /**
  * Removes a maintenance task entry from the maintenance task list
  * @param $maintenanceTaskEntryIdentifier   Remove entry with this identifier
  * @return bool                             Result of attempted removal
  * @throws InvalidArgumentException         if the provided argument is not set or of correct type
  */
 public function removeMaintenanceTaskEntry($maintenanceTaskEntryIdentifier)
 {
     if (!isset($maintenanceTaskEntryIdentifier)) {
         //argument check
         throw new InvalidArgumentException("Missing Argument");
     } else {
         if (!is_numeric($maintenanceTaskEntryIdentifier)) {
             //argument check
             throw new InvalidArgumentException("maintenanceTaskEntryIdentifier is not a number");
         }
     }
     if ($this->maintenanceTaskList->isEmpty()) {
         //if list is empty, nothing to remove
         return false;
     } else {
         if ($this->retrieveMaintenanceTaskEntry($maintenanceTaskEntryIdentifier) != null) {
             $this->maintenanceTaskList->offsetUnset($this->maintenanceTaskList->key());
             //remove from list
             return true;
             //return true, success
         } else {
             return false;
         }
     }
     //if entry was not found, return false
 }
Пример #3
0
 /**
  * Look for the node in the list and remove it
  *
  * @param Node $node
  */
 public function removeChild(Node $node)
 {
     foreach ($this->children as $key => $child) {
         if ($child !== $node) {
             continue;
         }
         $this->children->offsetUnset($key);
         break;
     }
 }
Пример #4
0
// isEmpty()
// 判断该链表是否为空链表,返回bool
$list->isEmpty();
// offsetExists($index)
// 判断参索引是否存在,返回bool
$list->offsetExists(2);
// 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()
Пример #5
0
 $e = microtime(true);
 echo "Count: " . count($array) . "\n";
 echo "Elapsed time: " . ($e - $s) . " sec.\n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 unset($array);
 echo "\n-- SplDoublyLinkedList \n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 $s = microtime(true);
 $spl = new SplDoublyLinkedList();
 for ($i = 0; $i < $v; $i++) {
     $spl->push($i);
 }
 try {
     $spl->offsetUnset(102);
     var_dump($spl->offsetGet(100));
     var_dump($spl->offsetGet(102));
 } catch (OutOfRangeException $e) {
     echo $e;
 }
 $e = microtime(true);
 echo "Count: " . $spl->count() . "\n";
 echo "Elapsed time: " . ($e - $s) . " sec.\n";
 echo "Mem usage: " . __convert(memory_get_usage()) . "\n";
 echo "Mem real: " . __convert(memory_get_usage(true)) . "\n";
 try {
     for ($i = 0; $i < $v; $i++) {
         $spl->pop();
     }
 } catch (Exception $e) {
Пример #6
0
 /**
  * @see \ArrayAccess::offsetUnset()
  * @param int $offset
  */
 public function offsetUnset($offset)
 {
     $offset = count($this) + $offset;
     parent::offsetUnset($offset);
 }
<?php

// Create a new Doubly Linked List
$dll = new SplDoublyLinkedList();
// Add some items to the list
$dll->push(1);
$dll->push(2);
$dll->push(3);
try {
    $dll->offsetUnset(-1);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
<?php

$ll = new SplDoublyLinkedList();
$ll->push('1');
$ll->push('2');
$ll->push('3');
try {
    $ll->offsetUnset($ll->count() + 1);
    var_dump($ll);
} catch (Exception $e) {
    echo $e->getMessage();
}
<?php

$list = new SplDoublyLinkedList();
$list->push('oh');
$list->push('hai');
$list->push('thar');
$list->offsetUnset(0);
var_dump($list);
<?php

// Create a new Doubly Linked List
$dll = new SplDoublyLinkedList();
// Add some items to the list
$dll->push(1);
$dll->push(2);
$dll->push(3);
try {
    $dll->offsetUnset(3);
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}
<?php

$list = new SplDoublyLinkedList();
$list->push('oh');
$list->push('hai');
$list->push('thar');
$list->offsetUnset(2);
var_dump($list);