提交 8f8c10c6 编写于 作者: G Gloria

Update docs against 15343+14417

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 2f095629
...@@ -320,11 +320,9 @@ arrayList.add(2); ...@@ -320,11 +320,9 @@ arrayList.add(2);
arrayList.add(4); arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.replaceAllElements((value: number, index: number)=> { arrayList.replaceAllElements((value) => {
return value = 2 * value; // Add the user operation logic based on the actual scenario.
}); return value;
arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2;
}); });
``` ```
...@@ -361,7 +359,7 @@ arrayList.add(4); ...@@ -361,7 +359,7 @@ arrayList.add(4);
arrayList.add(5); arrayList.add(5);
arrayList.add(4); arrayList.add(4);
arrayList.forEach((value, index) => { arrayList.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -208,7 +208,7 @@ deque.insertEnd(4); ...@@ -208,7 +208,7 @@ deque.insertEnd(4);
deque.insertFront(5); deque.insertFront(5);
deque.insertEnd(4); deque.insertEnd(4);
deque.forEach((value, index) => { deque.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -375,7 +375,7 @@ let hashMap = new HashMap(); ...@@ -375,7 +375,7 @@ let hashMap = new HashMap();
hashMap.set("sdfs", 123); hashMap.set("sdfs", 123);
hashMap.set("dfsghsf", 357); hashMap.set("dfsghsf", 357);
hashMap.forEach((value, key) => { hashMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, "key:" + key);
}); });
``` ```
......
...@@ -228,7 +228,7 @@ let hashSet = new HashSet(); ...@@ -228,7 +228,7 @@ let hashSet = new HashSet();
hashSet.add("sdfs"); hashSet.add("sdfs");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf");
hashSet.forEach((value, key) => { hashSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, "key:" + key);
}); });
``` ```
......
...@@ -582,7 +582,7 @@ let lightWeightMap = new LightWeightMap(); ...@@ -582,7 +582,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("sdfs", 123); lightWeightMap.set("sdfs", 123);
lightWeightMap.set("dfsghsf", 357); lightWeightMap.set("dfsghsf", 357);
lightWeightMap.forEach((value, key) => { lightWeightMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, "key:" + key);
}); });
``` ```
......
...@@ -482,7 +482,7 @@ let lightWeightSet = new LightWeightSet(); ...@@ -482,7 +482,7 @@ let lightWeightSet = new LightWeightSet();
lightWeightSet.add("sdfs"); lightWeightSet.add("sdfs");
lightWeightSet.add("dfsghsf"); lightWeightSet.add("dfsghsf");
lightWeightSet.forEach((value, key) => { lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, "key:" + key);
}); });
``` ```
......
...@@ -496,7 +496,7 @@ linkedList.add(4); ...@@ -496,7 +496,7 @@ linkedList.add(4);
linkedList.add(5); linkedList.add(5);
linkedList.add(4); linkedList.add(4);
linkedList.forEach((value, index) => { linkedList.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -405,7 +405,7 @@ list.add(4); ...@@ -405,7 +405,7 @@ list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.forEach((value, index) => { list.forEach((value, index) => {
console.log("value: " + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -482,7 +482,7 @@ let plainArray = new PlainArray(); ...@@ -482,7 +482,7 @@ let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "sddfhf");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sffdfhf");
plainArray.forEach((value, index) => { plainArray.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -160,7 +160,7 @@ queue.add(4); ...@@ -160,7 +160,7 @@ queue.add(4);
queue.add(5); queue.add(5);
queue.add(4); queue.add(4);
queue.forEach((value, index) => { queue.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
...@@ -192,7 +192,7 @@ stack.push(4); ...@@ -192,7 +192,7 @@ stack.push(4);
stack.push(5); stack.push(5);
stack.push(4); stack.push(4);
stack.forEach((value, index) => { stack.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, "index:" + index);
}); });
``` ```
......
# Nonlinear Container 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** 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. **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,6 +8,10 @@ ...@@ -12,6 +8,10 @@
Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order. Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order.
> **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 ## Modules to Import
```ts ```ts
...@@ -490,7 +490,7 @@ let treeMap = new TreeMap(); ...@@ -490,7 +490,7 @@ let treeMap = new TreeMap();
treeMap.set("sdfs", 123); treeMap.set("sdfs", 123);
treeMap.set("dfsghsf", 357); treeMap.set("dfsghsf", 357);
treeMap.forEach((value, key) => { treeMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, "key:" + key);
}); });
``` ```
......
# Nonlinear Container 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. **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.
...@@ -10,6 +7,10 @@ ...@@ -10,6 +7,10 @@
Recommended use case: Use **TreeSet** when you need to store data in sorted order. Recommended use case: Use **TreeSet** when you need to store data in sorted order.
> **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 ## Modules to Import
```ts ```ts
...@@ -392,7 +393,7 @@ let treeSet = new TreeSet(); ...@@ -392,7 +393,7 @@ let treeSet = new TreeSet();
treeSet.add("sdfs"); treeSet.add("sdfs");
treeSet.add("dfsghsf"); treeSet.add("dfsghsf");
treeSet.forEach((value, key) => { treeSet.forEach((value, key) => {
console.log("value:" + value, key) console.log("value:" + value, "key:" + key);
}); });
``` ```
......
# Linear Container 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. **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%. 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%.
**Recommended use case**: Use **Vector** when the data volume is large. **Recommended use case**: Use **Vector** when the data volume is large.
> **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 ## Modules to Import
```ts ```ts
...@@ -248,7 +248,7 @@ Removes the first occurrence of the specified element from this container. ...@@ -248,7 +248,7 @@ Removes the first occurrence of the specified element from this container.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
**Return value** **Example**
```ts ```ts
let vector = new Vector(); let vector = new Vector();
...@@ -319,11 +319,9 @@ vector.add(2); ...@@ -319,11 +319,9 @@ vector.add(2);
vector.add(4); vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
vector.replaceAllElements((value: number, index: number) => { vector.replaceAllElements((value) => {
return value = 2 * value; // Add the user operation logic based on the actual scenario.
}); return value;
vector.replaceAllElements((value: number, index: number) => {
return value = value - 2;
}); });
``` ```
...@@ -360,7 +358,7 @@ vector.add(4); ...@@ -360,7 +358,7 @@ vector.add(4);
vector.add(5); vector.add(5);
vector.add(4); vector.add(4);
vector.forEach((value, index) => { vector.forEach((value, index) => {
console.log("value:" + value, index) console.log("value:" + value, "index:" + index);
}); });
``` ```
...@@ -420,7 +418,7 @@ Obtains elements within a range in this container, including the element at the ...@@ -420,7 +418,7 @@ Obtains elements within a range in this container, including the element at the
| -------- | -------- | | -------- | -------- |
| Vector&lt;T&gt; | New **Vector** instance obtained.| | Vector&lt;T&gt; | New **Vector** instance obtained.|
**Return value** **Example**
```ts ```ts
let vector = new Vector(); let vector = new Vector();
...@@ -442,7 +440,7 @@ Clears all elements in this container and sets its length to **0**. ...@@ -442,7 +440,7 @@ Clears all elements in this container and sets its length to **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Example**
```ts ```ts
let vector = new Vector(); let vector = new Vector();
...@@ -637,18 +635,6 @@ Copies elements in this container into an array to overwrite elements of the sam ...@@ -637,18 +635,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.| | 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
getFirstElement(): T getFirstElement(): T
...@@ -842,17 +828,6 @@ Replaces an element at the specified position in this container with a given ele ...@@ -842,17 +828,6 @@ Replaces an element at the specified position in this container with a given ele
| -------- | -------- | | -------- | -------- |
| T | New element.| | 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");
```
### [Symbol.iterator] ### [Symbol.iterator]
[Symbol.iterator]\(): IterableIterator&lt;T&gt; [Symbol.iterator]\(): IterableIterator&lt;T&gt;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册