createOrderedMap() public method

Keys can only be associated with a single value and such if the iterator returns duplicate keys the last respective value will be used.
public createOrderedMap ( Traversable $iterator = null ) : Pinq\Iterators\IOrderedMap
$iterator Traversable
return Pinq\Iterators\IOrderedMap
Ejemplo n.º 1
0
 /**
  * @dataProvider orderedMaps
  */
 public function testThatOffsetSetWithNoKeyAppendsWithNextLargestIntGreaterThanOrEqualToZero(IOrderedMap $orderedMap, IIteratorScheme $scheme)
 {
     $orderedMap = $scheme->createOrderedMap($scheme->arrayIterator([-5 => 'foo']));
     $orderedMap[] = 'bar';
     $orderedMap[7] = 'baz';
     $orderedMap[] = 'qux';
     $this->assertSame('foo', $orderedMap->get(-5));
     $this->assertSame('bar', $orderedMap->get(0));
     $this->assertSame('baz', $orderedMap->get(7));
     $this->assertSame('qux', $orderedMap->get(8));
     $orderedMap->remove(8);
     $this->assertFalse($orderedMap->contains(8));
     $orderedMap[] = 'qux1';
     $this->assertSame('qux1', $orderedMap->get(8));
     $orderedMap->remove(8);
     $orderedMap->remove(7);
     $orderedMap[] = 'boo';
     $this->assertSame('boo', $orderedMap->get(1));
 }
Ejemplo n.º 2
0
 /**
  * @return Iterators\IOrderedMap
  */
 protected function asOrderedMap()
 {
     return $this->elements instanceof Iterators\IOrderedMap ? $this->elements : $this->scheme->createOrderedMap($this->elements);
 }