Ejemplo n.º 1
0
 /**
  * {@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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * {@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;
 }
Ejemplo n.º 5
0
 /**
  * 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++;
 }
Ejemplo n.º 6
0
Archivo: DB.php Proyecto: xdire/dude
 /**
  * @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());
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 9
0
$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] => )
Ejemplo n.º 10
0
 /**
  * Get number of items in the Collection
  *
  * @return number
  */
 public function count()
 {
     return $this->items->getSize();
 }
<?php

$fixed_array = new SplFixedArray(2);
echo "*test* " . $fixed_array->getSize(3);
Ejemplo n.º 12
0
<?php

$ar = new SplFixedArray(1);
echo "size: " . $ar->getSize() . "\n";
$ar->setSize(PHP_INT_SIZE == 8 ? 0x2000000000000001 : 0x40000001);
echo "size: " . $ar->getSize() . "\n";
Ejemplo n.º 13
0
// 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";
Ejemplo n.º 14
0
 public function getSize()
 {
     return $this->numbers->getSize();
 }
Ejemplo n.º 15
0
 /**
  * @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()));
 }
Ejemplo n.º 16
0
 public function length()
 {
     return $this->buffer->getSize();
 }
Ejemplo n.º 17
0
    var_dump($a[1]);
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    $a[1] = 1;
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump(count($a[1]));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($a->getSize());
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    foreach ($a as $v) {
    }
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($a->setSize(10));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
echo "Done\n";
Ejemplo n.º 18
0
<?php

$fixedarr = new SplFixedArray();
echo "Errors:", PHP_EOL;
$fixedarr->setSize([]);
$fixedarr->setSize("notanint");
echo "No Error:", PHP_EOL;
$fixedarr->setSize("5");
$fixedarr->setSize("6.6");
var_dump($fixedarr->getSize() == 6);
$fixedarr->setSize(2.2);
var_dump($fixedarr->getSize() == 2);
$fixedarr->setSize(true);
var_dump($fixedarr->getSize() == 1);
// because php...
$fixedarr->setSize(false);
var_dump($fixedarr->getSize() == 0);
// because php...