1 | <?php |
||
18 | class HashSet extends AbstractSet |
||
19 | { |
||
20 | /** |
||
21 | * The data storage |
||
22 | * |
||
23 | * @var MapInterface |
||
24 | */ |
||
25 | protected $map; |
||
26 | |||
27 | /** |
||
28 | * Constructor |
||
29 | * |
||
30 | * Use [@see AbstractSet::add] to ensure uniqueness |
||
31 | * |
||
32 | * @param array $elements |
||
33 | */ |
||
34 | 7 | public function __construct(array $elements = null) |
|
42 | |||
43 | /** |
||
44 | * Adds the element to the collection if it doesn't exist |
||
45 | * |
||
46 | * @param mixed $element |
||
47 | * @return bool |
||
48 | */ |
||
49 | 33 | public function add($element): bool |
|
59 | |||
60 | /** |
||
61 | * Removes all elements from a collection |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | 1 | public function clear() |
|
69 | |||
70 | /** |
||
71 | * Removes object if it exists |
||
72 | * |
||
73 | * Returns true if the element was removed |
||
74 | * |
||
75 | * @param mixed $element |
||
76 | * @return bool |
||
77 | */ |
||
78 | 8 | public function remove($element): bool |
|
85 | |||
86 | /** |
||
87 | * Returns an array of all elements in the collection |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 34 | public function toArray(): array |
|
95 | |||
96 | /** |
||
97 | * Filter the collection using closure |
||
98 | * |
||
99 | * The closure will get passed each element. Returning true from the |
||
100 | * closure will include that element in the new collection. |
||
101 | * |
||
102 | * @param callable $filter |
||
103 | * @return CollectionInterface |
||
104 | */ |
||
105 | 1 | public function filter(callable $filter): CollectionInterface |
|
109 | |||
110 | /** |
||
111 | * Retrieve an external iterator |
||
112 | * |
||
113 | * @return ArrayIterator |
||
114 | */ |
||
115 | 8 | public function getIterator(): ArrayIterator |
|
119 | } |
||
120 |