本文整理汇总了PHP中SplFixedArray::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFixedArray::getSize方法的具体用法?PHP SplFixedArray::getSize怎么用?PHP SplFixedArray::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFixedArray
的用法示例。
在下文中一共展示了SplFixedArray::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: appendItems
/**
* {@inheritdoc}
*/
public function appendItems(array $items)
{
$size = $this->items->getSize();
$amount = count($items);
$this->items->setSize($size + $amount);
for ($i = 0; $i < $amount; $i++) {
$this->items[$size + $i] = $items[$i];
}
$this->setCurrentPosition($this->items->getSize() - 1);
}
示例2: attach
/**
* Attach other object to be executed in batch mode (make only one system call e.g. shell>cmd && cmd1 && cmdx)
*
* @param FFMpegThumbnailer $fft
* @return FFMpegThumbnailer Fluent interface
*/
public function attach(FFMpegThumbnailer $fft)
{
$size = $this->attaches->getSize();
$this->attaches->setSize(++$size);
$this->attaches[--$size] = $fft;
return $this;
}
示例3: _setObjectDataForIndex
/**
* Sets the Document instance at the given index
*
* @param DocumentInterface $object
* @param int $index
* @return \Cundd\PersistentObjectStore\Domain\Model\DocumentInterface Returns the given object
*/
protected function _setObjectDataForIndex($object, $index)
{
if ($index >= $this->objectData->getSize()) {
throw new InvalidIndexException("Index {$index} out of range", 1413712508);
}
$this->objectData[$index] = $object;
return $object;
}
示例4: next
/**
* {@inheritdoc}
*/
public function next()
{
if ($this->currentPosition == -1) {
throw new \LogicException('Cannot fetch an item from empty bag.');
}
if ($this->currentPosition == 0) {
$this->currentPosition = $this->items->getSize() - 1;
return $this->items[0];
}
$maxOffset = $this->currentPosition;
$randomOffset = (int) ($this->generator->next() * $maxOffset);
$item = $this->items[$randomOffset];
if ($randomOffset < $maxOffset) {
$this->items[$randomOffset] = $this->items[$this->currentPosition];
$this->items[$this->currentPosition] = $item;
}
$this->currentPosition--;
return $item;
}
示例5: storageResize
/**
* Resize the underlying storage, only resize when necessary. When resizing
* we allocate more than newsize, to avoid resizing each item being added.
*
* @param int $newsize
* @return void
*/
private function storageResize($newsize)
{
$allocated = $this->items->getSize();
if ($allocated >= $newsize && $newsize >= $allocated >> 1) {
$this->size++;
return;
}
$newAllocated = ($newsize >> 3) + ($newsize < 9 ? 3 : 6);
if ($newAllocated > PHP_INT_MAX - $newsize) {
throw new \RuntimeException(sprintf('Trying to allocated too big array'));
} else {
$newAllocated += $newsize;
}
if ($newsize == 0) {
$newAllocated = 0;
}
$this->items->setSize($newAllocated);
$this->size++;
}
示例6: select
/**
* @param string $statement SQL SELECT query
* @param array $params OPTIONAL Params for query
* @param bool $compressResult Return SplFixedArray instead of usual array
* @return array | \SplFixedArray
* @throws DBException
*/
public function select($statement, array $params = null, $compressResult = false)
{
try {
$query = $this->dbinstance->prepare($statement);
$result = $query->execute($params);
$this->rowsSelected = $query->rowCount();
if ($result) {
if (!$compressResult) {
return $query->fetchAll(\PDO::FETCH_ASSOC);
} else {
// Default result compressing operation
// using incremental raise of array size.
// By default it's not will double the
// array size, but make incremental grow
$return = new \SplFixedArray(2000);
$i = 0;
$k = 0;
while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {
$return[$k] = $row;
$i++;
$k++;
if ($i > 1999) {
$i = 0;
$oldIndex = $return->getSize();
$return->setSize($oldIndex + 2000);
}
}
$return->setSize($k);
return $return;
}
} else {
throw new DBReadException("Data read was failed", 404, $query->errorInfo(), $query->errorCode());
}
} catch (\PDOException $e) {
throw new DBReadException("Data read was failed", 500, $e->getMessage(), $e->getCode());
}
}
示例7: filter
/**
* Applies array_filter to internal collection, returns new instance with resulting values.
*
* @link http://www.php.net/manual/en/function.array-filter.php
*
* Inspired by:
*
* @link http://www.doctrine-project.org/api/common/2.3/source-class-Doctrine.Common.Collections.ArrayCollection.html#377-387
*
* @param callable $func
* @throws \InvalidArgumentException
* @return \DCarbone\AbstractFixedCollectionPlus
*/
public function filter($func = null)
{
$new = new static(parent::getSize());
$newSize = 0;
if (null === $func) {
foreach ($this as $i => $v) {
if ($v) {
$new[$newSize++] = $v;
}
}
} else {
if (is_callable($func, false, $callable_name)) {
// If this is a method on an object (except for \Closure), parse and continue
if (strpos($callable_name, '::') !== false && strpos($callable_name, 'Closure') === false) {
$exp = explode('::', $callable_name);
foreach ($this as $i => $v) {
if ($exp[0]::$exp[1]($v)) {
$new[$newSize++] = $v;
}
}
} else {
foreach ($this as $i => $v) {
if ($func($v)) {
$new[$newSize++] = $v;
}
}
}
} else {
throw new \InvalidArgumentException(vsprintf('%s::filter - Argument 1 expected to be null or callable.', array(get_class($this))));
}
}
$new->setSize($newSize);
return $new;
}
示例8: setUrl
/**
* Add url to $mUrl
* @access public
* @static
* @param array $pArr
*/
public static function setUrl($pArr)
{
$count = self::$mUrl->getSize();
self::$mUrl->setSize($count + 1);
self::$mUrl[$count] = $pArr;
}
示例9:
$array->valid();
// rewind()
// 回到初始节点
$array->rewind();
// current()
// 获得当前节点
$array->current();
// next()
// 指针移动到下一个节点
$array->next();
// setSize(int $size)
// 重新设置阵列数组的大小
$array->setSize(10);
// getSize()
// 获得阵列数组的大小
$array->getSize();
// offsetExists(int $index)
// 判断该索引是否存在值,返回boolean
$array->offsetExists(3);
// offsetGet(int $index)
// 获得该索引对应的值
$array->offsetGet(3);
// offsetSet(int $index, mixed $value)
// 设置该索引对应的值
$array->offsetSet(6, 'value3');
// offsetUnset(int $index)
// 删除该索引对应的值
$array->offsetUnset(6);
// toArray()
// 将阵列转化成php数组
// output: Array ( [0] => [1] => 2 [2] => [3] => value2 [4] => [5] => [6] => [7] => [8] => [9] => )
示例10: count
/**
* Get number of items in the Collection
*
* @return number
*/
public function count()
{
return $this->items->getSize();
}
示例11: SplFixedArray
<?php
$fixed_array = new SplFixedArray(2);
echo "*test* " . $fixed_array->getSize(3);
示例12: SplFixedArray
<?php
$ar = new SplFixedArray(1);
echo "size: " . $ar->getSize() . "\n";
$ar->setSize(PHP_INT_SIZE == 8 ? 0x2000000000000001 : 0x40000001);
echo "size: " . $ar->getSize() . "\n";
示例13: SplFixedArray
// Initialize the array with a fixed length
$array = new SplFixedArray(5);
$array[1] = 2;
$array[4] = "foo";
echo "<pre>";
var_dump($array[0]);
// NULL
var_dump($array[1]);
// int(2)
var_dump($array["4"]);
// string(3) "foo"
echo "\n Array Count defined : " . $array->count() . "\n";
// Increase the size of the array to 10
$array->setSize(10);
// getting the array size
echo "\n getSize :" . $array->getSize() . "\n";
$array[9] = "asdf";
echo "\n Array Count increase : " . $array->count() . "\n";
// Shrink the array to a size of 2
$array->setSize(2);
echo "\n Array Count shrink : " . $array->count() . "\n";
// The following lines throw a RuntimeException: Index invalid or out of range
try {
var_dump($array["non-numeric"]);
} catch (RuntimeException $re) {
echo "RuntimeException: " . $re->getMessage() . "\n";
}
try {
var_dump($array[-1]);
} catch (RuntimeException $re) {
echo "RuntimeException: " . $re->getMessage() . "\n";
示例14: getSize
public function getSize()
{
return $this->numbers->getSize();
}
示例15: note
/**
* @param string $note
* @param int $octave
* @param number $duration
*
* @return Sample
*/
public function note($note, $octave, $duration)
{
$result = new \SplFixedArray((int) ceil($this->getSampleRate() * $duration * 2));
$octave = min(8, max(1, $octave));
$frequency = Note::get($note) * pow(2, $octave - 4);
$attack = $this->generator->getAttack($this->getSampleRate(), $frequency, $this->getVolume());
$dampen = $this->generator->getDampen($this->getSampleRate(), $frequency, $this->getVolume());
$attackLength = (int) ($this->getSampleRate() * $attack);
$decayLength = (int) ($this->getSampleRate() * $duration);
for ($i = 0; $i < $attackLength; $i++) {
$value = $this->getVolume() * ($i / ($this->getSampleRate() * $attack)) * $this->getGenerator()->getWave($this->getSampleRate(), $frequency, $this->getVolume(), $i);
$result[$i << 1] = Helper::packChar($value);
$result[($i << 1) + 1] = Helper::packChar($value >> 8);
}
for (; $i < $decayLength; $i++) {
$value = $this->getVolume() * pow(1 - ($i - $this->getSampleRate() * $attack) / ($this->getSampleRate() * ($duration - $attack)), $dampen) * $this->getGenerator()->getWave($this->getSampleRate(), $frequency, $this->getVolume(), $i);
$result[$i << 1] = Helper::packChar($value);
$result[($i << 1) + 1] = Helper::packChar($value >> 8);
}
return new Sample($result->getSize(), implode('', $result->toArray()));
}