1 | <?php |
||
18 | class HashMap extends AbstractMap |
||
19 | { |
||
20 | /** |
||
21 | * An array of [@see MapEntry] elements |
||
22 | * |
||
23 | * @var MapEntry[] |
||
24 | */ |
||
25 | protected $elements = []; |
||
26 | |||
27 | /** |
||
28 | * Constructor |
||
29 | * |
||
30 | * @param array $map |
||
31 | */ |
||
32 | 15 | public function __construct(array $map = []) |
|
38 | |||
39 | /** |
||
40 | * Removes all mappings from map |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | 2 | public function clear() |
|
48 | |||
49 | /** |
||
50 | * Returns true if the key exists in the lookup table |
||
51 | * |
||
52 | * @param mixed $key |
||
53 | * @return bool |
||
54 | */ |
||
55 | 57 | public function containsKey($key): bool |
|
59 | |||
60 | /** |
||
61 | * Returns true if the value exists in the map |
||
62 | * |
||
63 | * @param mixed $value |
||
64 | * @return bool |
||
65 | */ |
||
66 | 2 | public function containsValue($value): bool |
|
72 | |||
73 | /** |
||
74 | * Return a set representation of map |
||
75 | * |
||
76 | * If a set is passed in, that set will be populated, otherwise |
||
77 | * a default set will be used. |
||
78 | * |
||
79 | * @param SetInterface $set |
||
80 | * @return SetInterface |
||
81 | */ |
||
82 | 11 | public function entrySet(SetInterface $set = null): SetInterface |
|
89 | |||
90 | /** |
||
91 | * Get the value at the specified key |
||
92 | * |
||
93 | * @param mixed $key |
||
94 | * @return mixed |
||
95 | * @throws \OutOfRangeException if the key doesn't exist |
||
96 | */ |
||
97 | 14 | public function get($key) |
|
107 | |||
108 | /** |
||
109 | * Returns true if the map is empty |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | 2 | public function isEmpty(): bool |
|
117 | |||
118 | /** |
||
119 | * Returns a set of the keys in the map |
||
120 | * |
||
121 | * If a set is passed in, that set will be populated, otherwise |
||
122 | * a default set will be used. |
||
123 | * |
||
124 | * @param SetInterface $set |
||
125 | * @return SetInterface |
||
126 | */ |
||
127 | 2 | public function keySet(SetInterface $set = null): SetInterface |
|
137 | |||
138 | /** |
||
139 | * Returns the previous value or null if there was no value |
||
140 | * |
||
141 | * @param mixed $key |
||
142 | * @param mixed $value |
||
143 | * @return mixed |
||
144 | */ |
||
145 | 57 | public function put($key, $value) |
|
152 | |||
153 | /** |
||
154 | * Remove the mapping for the key and returns the previous value |
||
155 | * or null |
||
156 | * |
||
157 | * @param mixed $key |
||
158 | * @return mixed |
||
159 | */ |
||
160 | 57 | public function remove($key) |
|
173 | |||
174 | /** |
||
175 | * Returns the number of mappings in the map |
||
176 | * |
||
177 | * @return int |
||
178 | */ |
||
179 | 13 | public function count(): int |
|
183 | |||
184 | /** |
||
185 | * Returns the keys as a collection |
||
186 | * |
||
187 | * @param CollectionInterface $collection |
||
188 | * @return CollectionInterface |
||
189 | */ |
||
190 | 3 | public function keys(CollectionInterface $collection = null): CollectionInterface |
|
200 | |||
201 | /** |
||
202 | * Returns the values as a collection |
||
203 | * |
||
204 | * @param CollectionInterface $collection |
||
205 | * @return CollectionInterface |
||
206 | */ |
||
207 | 42 | public function values(CollectionInterface $collection = null): CollectionInterface |
|
217 | |||
218 | /** |
||
219 | * Filter the collection using closure |
||
220 | * |
||
221 | * The closure will get passed a [@see MapEntry]. Returning true from the |
||
222 | * closure will include that entry in the new map. |
||
223 | * |
||
224 | * @param callable $filter |
||
225 | * @return MapInterface |
||
226 | */ |
||
227 | 1 | public function filter(callable $filter): MapInterface |
|
240 | |||
241 | /** |
||
242 | * Generate a hashcode for a php value |
||
243 | * |
||
244 | * @param mixed $value |
||
245 | * @return string |
||
246 | */ |
||
247 | 57 | protected function hashCode($value): string |
|
259 | |||
260 | /** |
||
261 | * Returns an array of [@see MapEntry] keys |
||
262 | * |
||
263 | * @return array |
||
264 | */ |
||
265 | 5 | private function getKeys() |
|
271 | |||
272 | /** |
||
273 | * Returns an array of [@see MapEntry] values |
||
274 | * |
||
275 | * @return array |
||
276 | */ |
||
277 | private function getValues() |
||
283 | } |
||
284 |