• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit ArkTS
19 */
20
21/**
22 * HashMap is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion,
23 * and removal. The elements in a HashMap instance are mappings of key-value pairs. Each key must be unique and have only one value.
24 *
25 * @syscap SystemCapability.Utils.Lang
26 * @since 8
27 */
28/**
29 * HashMap is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion,
30 * and removal. The elements in a HashMap instance are mappings of key-value pairs. Each key must be unique and have only one value.
31 *
32 * @syscap SystemCapability.Utils.Lang
33 * @crossplatform
34 * @since 10
35 */
36/**
37 * HashMap is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion,
38 * and removal. The elements in a HashMap instance are mappings of key-value pairs. Each key must be unique and have only one value.
39 *
40 * @syscap SystemCapability.Utils.Lang
41 * @crossplatform
42 * @atomicservice
43 * @since arkts {'1.1':'12', '1.2':'20'}
44 * @arkts 1.1&1.2
45 */
46declare class HashMap<K, V> {
47  /**
48   * A constructor used to create a HashMap object.
49   *
50   * @throws { BusinessError } 10200012 - The HashMap's constructor cannot be directly invoked.
51   * @syscap SystemCapability.Utils.Lang
52   * @since 8
53   */
54  /**
55   * A constructor used to create a HashMap object.
56   *
57   * @throws { BusinessError } 10200012 - The HashMap's constructor cannot be directly invoked.
58   * @syscap SystemCapability.Utils.Lang
59   * @crossplatform
60   * @since 10
61   */
62  /**
63   * A constructor used to create a HashMap instance.
64   *
65   * @throws { BusinessError } 10200012 - The HashMap's constructor cannot be directly invoked.
66   * @syscap SystemCapability.Utils.Lang
67   * @crossplatform
68   * @atomicservice
69   * @since arkts {'1.1':'12', '1.2':'20'}
70   * @arkts 1.1&1.2
71   */
72  constructor();
73  /**
74   * Gets the element number of the hashmap.
75   *
76   * @type { number }
77   * @syscap SystemCapability.Utils.Lang
78   * @since 8
79   */
80  /**
81   * Gets the element number of the hashmap.
82   *
83   * @type { number }
84   * @syscap SystemCapability.Utils.Lang
85   * @crossplatform
86   * @since 10
87   */
88  /**
89   * Number of elements in a hash map.
90   *
91   * @type { number }
92   * @syscap SystemCapability.Utils.Lang
93   * @crossplatform
94   * @atomicservice
95   * @since 12
96   */
97  length: number;
98  /**
99   * Gets the number of elements in a hash map.
100   *
101   * @type { number }
102   * @syscap SystemCapability.Utils.Lang
103   * @crossplatform
104   * @atomicservice
105   * @since 20
106   * @arkts 1.2
107   */
108  get length(): number;
109  /**
110   * Returns whether the Map object contains elements
111   *
112   * @returns { boolean } the boolean type
113   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
114   * @syscap SystemCapability.Utils.Lang
115   * @since 8
116   */
117  /**
118   * Returns whether the Map object contains elements
119   *
120   * @returns { boolean } the boolean type
121   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
122   * @syscap SystemCapability.Utils.Lang
123   * @crossplatform
124   * @since 10
125   */
126  /**
127   * Checks whether this container is empty (contains no element).
128   *
129   * @returns { boolean } the boolean type
130   * @throws { BusinessError } 10200011 - The isEmpty method cannot be bound.
131   * @syscap SystemCapability.Utils.Lang
132   * @crossplatform
133   * @atomicservice
134   * @since arkts {'1.1':'12', '1.2':'20'}
135   * @arkts 1.1&1.2
136   */
137  isEmpty(): boolean;
138  /**
139   * Returns whether a key is contained in this map
140   *
141   * @param { K } key - key key need to determine whether to include the key
142   * @returns { boolean } the boolean type
143   * @throws { BusinessError } 10200011 - The hasKey method cannot be bound.
144   * @syscap SystemCapability.Utils.Lang
145   * @since 8
146   */
147  /**
148   * Returns whether a key is contained in this map
149   *
150   * @param { K } key - key key need to determine whether to include the key
151   * @returns { boolean } the boolean type
152   * @throws { BusinessError } 10200011 - The hasKey method cannot be bound.
153   * @syscap SystemCapability.Utils.Lang
154   * @crossplatform
155   * @since 10
156   */
157  /**
158   * Checks whether this container contains the specified key.
159   *
160   * @param { K } key - Target key.
161   * @returns { boolean } the boolean type
162   * @throws { BusinessError } 10200011 - The hasKey method cannot be bound.
163   * @syscap SystemCapability.Utils.Lang
164   * @crossplatform
165   * @atomicservice
166   * @since arkts {'1.1':'12', '1.2':'20'}
167   * @arkts 1.1&1.2
168   */
169  hasKey(key: K): boolean;
170  /**
171   * Returns whether a value is contained in this map
172   *
173   * @param { V } value - value value need to determine whether to include the value
174   * @returns { boolean } the boolean type
175   * @throws { BusinessError } 10200011 - The hasValue method cannot be bound.
176   * @syscap SystemCapability.Utils.Lang
177   * @since 8
178   */
179  /**
180   * Returns whether a value is contained in this map
181   *
182   * @param { V } value - value value need to determine whether to include the value
183   * @returns { boolean } the boolean type
184   * @throws { BusinessError } 10200011 - The hasValue method cannot be bound.
185   * @syscap SystemCapability.Utils.Lang
186   * @crossplatform
187   * @since 10
188   */
189  /**
190   * Checks whether this container contains the specified value.
191   *
192   * @param { V } value - Target value.
193   * @returns { boolean } the boolean type
194   * @throws { BusinessError } 10200011 - The hasValue method cannot be bound.
195   * @syscap SystemCapability.Utils.Lang
196   * @crossplatform
197   * @atomicservice
198   * @since arkts {'1.1':'12', '1.2':'20'}
199   * @arkts 1.1&1.2
200   */
201  hasValue(value: V): boolean;
202  /**
203   * Returns a specified element in a Map object, or undefined if there is no corresponding element
204   *
205   * @param { K } key - key key the index in HashMap
206   * @returns { V } value or undefined
207   * @throws { BusinessError } 10200011 - The get method cannot be bound.
208   * @syscap SystemCapability.Utils.Lang
209   * @since 8
210   */
211  /**
212   * Returns a specified element in a Map object, or undefined if there is no corresponding element
213   *
214   * @param { K } key - key key the index in HashMap
215   * @returns { V } value or undefined
216   * @throws { BusinessError } 10200011 - The get method cannot be bound.
217   * @syscap SystemCapability.Utils.Lang
218   * @crossplatform
219   * @since 10
220   */
221  /**
222   * Obtains the value of the specified key in this container. If nothing is obtained, undefined is returned.
223   *
224   * @param { K } key - Target key.
225   * @returns { V } value or undefined
226   * @throws { BusinessError } 10200011 - The get method cannot be bound.
227   * @syscap SystemCapability.Utils.Lang
228   * @crossplatform
229   * @atomicservice
230   * @since 12
231   */
232  get(key: K): V;
233
234  /**
235   * Obtains the value of the specified key in this container. If nothing is obtained, undefined is returned.
236   *
237   * @param { K } key - Target key.
238   * @returns { V | undefined } value or undefined
239   * @syscap SystemCapability.Utils.Lang
240   * @crossplatform
241   * @atomicservice
242   * @since 20
243   * @arkts 1.2
244   */
245  get(key: K): V | undefined;
246
247  /**
248   * Adds all element groups in one map to another map
249   *
250   * @param { HashMap<K, V> } map - map map the Map object to add members
251   * @throws { BusinessError } 10200011 - The setAll method cannot be bound.
252   * @throws { BusinessError } 401 -  Parameter error. Possible causes:
253   * 1.Mandatory parameters are left unspecified;
254   * 2.Incorrect parameter types.
255   * @syscap SystemCapability.Utils.Lang
256   * @since 8
257   */
258  /**
259   * Adds all element groups in one map to another map
260   *
261   * @param { HashMap<K, V> } map - map map the Map object to add members
262   * @throws { BusinessError } 10200011 - The setAll method cannot be bound.
263   * @throws { BusinessError } 401 -  Parameter error. Possible causes:
264   * 1.Mandatory parameters are left unspecified;
265   * 2.Incorrect parameter types.
266   * @syscap SystemCapability.Utils.Lang
267   * @crossplatform
268   * @since 10
269   */
270  /**
271   * Adds all elements in a HashMap instance to this container.
272   *
273   * @param { HashMap<K, V> } map - HashMap instance whose elements are to be added to the current container.
274   * @throws { BusinessError } 10200011 - The setAll method cannot be bound.
275   * @throws { BusinessError } 401 -  Parameter error. Possible causes:
276   * 1.Mandatory parameters are left unspecified;
277   * 2.Incorrect parameter types.
278   * @syscap SystemCapability.Utils.Lang
279   * @crossplatform
280   * @atomicservice
281   * @since arkts {'1.1':'12', '1.2':'20'}
282   * @arkts 1.1&1.2
283   */
284  setAll(map: HashMap<K, V>): void;
285  /**
286   * Adds or updates a(new) key-value pair with a key and value specified for the Map object
287   *
288   * @param { K } key - key key Added or updated targets
289   * @param { V } value - value value Added or updated value
290   * @returns { Object } the map object after set
291   * @throws { BusinessError } 10200011 - The set method cannot be bound.
292   * @throws { BusinessError } 401 - Parameter error. Possible causes:
293   * 1.Mandatory parameters are left unspecified.
294   * @syscap SystemCapability.Utils.Lang
295   * @since 8
296   */
297  /**
298   * Adds or updates a(new) key-value pair with a key and value specified for the Map object
299   *
300   * @param { K } key - key key Added or updated targets
301   * @param { V } value - value value Added or updated value
302   * @returns { Object } the map object after set
303   * @throws { BusinessError } 10200011 - The set method cannot be bound.
304   * @throws { BusinessError } 401 - Parameter error. Possible causes:
305   * 1.Mandatory parameters are left unspecified.
306   * @syscap SystemCapability.Utils.Lang
307   * @crossplatform
308   * @since 10
309   */
310  /**
311   * Adds or updates an element in this container.
312   *
313   * @param { K } key - Key of the target element.
314   * @param { V } value - Value of the target element.
315   * @returns { Object } the map object after set
316   * @throws { BusinessError } 10200011 - The set method cannot be bound.
317   * @throws { BusinessError } 401 - Parameter error. Possible causes:
318   * 1.Mandatory parameters are left unspecified.
319   * @syscap SystemCapability.Utils.Lang
320   * @crossplatform
321   * @atomicservice
322   * @since arkts {'1.1':'12', '1.2':'20'}
323   * @arkts 1.1&1.2
324   */
325  set(key: K, value: V): Object;
326  /**
327   * Remove a specified element from a Map object
328   *
329   * @param { K } key - key key Target to be deleted
330   * @returns { V } Target mapped value
331   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
332   * @syscap SystemCapability.Utils.Lang
333   * @since 8
334   */
335  /**
336   * Remove a specified element from a Map object
337   *
338   * @param { K } key - key key Target to be deleted
339   * @returns { V } Target mapped value
340   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
341   * @syscap SystemCapability.Utils.Lang
342   * @crossplatform
343   * @since 10
344   */
345  /**
346   * Removes an element with the specified key from this container.
347   *
348   * @param { K } key - Key of the target element.
349   * @returns { V } Target mapped value
350   * @throws { BusinessError } 10200011 - The remove method cannot be bound.
351   * @syscap SystemCapability.Utils.Lang
352   * @crossplatform
353   * @atomicservice
354   * @since 12
355   */
356  remove(key: K): V;
357
358  /**
359   * Removes an element with the specified key from this container.
360   *
361   * @param { K } key - Key of the target element.
362   * @returns { V | undefined } Tthe value associated with the key if it was removed, undefined otherwise
363   * @syscap SystemCapability.Utils.Lang
364   * @crossplatform
365   * @atomicservice
366   * @since 20
367   * @arkts 1.2
368   */
369  remove(key: K): V | undefined;
370
371  /**
372   * Clear all element groups in the map
373   *
374   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
375   * @syscap SystemCapability.Utils.Lang
376   * @since 8
377   */
378  /**
379   * Clear all element groups in the map
380   *
381   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
382   * @syscap SystemCapability.Utils.Lang
383   * @crossplatform
384   * @since 10
385   */
386  /**
387   * Clears this container and sets its length to 0.
388   *
389   * @throws { BusinessError } 10200011 - The clear method cannot be bound.
390   * @syscap SystemCapability.Utils.Lang
391   * @crossplatform
392   * @atomicservice
393   * @since arkts {'1.1':'12', '1.2':'20'}
394   * @arkts 1.1&1.2
395   */
396  clear(): void;
397  /**
398   * Returns a new Iterator object that contains the keys contained in this map
399   *
400   * @returns { IterableIterator<K> }
401   * @throws { BusinessError } 10200011 - The keys method cannot be bound.
402   * @syscap SystemCapability.Utils.Lang
403   * @since 8
404   */
405  /**
406   * Returns a new Iterator object that contains the keys contained in this map
407   *
408   * @returns { IterableIterator<K> }
409   * @throws { BusinessError } 10200011 - The keys method cannot be bound.
410   * @syscap SystemCapability.Utils.Lang
411   * @crossplatform
412   * @since 10
413   */
414  /**
415   * Obtains an iterator that contains all the keys in this container.
416   *
417   * @returns { IterableIterator<K> }
418   * @throws { BusinessError } 10200011 - The keys method cannot be bound.
419   * @syscap SystemCapability.Utils.Lang
420   * @crossplatform
421   * @atomicservice
422   * @since arkts {'1.1':'12', '1.2':'20'}
423   * @arkts 1.1&1.2
424   */
425  keys(): IterableIterator<K>;
426  /**
427   * Returns a new Iterator object that contains the values contained in this map
428   *
429   * @returns { IterableIterator<V> }
430   * @throws { BusinessError } 10200011 - The values method cannot be bound.
431   * @syscap SystemCapability.Utils.Lang
432   * @since 8
433   */
434  /**
435   * Returns a new Iterator object that contains the values contained in this map
436   *
437   * @returns { IterableIterator<V> }
438   * @throws { BusinessError } 10200011 - The values method cannot be bound.
439   * @syscap SystemCapability.Utils.Lang
440   * @crossplatform
441   * @since 10
442   */
443  /**
444   * Obtains an iterator that contains all the values in this container.
445   *
446   * @returns { IterableIterator<V> }
447   * @throws { BusinessError } 10200011 - The values method cannot be bound.
448   * @syscap SystemCapability.Utils.Lang
449   * @crossplatform
450   * @atomicservice
451   * @since arkts {'1.1':'12', '1.2':'20'}
452   * @arkts 1.1&1.2
453   */
454  values(): IterableIterator<V>;
455  /**
456   * Replace the old value by new value corresponding to the specified key
457   *
458   * @param { K } key - key key Updated targets
459   * @param { V } newValue - newValue newValue Updated the target mapped value
460   * @returns { boolean } the boolean type(Is there a target pointed to by the key)
461   * @throws { BusinessError } 10200011 - The replace method cannot be bound.
462   * @syscap SystemCapability.Utils.Lang
463   * @since 8
464   */
465  /**
466   * Replace the old value by new value corresponding to the specified key
467   *
468   * @param { K } key - key key Updated targets
469   * @param { V } newValue - newValue newValue Updated the target mapped value
470   * @returns { boolean } the boolean type(Is there a target pointed to by the key)
471   * @throws { BusinessError } 10200011 - The replace method cannot be bound.
472   * @syscap SystemCapability.Utils.Lang
473   * @crossplatform
474   * @since 10
475   */
476  /**
477   * Replaces an element in this container.
478   *
479   * @param { K } key - Key of the target element.
480   * @param { V } newValue - New value of the element.
481   * @returns { boolean } the boolean type(Is there a target pointed to by the key)
482   * @throws { BusinessError } 10200011 - The replace method cannot be bound.
483   * @syscap SystemCapability.Utils.Lang
484   * @crossplatform
485   * @atomicservice
486   * @since arkts {'1.1':'12', '1.2':'20'}
487   * @arkts 1.1&1.2
488   */
489  replace(key: K, newValue: V): boolean;
490  /**
491   * Executes the given callback function once for each real key in the map.
492   * It does not perform functions on deleted keys
493   *
494   * @param { function } callbackFn - callbackFn
495   * callbackFn (required) A function that accepts up to three arguments.
496   * The function to be called for each element.
497   * @param { Object } [thisArg] - thisArg
498   * thisArg (Optional) The value to be used as this value for when callbackFn is called.
499   * If thisArg is omitted, undefined is used as the this value.
500   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
501   * @throws { BusinessError } 401 - Parameter error. Possible causes:
502   * 1.Mandatory parameters are left unspecified;
503   * 2.Incorrect parameter types.
504   * @syscap SystemCapability.Utils.Lang
505   * @since 8
506   */
507  /**
508   * Executes the given callback function once for each real key in the map.
509   * It does not perform functions on deleted keys
510   *
511   * @param { function } callbackFn - callbackFn
512   * callbackFn (required) A function that accepts up to three arguments.
513   * The function to be called for each element.
514   * @param { Object } [thisArg] - thisArg
515   * thisArg (Optional) The value to be used as this value for when callbackFn is called.
516   * If thisArg is omitted, undefined is used as the this value.
517   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
518   * @throws { BusinessError } 401 - Parameter error. Possible causes:
519   * 1.Mandatory parameters are left unspecified;
520   * 2.Incorrect parameter types.
521   * @syscap SystemCapability.Utils.Lang
522   * @crossplatform
523   * @since 10
524   */
525  /**
526   * Uses a callback to traverse the elements in this container and obtain their position indexes.
527   *
528   * @param { function } callbackFn - Callback invoked to traverse the elements in the container.
529   * @param { Object } [thisArg] - Value of this to use when callbackFn is invoked. The default value is this instance.
530   * @throws { BusinessError } 10200011 - The forEach method cannot be bound.
531   * @throws { BusinessError } 401 - Parameter error. Possible causes:
532   * 1.Mandatory parameters are left unspecified;
533   * 2.Incorrect parameter types.
534   * @syscap SystemCapability.Utils.Lang
535   * @crossplatform
536   * @atomicservice
537   * @since 12
538   */
539  forEach(callbackFn: (value?: V, key?: K, map?: HashMap<K, V>) => void, thisArg?: Object): void;
540
541  /**
542   * Uses a callback to traverse the elements in this container and obtain their position indexes.
543   *
544   * @param { HashMapCbFn<K, V> } callbackFn - Callback invoked to traverse the elements in the container.
545   * @syscap SystemCapability.Utils.Lang
546   * @crossplatform
547   * @atomicservice
548   * @since 20
549   * @arkts 1.2
550   */
551  forEach(callbackFn: HashMapCbFn<K, V>): void;
552
553  /**
554   * Returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order
555   *
556   * @returns { IterableIterator<[K, V]> }
557   * @throws { BusinessError } 10200011 - The entries method cannot be bound.
558   * @syscap SystemCapability.Utils.Lang
559   * @since 8
560   */
561  /**
562   * Returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order
563   *
564   * @returns { IterableIterator<[K, V]> }
565   * @throws { BusinessError } 10200011 - The entries method cannot be bound.
566   * @syscap SystemCapability.Utils.Lang
567   * @crossplatform
568   * @since 10
569   */
570  /**
571   * Obtains an iterator that contains all the elements in this container.
572   *
573   * @returns { IterableIterator<[K, V]> }
574   * @throws { BusinessError } 10200011 - The entries method cannot be bound.
575   * @syscap SystemCapability.Utils.Lang
576   * @crossplatform
577   * @atomicservice
578   * @since arkts {'1.1':'12', '1.2':'20'}
579   * @arkts 1.1&1.2
580   */
581  entries(): IterableIterator<[K, V]>;
582  /**
583   * returns an iterator.Each item of the iterator is a Javascript Object
584   *
585   * @returns { IterableIterator<[K, V]> }
586   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
587   * @syscap SystemCapability.Utils.Lang
588   * @since 8
589   */
590  /**
591   * returns an iterator.Each item of the iterator is a Javascript Object
592   *
593   * @returns { IterableIterator<[K, V]> }
594   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
595   * @syscap SystemCapability.Utils.Lang
596   * @crossplatform
597   * @since 10
598   */
599  /**
600   * Obtains an iterator, each item of which is a JavaScript object.
601   *
602   * @returns { IterableIterator<[K, V]> }
603   * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound.
604   * @syscap SystemCapability.Utils.Lang
605   * @crossplatform
606   * @atomicservice
607   * @since 12
608   */
609  [Symbol.iterator](): IterableIterator<[K, V]>;
610
611  /**
612   * Obtains an iterator, each item of which is a JavaScript object.
613   *
614   * @returns { IterableIterator<[K, V]> } an iterator for the HashMap
615   * @syscap SystemCapability.Utils.Lang
616   * @crossplatform
617   * @atomicservice
618   * @since 20
619   * @arkts 1.2
620   */
621  $_iterator(): IterableIterator<[K, V]>;
622}
623
624  /**
625   * The type of HashMap callback function.
626   *
627   * @typedef { function } HashMapCbFn
628   * @param { V } value - The value of the current entry
629   * @param { K } key - The key of the current entry
630   * @param { HashMap<K, V> } map - The HashMap instance being traversed
631   * @returns { void } This callback does not return a value
632   * @syscap SystemCapability.Utils.Lang
633   * @atomicservice
634   * @since 20
635   * @arkts 1.2
636   */
637  type HashMapCbFn<K, V> = (value: V, key: K, map: HashMap<K, V>) => void;
638
639export default HashMap;
640