Exemplo n.º 1
0
 /**
  * Insert a sub-range of another collection at a particular index.
  *
  * Inserts all elements from the range [$begin, $end), i.e. $begin is inclusive, $end is exclusive.
  *
  * @param integer                      $index    The index at which the elements are inserted, if index is a negative number the elements are inserted that far from the end of the sequence.
  * @param RandomAccessInterface+Vector $elements The elements to insert.
  * @param integer                      $begin    The index of the first element from $elements to insert, if begin is a negative number the removal begins that far from the end of the sequence.
  * @param integer                      $end|null The index of the last element to $elements to insert, if end is a negative number the removal ends that far from the end of the sequence.
  *
  * @throws Exception\IndexException if $index, $begin or $end is out of range.
  */
 public function insertRange($index, RandomAccessInterface $elements, $begin, $end = null)
 {
     if (!$elements instanceof self) {
         throw new InvalidArgumentException('The given collection is not an instance of ' . __CLASS__ . '.');
     }
     $this->validateIndex($index);
     $elements->validateIndex($begin);
     $elements->validateIndex($end, $elements->size);
     $size = $end - $begin;
     $this->shiftRight($index, $size);
     $this->size += $size;
     while ($begin !== $end) {
         $this->elements[$index++] = $elements->elements[$begin++];
     }
 }
Exemplo n.º 2
0
 /**
  * Insert a sub-range of another collection at a particular index.
  *
  * Inserts all elements from the range [$begin, $end), i.e. $begin is inclusive, $end is exclusive.
  *
  * @param integer                          $index    The index at which the elements are inserted, if index is a negative number the elements are inserted that far from the end of the sequence.
  * @param RandomAccessInterface+LinkedList $elements The elements to insert.
  * @param integer                          $begin    The index of the first element from $elements to insert, if begin is a negative number the removal begins that far from the end of the sequence.
  * @param integer                          $end|null The index of the last element to $elements to insert, if end is a negative number the removal ends that far from the end of the sequence.
  *
  * @throws Exception\IndexException if $index, $begin or $end is out of range.
  */
 public function insertRange($index, RandomAccessInterface $elements, $begin, $end = null)
 {
     if (!$elements instanceof self) {
         throw new InvalidArgumentException('The given collection is not an instance of ' . __CLASS__ . '.');
     }
     $this->validateIndex($index);
     $elements->validateIndex($begin);
     $elements->validateIndex($end, $elements->size);
     list($head, $tail, $size) = $elements->cloneNodes($elements->nodeAt($begin), null, $end - $begin);
     $this->insertNodes($index, $head, $tail, $size);
 }