Example #1
0
 /**
  * {@inheritdoc}
  */
 public function enqueue($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('enqueue', $item));
     $this->list->push($item);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function add($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('add', $item));
     $this->tree->set($item, true);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function set($key, $value)
 {
     assert(Validate::isType($key, $this->keyType()), $this->keyTypeError('set', $key));
     assert(Validate::isType($value, $this->valueType()), $this->valueTypeError('set', $value));
     $hash = Hasher::hash($key);
     if (!isset($this->buckets[$hash])) {
         $this->buckets[$hash] = new TableBucketChain();
     }
     if ($this->buckets[$hash]->set($key, $value)) {
         $this->count++;
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function set($key, $value)
 {
     assert(Validate::isType($key, $this->keyType()), $this->keyTypeError('set', $key));
     assert(Validate::isType($value, $this->valueType()), $this->valueTypeError('set', $value));
     $this->tree->set($key, $value);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function push($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('push', $item));
     $index = $this->count++;
     $this->items[$index] = $item;
 }
Example #6
0
 /**
  * @dataProvider invalidTypeProvider
  */
 public function test_that_is_type_returns_false_for_invalid_value($value, $type)
 {
     $this->assertFalse(Validate::isType($value, $type));
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function add($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('add', $item));
     $hash = Hasher::hash($item);
     if (!isset($this->buckets[$hash])) {
         $this->buckets[$hash] = new SetBucketChain();
     }
     if ($this->buckets[$hash]->add($item)) {
         $this->count++;
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function set(int $index, $item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('set', $item));
     $count = count($this->items);
     if ($index < -$count || $index > $count - 1) {
         $message = sprintf('Index (%d) out of range[%d, %d]', $index, -$count, $count - 1);
         throw new IndexException($message);
     }
     if ($index < 0) {
         $index += $count;
     }
     $this->items[$index] = $item;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function addLast($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('addLast', $item));
     $this->list->push($item);
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function enqueue($item)
 {
     assert(Validate::isType($item, $this->itemType()), $this->itemTypeError('enqueue', $item));
     if ($this->count === $this->cap) {
         $this->reindex($this->cap * 2);
     }
     $index = $this->end++;
     $this->items[$index] = $item;
     if ($this->end === $this->cap) {
         $this->end = 0;
     }
     $this->count++;
 }