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 | 8 | 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 | 61 | public function add($element): bool |
|
60 | |||
61 | /** |
||
62 | * Returns true if the collection contains element |
||
63 | * |
||
64 | * @param mixed $element |
||
65 | * @return bool |
||
66 | */ |
||
67 | 61 | public function contains($element): bool |
|
73 | |||
74 | /** |
||
75 | * Removes all elements from a collection |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | 2 | public function clear() |
|
83 | |||
84 | /** |
||
85 | * Remove all items from this collection that don't exist in specified array |
||
86 | * |
||
87 | * Returns true if the collection was modified |
||
88 | * |
||
89 | * @param array $collection |
||
90 | * @return bool |
||
91 | */ |
||
92 | public function retainAllArray(array $collection): bool |
||
105 | |||
106 | /** |
||
107 | * Removes object if it exists |
||
108 | * |
||
109 | * Returns true if the element was removed |
||
110 | * |
||
111 | * @param mixed $element |
||
112 | * @return bool |
||
113 | */ |
||
114 | 16 | public function remove($element): bool |
|
122 | |||
123 | /** |
||
124 | * Returns an array of all elements in the collection |
||
125 | * |
||
126 | * @return array |
||
127 | */ |
||
128 | 59 | public function toArray(): array |
|
132 | |||
133 | /** |
||
134 | * Filter the collection using closure |
||
135 | * |
||
136 | * The closure will get passed each element. Returning true from the |
||
137 | * closure will include that element in the new collection. |
||
138 | * |
||
139 | * @param callable $filter |
||
140 | * @return CollectionInterface |
||
141 | */ |
||
142 | 2 | public function filter(callable $filter): CollectionInterface |
|
146 | |||
147 | /** |
||
148 | * Retrieve an external iterator |
||
149 | * |
||
150 | * @return ArrayIterator |
||
151 | */ |
||
152 | 16 | public function getIterator(): ArrayIterator |
|
156 | |||
157 | /** |
||
158 | * Return the key to use for the HashMap |
||
159 | * |
||
160 | * @param mixed $element |
||
161 | * @return mixed |
||
162 | */ |
||
163 | 33 | protected function getKey($element) |
|
167 | } |
||
168 |