| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This file is part of the ramsey/collection library |
| 5 |
* |
| 6 |
* For the full copyright and license information, please view the LICENSE |
| 7 |
* file that was distributed with this source code. |
| 8 |
* |
| 9 |
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 |
* @license http://opensource.org/licenses/MIT MIT |
| 11 |
*/ |
| 12 |
declare (strict_types=1); |
| 13 |
namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection; |
| 14 |
|
| 15 |
/** |
| 16 |
* This class contains the basic implementation of a collection that does not |
| 17 |
* allow duplicated values (a set), to minimize the effort required to implement |
| 18 |
* this specific type of collection. |
| 19 |
* |
| 20 |
* @template T |
| 21 |
* @extends AbstractCollection<T> |
| 22 |
*/ |
| 23 |
abstract class AbstractSet extends AbstractCollection |
| 24 |
{ |
| 25 |
public function add(mixed $element) : bool |
| 26 |
{ |
| 27 |
if ($this->contains($element)) { |
| 28 |
return \false; |
| 29 |
} |
| 30 |
// Call offsetSet() on the parent instead of add(), since calling |
| 31 |
// parent::add() will invoke $this->offsetSet(), which will call |
| 32 |
// $this->contains() a second time. This can cause performance issues |
| 33 |
// with extremely large collections. For more information, see |
| 34 |
// https://github.com/ramsey/collection/issues/68. |
| 35 |
parent::offsetSet(null, $element); |
| 36 |
return \true; |
| 37 |
} |
| 38 |
public function offsetSet(mixed $offset, mixed $value) : void |
| 39 |
{ |
| 40 |
if ($this->contains($value)) { |
| 41 |
return; |
| 42 |
} |
| 43 |
parent::offsetSet($offset, $value); |
| 44 |
} |
| 45 |
} |
| 46 |
|