提交 223b21e7 编写于 作者: G Gloria

Update docs against 14955+14403+14641

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 7dea9ec9
......@@ -404,11 +404,9 @@ arrayList.add(2);
arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.replaceAllElements((value: number, index: number)=> {
return value = 2 * value;
});
arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2;
arrayList.replaceAllElements((value) => {
// Add the user operation logic based on the actual scenario.
return value;
});
```
......@@ -453,7 +451,7 @@ arrayList.add(4);
arrayList.add(5);
arrayList.add(4);
arrayList.forEach((value, index) => {
console.log(`value:${value}`, index);
console.log("value:" + value, "index:" + index);
});
```
......@@ -796,14 +794,14 @@ arrayList.add(4);
// Method 1:
for (let item of arrayList) {
console.log(`value:${item}`);
console.log(`value:${item}`);
}
// Method 2:
let iter = arrayList[Symbol.iterator]();
let temp = iter.next().value;
while(temp != undefined) {
console.log(`value:${temp}`);
temp = iter.next().value;
console.log(`value:${temp}`);
temp = iter.next().value;
}
```
# @ohos.util.Deque (Linear Container Deque)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects:
**Queue** follows the principle of FIFO only and allows element removal at the front and insertion at the rear.
......@@ -15,6 +11,11 @@ Double-ended queue (deque) is a sequence container implemented based on the queu
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -269,7 +270,7 @@ deque.insertEnd(4);
deque.insertFront(5);
deque.insertEnd(4);
deque.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
# @ohos.util.HashMap (Nonlinear Container HashMap)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashMap** is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion, and removal. The elements in a **HashMap** instance are mappings of key-value pairs. Each key must be unique and have only one value.
**HashMap** is faster in accessing data than **[TreeMap](js-apis-treemap.md)**, because the former accesses the keys based on the hash codes, whereas the latter stores and accesses the keys in sorted order.
......@@ -15,6 +12,11 @@ This topic uses the following to identify the use of generics:
- K: Key
- V: Value
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -482,7 +484,7 @@ let hashMap = new HashMap();
hashMap.set("sparrow", 123);
hashMap.set("gull", 357);
hashMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -305,7 +305,7 @@ let hashSet = new HashSet();
hashSet.add("sparrow");
hashSet.add("squirrel");
hashSet.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -747,7 +747,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("sparrow", 123);
lightWeightMap.set("gull", 357);
lightWeightMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
......@@ -611,7 +611,7 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("sparrow");
lightWeightSet.add("gull");
lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
# @ohos.util.LinkedList (Linear Container LinkedList)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LinkedList** is implemented based on the doubly linked list. Each node of the doubly linked list has references pointing to the previous element and the next element. When querying an element, the system traverses the list from the beginning or end. **LinkedList** offers efficient insertion and removal operations but supports low query efficiency. **LinkedList** allows null elements.
Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends.
......@@ -14,6 +11,11 @@ Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList*
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -505,6 +507,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| -------- | -------- |
| 10200011 | The removeFirstFound method cannot be bound. |
| 10200010 | Container is empty. |
| 10200017 | The element does not exist in this container. |
**Example**
......@@ -545,6 +548,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| -------- | -------- |
| 10200011 | The removeLastFound method cannot be bound. |
| 10200010 | Container is empty. |
| 10200017 | The element does not exist in this container. |
**Example**
......@@ -631,7 +635,7 @@ linkedList.add(4);
linkedList.add(5);
linkedList.add(4);
linkedList.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
# @ohos.util.List (Linear Container List)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**List** is implemented based on the singly linked list. Each node has a reference pointing to the next element. When querying an element, the system traverses the list from the beginning. **List** offers efficient insertion and removal operations but supports low query efficiency. **List** allows null elements.
Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **List** is a singly linked list that does not support insertion or removal at both ends.
......@@ -12,6 +9,10 @@ Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **Lis
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -505,7 +506,7 @@ list.add(4);
list.add(5);
list.add(4);
list.forEach((value, index) => {
console.log("value: " + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -621,7 +621,7 @@ let plainArray = new PlainArray();
plainArray.add(1, "squirrel");
plainArray.add(2, "sparrow");
plainArray.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -201,7 +201,7 @@ queue.add(4);
queue.add(5);
queue.add(4);
queue.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
......@@ -239,7 +239,7 @@ stack.push(4);
stack.push(5);
stack.push(4);
stack.forEach((value, index) => {
console.log("value:" + value, index);
console.log("value:" + value, "index:" + index);
});
```
......
# @ohos.util.TreeMap (Nonlinear Container TreeMap)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**TreeMap** is implemented using a red-black tree, which is a binary search tree where keys are stored in sorted order for efficient insertion and removal.
......@@ -12,9 +9,15 @@
Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order.
This topic uses the following to identify the use of generics:
- K: Key
- V: Value
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -609,7 +612,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
| thisArg | Object | No| Value to use when the callback is invoked.|
| thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.|
callbackfn
| Name| Type| Mandatory| Description|
......@@ -633,7 +636,7 @@ let treeMap = new TreeMap();
treeMap.set("sparrow", 123);
treeMap.set("gull", 357);
treeMap.forEach((value, key) => {
console.log("value:" + value, key);
console.log("value:" + value, "key:" + key);
});
```
......
# @ohos.util.TreeSet (Nonlinear Container TreeSet)
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique.
**[HashSet](js-apis-hashset.md)** stores data in a random order, whereas **TreeSet** stores data in sorted order. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**.
......@@ -10,8 +7,13 @@
Recommended use case: Use **TreeSet** when you need to store data in sorted order.
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
......@@ -482,13 +484,13 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
| thisArg | Object | No| Value to use when the callback is invoked.|
| thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.|
callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | No| Value of the element that is currently traversed.|
| key | T | No| Key of the element that is currently traversed (same as **value**).|
| key | T | No| Key of the element that is currently traversed.|
| set | TreeSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|
**Error codes**
......@@ -506,7 +508,7 @@ let treeSet = new TreeSet();
treeSet.add("sparrow");
treeSet.add("gull");
treeSet.forEach((value, key) => {
console.log("value:" + value, key)
console.log("value:" + value, "key:" + key);
});
```
......
# @ohos.util.Vector (Linear Container Vector)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Vector** is a linear data structure that is implemented based on arrays. When the memory of a vector is used up, a larger contiguous memory area is automatically allocated, all the elements are copied to the new memory area, and the current memory area is reclaimed. **Vector** can be used to efficiently access elements.
Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based on arrays, but **Vector** provides more interfaces for operating the arrays. Both of them can dynamically adjust the capacity. **Vector** doubles the capacity each time, whereas **ArrayList** increases the capacity by 50%.
......@@ -13,6 +9,12 @@ Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based
This topic uses the following to identify the use of generics:
- T: Type
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.util.ArrayList](js-apis-arraylist.md).
## Modules to Import
```ts
......@@ -251,7 +253,7 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -320,11 +322,9 @@ vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
vector.replaceAllElements((value: number, index: number) => {
return value = 2 * value;
});
vector.replaceAllElements((value: number, index: number) => {
return value = value - 2;
vector.replaceAllElements((value) => {
// Add the user operation logic based on the actual scenario.
return value;
});
```
......@@ -361,7 +361,7 @@ vector.add(4);
vector.add(5);
vector.add(4);
vector.forEach((value, index) => {
console.log("value:" + value, index)
console.log("value:" + value, "index:" + index);
});
```
......@@ -421,7 +421,7 @@ Obtains elements within a range in this container, including the element at the
| -------- | -------- |
| Vector&lt;T&gt; | New **Vector** instance obtained.|
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -444,7 +444,7 @@ Clears all elements in this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
**Example**
```ts
let vector = new Vector();
......@@ -639,18 +639,6 @@ Copies elements in this container into an array to overwrite elements of the sam
| -------- | -------- | -------- | -------- |
| array | Array&lt;T&gt; | Yes| Array to which the elements in the container will be copied.|
**Example**
```ts
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let array = ["a", "b", "c", "d", "e", "f"];
let result = vector.copyToArray(array);
```
### getFirstElement
getFirstElement(): T
......@@ -803,15 +791,15 @@ Obtains an element at the specified position in this container.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | Element obtained.|
| Type| Description|
| -------- | -------- |
| T | Element obtained.|
**Example**
......@@ -840,20 +828,9 @@ Replaces an element at the specified position in this container with a given ele
**Return value**
| Type| Description|
| -------- | -------- |
| T | New element.|
**Example**
```ts
let vector = new Vector();
vector.add(2);
vector.add(4);
vector.add(5);
vector.add(4);
let result = vector.set(2, "A");
```
| Type| Description|
| -------- | -------- |
| T | New element.|
### [Symbol.iterator]
......
......@@ -273,3 +273,21 @@ The task to cancel is being executed.
**Solution**
Before canceling a task, ensure that the task finishes execution.
## 10200017 Failed to Delete an Element That Does Not Exist
**Error Message**
The element does not exist in this container.
**Description**
This error code is reported when you attempt to delete an element that does not exist in the container.
**Possible Causes**
The element to delete does not exist in the container.
**Solution**
Before deleting an element, ensure that the element exists in this container.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册