本文整理汇总了PHP中SplDoublyLinkedList::offsetGet方法的典型用法代码示例。如果您正苦于以下问题:PHP SplDoublyLinkedList::offsetGet方法的具体用法?PHP SplDoublyLinkedList::offsetGet怎么用?PHP SplDoublyLinkedList::offsetGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplDoublyLinkedList
的用法示例。
在下文中一共展示了SplDoublyLinkedList::offsetGet方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process($index, \SplDoublyLinkedList $list)
{
$first = $list->offsetGet($index - 1);
$second = $list->offsetGet($index + 1);
$result = $first * $second;
$list->offsetSet($index - 1, $result);
unset($list[$index]);
unset($list[$index]);
}
示例2: process
public function process($index, \SplDoublyLinkedList $list)
{
$first = $list->offsetGet($index - 1);
$second = $list->offsetGet($index + 1);
if ($second == 0) {
throw new \Exception('zero division error');
}
$result = $first / $second;
$list->offsetSet($index - 1, $result);
unset($list[$index]);
unset($list[$index]);
}
示例3: valid
/**
* Returns whether or not the iterator has more elements
*
* @return bool
*/
public function valid()
{
if ($this->_buffer->offsetExists($this->_index)) {
$current = $this->_buffer->offsetGet($this->_index);
$this->_current = $current['value'];
$this->_key = $current['key'];
return true;
}
$valid = parent::valid();
if ($valid) {
$this->_current = parent::current();
$this->_key = parent::key();
$this->_buffer->push(['key' => $this->_key, 'value' => $this->_current]);
}
$this->_finished = !$valid;
return $valid;
}
示例4: test
function test(SplDoublyLinkedList $l)
{
$l->push("a");
$l->push("b");
$l->push("c");
echo "Foreach:", PHP_EOL;
foreach ($l as $key => $val) {
echo $key, '=>', $val, PHP_EOL;
}
echo PHP_EOL;
echo "ArrayAccess:", PHP_EOL;
var_dump($l[0]);
var_dump($l[1]);
var_dump($l[2]);
echo PHP_EOL;
echo "ArrayAccess Set:", PHP_EOL;
$l[2] = "two";
var_dump($l[2]);
try {
$l[3] = "five";
// 3 would be the next element
} catch (OutOfRangeException $e) {
echo "OutOfRangeException caught", PHP_EOL;
}
echo PHP_EOL;
echo "ArrayAccess Exists:", PHP_EOL;
var_dump(isset($l[0]), isset($l[2]), isset($l[3]));
// true, true, false
echo PHP_EOL;
echo "ArrayAccess Unset:", PHP_EOL;
unset($l[0]);
var_dump($l->offsetGet(0));
echo PHP_EOL;
echo "Foreach:", PHP_EOL;
foreach ($l as $key => $val) {
echo $key, '=>', $val, PHP_EOL;
}
echo PHP_EOL;
}
示例5:
$list->next();
// prev()
// 指针移到上一个节点, 如果原本指针在第一个,那么前一个节点为-1,并且将无法获得当前值
$list->prev();
// valid()
// 判断该链表是否有更多的值,返回bool
$list->valid();
// 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()
// 将链表的第一个移除
示例6: count
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) {
}
示例7: offsetGet
/**
* @see \ArrayAccess::offsetGet()
* @param int $offset
* @return \BitWasp\Buffertools\BufferInterface
*/
public function offsetGet($offset)
{
$offset = count($this) + $offset;
return parent::offsetGet($offset);
}
示例8: offsetGet
public function offsetGet($index)
{
return $this->_frames->offsetGet($index);
}
示例9: SplDoublyLinkedList
<?php
$dll = new SplDoublyLinkedList();
$dll->push(1);
$dll->push(2);
var_dump($dll->offsetGet());
示例10: SplDoublyLinkedList
<?php
$array = new SplDoublyLinkedList();
$get = $array->offsetGet('fail');
示例11: SplDoublyLinkedList
<?php
$array = new SplDoublyLinkedList();
$get = $array->offsetGet();
示例12: process
private function process($index, \SplDoublyLinkedList $list)
{
$operator = $list->offsetGet($index);
if (!isset(static::$operandsClasses[$operator])) {
throw new \Exception('Unknown operator:' . $operator);
}
return static::$operandsClasses[$operator]->process($index, $list);
}
示例13: SplDoublyLinkedList
<?php
$array = new SplDoublyLinkedList();
$get = $array->offsetGet(array('fail'));