提交 e1b411e8 编写于 作者: L lengchangjing

deal with vod problems

Signed-off-by: Nlengchangjing <lengchangjing@huawei.com>
上级 a6c38fa1
...@@ -11,6 +11,9 @@ ArrayList和[LinkedList](js-apis-linkedlist.md)相比,ArrayList的随机访问 ...@@ -11,6 +11,9 @@ ArrayList和[LinkedList](js-apis-linkedlist.md)相比,ArrayList的随机访问
**推荐使用场景:** 当需要频繁读取集合中的元素时,推荐使用ArrayList。 **推荐使用场景:** 当需要频繁读取集合中的元素时,推荐使用ArrayList。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -71,7 +74,7 @@ add(element: T): boolean ...@@ -71,7 +74,7 @@ add(element: T): boolean
let result1 = arrayList.add(1); let result1 = arrayList.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
let result2 = arrayList.add(b); let result2 = arrayList.add(b);
let c = {name: "lala", age: "13"}; let c = {name: "Dylon", age: "13"};
let result3 = arrayList.add(false); let result3 = arrayList.add(false);
``` ```
...@@ -123,9 +126,9 @@ has(element: T): boolean ...@@ -123,9 +126,9 @@ has(element: T): boolean
```ts ```ts
let arrayList = new ArrayList(); let arrayList = new ArrayList();
let result = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = arrayList.has("squirrel");
arrayList.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); arrayList.add("squirrel");
let result1 = arrayList.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = arrayList.has("squirrel");
``` ```
### getIndexOf ### getIndexOf
...@@ -360,7 +363,7 @@ arrayList.add(4); ...@@ -360,7 +363,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);
}); });
``` ```
...@@ -622,14 +625,14 @@ arrayList.add(4); ...@@ -622,14 +625,14 @@ arrayList.add(4);
// 使用方法一: // 使用方法一:
for (let item of arrayList) { for (let item of arrayList) {
console.log("value:" + item); console.log(`value:${item}`);
} }
// 使用方法二: // 使用方法二:
let iter = arrayList[Symbol.iterator](); let iter = arrayList[Symbol.iterator]();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
console.log("value:" + temp); console.log(`value:${temp}`);
temp = iter.next().value; temp = iter.next().value;
} }
``` ```
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Buffer对象用于表示固定长度的字节序列,是专门存放二进制数据的缓存区。 Buffer对象用于表示固定长度的字节序列,是专门存放二进制数据的缓存区。
**推荐使用场景:** 可用于处理大量二进制数据,处理图片、文件接收上传、网络协议等等 **推荐使用场景:** 可用于处理大量二进制数据,处理图片、文件接收上传等等
## 导入模块 ## 导入模块
...@@ -15,6 +15,16 @@ import buffer from '@ohos.buffer'; ...@@ -15,6 +15,16 @@ import buffer from '@ohos.buffer';
## Buffer ## Buffer
### 属性
**系统能力:** SystemCapability.Utils.Lang
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | buffer的字节长度。 |
| buffer | ArrayBuffer | 是 | 否 | ArrayBuffer对象。 |
| byteOffset | number | 是 | 否 | 当前buffer所在内存池的偏移量。 |
### alloc ### alloc
alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer
...@@ -438,6 +448,8 @@ compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, s ...@@ -438,6 +448,8 @@ compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, s
| sourceStart | number | 否 | `this`实例中开始的偏移量。 默认值: 0。 | | sourceStart | number | 否 | `this`实例中开始的偏移量。 默认值: 0。 |
| sourceEnd | number | 否 | `this`实例中结束的偏移量(不包括本身)。 默认值: buf.length。 | | sourceEnd | number | 否 | `this`实例中结束的偏移量(不包括本身)。 默认值: buf.length。 |
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| number | 比较结果。-1:前排序,0:与buf相同,1:后排序。 | | number | 比较结果。-1:前排序,0:与buf相同,1:后排序。 |
...@@ -1608,7 +1620,7 @@ let length = buffer1.write('abcd', 8); ...@@ -1608,7 +1620,7 @@ let length = buffer1.write('abcd', 8);
writeBigInt64BE(value: bigint, offset?: number): number writeBigInt64BE(value: bigint, offset?: number): number
从buf的offset偏移写入大端序的64位BigInt型数据value 从buf的offset偏移写入有符号的大端序64位BigInt型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1639,7 +1651,7 @@ buf.writeBigInt64BE(0x0102030405060708n, 0); ...@@ -1639,7 +1651,7 @@ buf.writeBigInt64BE(0x0102030405060708n, 0);
writeBigInt64LE(value: bigint, offset?: number): number writeBigInt64LE(value: bigint, offset?: number): number
从buf的offset偏移写入小端序的64位BigInt型数据value 从buf的offset偏移写入有符号的小端序64位BigInt型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1670,7 +1682,7 @@ buf.writeBigInt64LE(0x0102030405060708n, 0); ...@@ -1670,7 +1682,7 @@ buf.writeBigInt64LE(0x0102030405060708n, 0);
writeBigUInt64BE(value: bigint, offset?: number): number writeBigUInt64BE(value: bigint, offset?: number): number
从buf的offset偏移写入大端序的64位BigUInt型数据value 从buf的offset偏移写入无符号的大端序64位BigUInt型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1701,7 +1713,7 @@ buf.writeBigUInt64BE(0xdecafafecacefaden, 0); ...@@ -1701,7 +1713,7 @@ buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
writeBigUInt64LE(value: bigint, offset?: number): number writeBigUInt64LE(value: bigint, offset?: number): number
从buf的offset偏移写入小端序的64位BigUInt型数据value 从buf的offset偏移写入无符号的小端序64位BigUInt型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1732,7 +1744,7 @@ buf.writeBigUInt64LE(0xdecafafecacefaden, 0); ...@@ -1732,7 +1744,7 @@ buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
writeDoubleBE(value: number, offset?: number): number writeDoubleBE(value: number, offset?: number): number
从buf的offset偏移写入大端序的64位有符号双浮点型数据value 从buf的offset偏移写入大端序的64位双浮点型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1763,7 +1775,7 @@ buf.writeDoubleBE(123.456, 0); ...@@ -1763,7 +1775,7 @@ buf.writeDoubleBE(123.456, 0);
writeDoubleLE(value: number, offset?: number): number writeDoubleLE(value: number, offset?: number): number
从buf的offset偏移写入小端序的64位有符号双浮点型数据value 从buf的offset偏移写入小端序的64位双浮点型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1794,7 +1806,7 @@ buf.writeDoubleLE(123.456, 0); ...@@ -1794,7 +1806,7 @@ buf.writeDoubleLE(123.456, 0);
writeFloatBE(value: number, offset?: number): number writeFloatBE(value: number, offset?: number): number
从buf的offset偏移写入大端序的32位有符号浮点型数据value 从buf的offset偏移写入大端序的32位浮点型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -1826,7 +1838,7 @@ buf.writeFloatBE(0xcafebabe, 0); ...@@ -1826,7 +1838,7 @@ buf.writeFloatBE(0xcafebabe, 0);
writeFloatLE(value: number, offset?: number): number writeFloatLE(value: number, offset?: number): number
从buf的offset偏移写入小端序的32位有符号浮点型数据value 从buf的offset偏移写入小端序的32位浮点型数据value
**系统能力:** SystemCapability.Utils.Lang **系统能力:** SystemCapability.Utils.Lang
...@@ -2419,7 +2431,7 @@ slice(start?: number, end?: number, type?: string): Blob ...@@ -2419,7 +2431,7 @@ slice(start?: number, end?: number, type?: string): Blob
let blob3 = blob.slice(0, 2, "MIME"); let blob3 = blob.slice(0, 2, "MIME");
``` ```
### text ### text
text(): Promise&lt;string&gt; text(): Promise&lt;string&gt;
......
...@@ -11,6 +11,9 @@ Deque和[Queue](js-apis-queue.md)相比,Queue的特点是先进先出,只能 ...@@ -11,6 +11,9 @@ Deque和[Queue](js-apis-queue.md)相比,Queue的特点是先进先出,只能
**推荐使用场景:** 需要频繁在集合两端进行增删元素的操作时,推荐使用Deque。 **推荐使用场景:** 需要频繁在集合两端进行增删元素的操作时,推荐使用Deque。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -63,7 +66,7 @@ deque.insertFront("a"); ...@@ -63,7 +66,7 @@ deque.insertFront("a");
deque.insertFront(1); deque.insertFront(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertFront(b); deque.insertFront(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertFront(false); deque.insertFront(false);
``` ```
...@@ -89,7 +92,7 @@ deque.insertEnd("a"); ...@@ -89,7 +92,7 @@ deque.insertEnd("a");
deque.insertEnd(1); deque.insertEnd(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
deque.insertEnd(b); deque.insertEnd(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
deque.insertEnd(false); deque.insertEnd(false);
``` ```
...@@ -117,9 +120,9 @@ has(element: T): boolean ...@@ -117,9 +120,9 @@ has(element: T): boolean
```ts ```ts
let deque = new Deque(); let deque = new Deque();
let result = deque.has("Ahfbrgrbgnutfodgorrogorg"); let result = deque.has("squirrel");
deque.insertFront("Ahfbrgrbgnutfodgorrogorg"); deque.insertFront("squirrel");
let result1 = deque.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = deque.has("squirrel");
``` ```
### popFirst ### popFirst
......
...@@ -11,6 +11,10 @@ HashMap和[TreeMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存 ...@@ -11,6 +11,10 @@ HashMap和[TreeMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存
**推荐使用场景:** 需要快速存取、删除以及插入键值对数据时,推荐使用HashMap。 **推荐使用场景:** 需要快速存取、删除以及插入键值对数据时,推荐使用HashMap。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- K: Key, 键<br>
- V: Value, 值
## 导入模块 ## 导入模块
```ts ```ts
...@@ -89,9 +93,9 @@ hasKey(key: K): boolean ...@@ -89,9 +93,9 @@ hasKey(key: K): boolean
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashMap.hasKey("squirrel");
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = hashMap.hasKey("squirrel");
``` ```
...@@ -120,7 +124,7 @@ hasValue(value: V): boolean ...@@ -120,7 +124,7 @@ hasValue(value: V): boolean
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.hasValue(123); let result = hashMap.hasValue(123);
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
let result1 = hashMap.hasValue(123); let result1 = hashMap.hasValue(123);
``` ```
...@@ -149,9 +153,9 @@ get(key: K): V ...@@ -149,9 +153,9 @@ get(key: K): V
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let result = hashMap.get("sdfs"); let result = hashMap.get("sparrow");
``` ```
...@@ -173,8 +177,8 @@ setAll(map: HashMap<K, V>): void ...@@ -173,8 +177,8 @@ setAll(map: HashMap<K, V>): void
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let newHashMap = new HashMap(); let newHashMap = new HashMap();
hashMap.setAll(newHashMap); hashMap.setAll(newHashMap);
``` ```
...@@ -205,7 +209,7 @@ set(key: K, value: V): Object ...@@ -205,7 +209,7 @@ set(key: K, value: V): Object
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
let result = hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); let result = hashMap.set("squirrel", 123);
``` ```
...@@ -233,9 +237,9 @@ remove(key: K): V ...@@ -233,9 +237,9 @@ remove(key: K): V
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let result = hashMap.remove("sdfs"); let result = hashMap.remove("sparrow");
``` ```
...@@ -251,8 +255,8 @@ clear(): void ...@@ -251,8 +255,8 @@ clear(): void
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
hashMap.clear(); hashMap.clear();
``` ```
...@@ -275,8 +279,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -275,8 +279,8 @@ keys(): IterableIterator&lt;K&gt;
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.keys(); let iter = hashMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -304,8 +308,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -304,8 +308,8 @@ values(): IterableIterator&lt;V&gt;
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.values(); let iter = hashMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -340,8 +344,8 @@ replace(key: K, newValue: V): boolean ...@@ -340,8 +344,8 @@ replace(key: K, newValue: V): boolean
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("sdfs", 123); hashMap.set("sparrow", 123);
let result = hashMap.replace("sdfs", 357); let result = hashMap.replace("sparrow", 357);
``` ```
...@@ -371,8 +375,8 @@ callbackfn的参数说明: ...@@ -371,8 +375,8 @@ callbackfn的参数说明:
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("sdfs", 123); hashMap.set("sparrow", 123);
hashMap.set("dfsghsf", 357); hashMap.set("gull", 357);
hashMap.forEach((value, key) => { hashMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -397,8 +401,8 @@ entries(): IterableIterator&lt;[K, V]&gt; ...@@ -397,8 +401,8 @@ entries(): IterableIterator&lt;[K, V]&gt;
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
let iter = hashMap.entries(); let iter = hashMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -426,8 +430,8 @@ while(temp != undefined) { ...@@ -426,8 +430,8 @@ while(temp != undefined) {
**示例:** **示例:**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); hashMap.set("squirrel", 123);
hashMap.set("sdfs", 356); hashMap.set("sparrow", 356);
// 使用方法一: // 使用方法一:
for (let item of hashMap) { for (let item of hashMap) {
......
...@@ -9,6 +9,9 @@ HashSet和[TreeSet](js-apis-treeset.md)相比,HashSet中的数据无序存放 ...@@ -9,6 +9,9 @@ HashSet和[TreeSet](js-apis-treeset.md)相比,HashSet中的数据无序存放
**推荐使用场景:** 可以利用HashSet不重复的特性,当需要不重复的集合或需要去重某个集合的时候使用。 **推荐使用场景:** 可以利用HashSet不重复的特性,当需要不重复的集合或需要去重某个集合的时候使用。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -25,6 +28,17 @@ import HashSet from '@ohos.util.HashSet'; ...@@ -25,6 +28,17 @@ import HashSet from '@ohos.util.HashSet';
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | 是 | 否 | HashSet的元素个数。 | | length | number | 是 | 否 | HashSet的元素个数。 |
**示例:**
```ts
let hashSet = new HashSet();
hashSet.add(1);
hashSet.add(2);
hashSet.add(3);
hashSet.add(4);
hashSet.add(5);
let res = hashSet.length;
```
### constructor ### constructor
...@@ -87,9 +101,9 @@ has(value: T): boolean ...@@ -87,9 +101,9 @@ has(value: T): boolean
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
let result = hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashSet.has("squirrel");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
let result1 = hashSet.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = hashSet.has("squirrel");
``` ```
...@@ -117,7 +131,7 @@ add(value: T): boolean ...@@ -117,7 +131,7 @@ add(value: T): boolean
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
let result = hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = hashSet.add("squirrel");
``` ```
...@@ -145,9 +159,9 @@ remove(value: T): boolean ...@@ -145,9 +159,9 @@ remove(value: T): boolean
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let result = hashSet.remove("sdfs"); let result = hashSet.remove("sparrow");
``` ```
...@@ -163,8 +177,8 @@ clear(): void ...@@ -163,8 +177,8 @@ clear(): void
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
hashSet.clear(); hashSet.clear();
``` ```
...@@ -187,8 +201,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -187,8 +201,8 @@ values(): IterableIterator&lt;T&gt;
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let iter = hashSet.values(); let iter = hashSet.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -224,8 +238,8 @@ callbackfn的参数说明: ...@@ -224,8 +238,8 @@ callbackfn的参数说明:
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("sdfs"); hashSet.add("sparrow");
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.forEach((value, key) => { hashSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -249,8 +263,8 @@ entries(): IterableIterator<[T, T]> ...@@ -249,8 +263,8 @@ entries(): IterableIterator<[T, T]>
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
let iter = hashSet.entries(); let iter = hashSet.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -279,8 +293,8 @@ while(temp != undefined) { ...@@ -279,8 +293,8 @@ while(temp != undefined) {
```ts ```ts
let hashSet = new HashSet(); let hashSet = new HashSet();
hashSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); hashSet.add("squirrel");
hashSet.add("sdfs"); hashSet.add("sparrow");
// 使用方法一: // 使用方法一:
for (let item of hashSet) { for (let item of hashSet) {
......
...@@ -11,6 +11,10 @@ LightWeightMap和[HashMap](js-apis-hashmap.md)都是用来存储键值对的集 ...@@ -11,6 +11,10 @@ LightWeightMap和[HashMap](js-apis-hashmap.md)都是用来存储键值对的集
**推荐使用场景:** 当需要存取key-value键值对时,推荐使用占用内存更小的LightWeightMap。 **推荐使用场景:** 当需要存取key-value键值对时,推荐使用占用内存更小的LightWeightMap。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- K: Key, 键<br>
- V: Value, 值
## 导入模块 ## 导入模块
```ts ```ts
...@@ -91,10 +95,10 @@ hasAll(map: LightWeightMap<K, V>): boolean ...@@ -91,10 +95,10 @@ hasAll(map: LightWeightMap<K, V>): boolean
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap(); let map = new LightWeightMap();
map.set("sdfs", 356); map.set("sparrow", 356);
let result = lightWeightMap.hasAll(map); let result = lightWeightMap.hasAll(map);
``` ```
...@@ -124,9 +128,9 @@ hasKey(key: K): boolean; ...@@ -124,9 +128,9 @@ hasKey(key: K): boolean;
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasKey; let result = lightWeightMap.hasKey;
lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightMap.hasKey("squirrel");
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = lightWeightMap.hasKey("squirrel");
``` ```
...@@ -155,7 +159,7 @@ hasValue(value: V): boolean ...@@ -155,7 +159,7 @@ hasValue(value: V): boolean
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasValue(123); let result = lightWeightMap.hasValue(123);
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasValue(123); let result1 = lightWeightMap.hasValue(123);
``` ```
...@@ -206,9 +210,9 @@ get(key: K): V ...@@ -206,9 +210,9 @@ get(key: K): V
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.get("sdfs"); let result = lightWeightMap.get("sparrow");
``` ```
...@@ -236,9 +240,9 @@ getIndexOfKey(key: K): number ...@@ -236,9 +240,9 @@ getIndexOfKey(key: K): number
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getIndexOfKey("sdfs"); let result = lightWeightMap.getIndexOfKey("sparrow");
``` ```
...@@ -266,8 +270,8 @@ getIndexOfValue(value: V): number ...@@ -266,8 +270,8 @@ getIndexOfValue(value: V): number
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getIndexOfValue(123); let result = lightWeightMap.getIndexOfValue(123);
``` ```
...@@ -296,8 +300,8 @@ getKeyAt(index: number): K ...@@ -296,8 +300,8 @@ getKeyAt(index: number): K
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getKeyAt(1); let result = lightWeightMap.getKeyAt(1);
``` ```
...@@ -320,8 +324,8 @@ setAll(map: LightWeightMap<K, V>): void ...@@ -320,8 +324,8 @@ setAll(map: LightWeightMap<K, V>): void
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap(); let map = new LightWeightMap();
lightWeightMap.setAll(map); lightWeightMap.setAll(map);
``` ```
...@@ -351,7 +355,7 @@ set(key: K, value: V): Object ...@@ -351,7 +355,7 @@ set(key: K, value: V): Object
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); let result = lightWeightMap.set("squirrel", 123);
``` ```
...@@ -379,9 +383,9 @@ remove(key: K): V ...@@ -379,9 +383,9 @@ remove(key: K): V
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.remove("sdfs"); lightWeightMap.remove("sparrow");
``` ```
...@@ -409,8 +413,8 @@ removeAt(index: number): boolean ...@@ -409,8 +413,8 @@ removeAt(index: number): boolean
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.removeAt(1); let result = lightWeightMap.removeAt(1);
``` ```
...@@ -440,8 +444,8 @@ setValueAt(index: number, newValue: V): boolean ...@@ -440,8 +444,8 @@ setValueAt(index: number, newValue: V): boolean
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.setValueAt(1, 3546); lightWeightMap.setValueAt(1, 3546);
``` ```
...@@ -470,8 +474,8 @@ getValueAt(index: number): V ...@@ -470,8 +474,8 @@ getValueAt(index: number): V
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let result = lightWeightMap.getValueAt(1); let result = lightWeightMap.getValueAt(1);
``` ```
...@@ -488,8 +492,8 @@ clear(): void ...@@ -488,8 +492,8 @@ clear(): void
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
lightWeightMap.clear(); lightWeightMap.clear();
``` ```
...@@ -512,8 +516,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -512,8 +516,8 @@ keys(): IterableIterator&lt;K&gt;
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.keys(); let iter = lightWeightMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -541,8 +545,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -541,8 +545,8 @@ values(): IterableIterator&lt;V&gt;
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.values(); let iter = lightWeightMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -578,8 +582,8 @@ callbackfn的参数说明: ...@@ -578,8 +582,8 @@ callbackfn的参数说明:
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("sdfs", 123); lightWeightMap.set("sparrow", 123);
lightWeightMap.set("dfsghsf", 357); lightWeightMap.set("gull", 357);
lightWeightMap.forEach((value, key) => { lightWeightMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -604,8 +608,8 @@ entries(): IterableIterator<[K, V]> ...@@ -604,8 +608,8 @@ entries(): IterableIterator<[K, V]>
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.entries(); let iter = lightWeightMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -633,8 +637,8 @@ toString(): String ...@@ -633,8 +637,8 @@ toString(): String
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("A", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.toString(); let iter = lightWeightMap.toString();
``` ```
...@@ -656,8 +660,8 @@ toString(): String ...@@ -656,8 +660,8 @@ toString(): String
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sdfs", 356); lightWeightMap.set("sparrow", 356);
// 使用方法一: // 使用方法一:
for (let item of lightWeightMap) { for (let item of lightWeightMap) {
......
...@@ -13,6 +13,9 @@ LightWeightSet和[HashSet](js-apis-hashset.md)都是用来存储键值的集合 ...@@ -13,6 +13,9 @@ LightWeightSet和[HashSet](js-apis-hashset.md)都是用来存储键值的集合
**推荐使用场景:** 当需要存取某个集合或是对某个集合去重时,推荐使用占用内存更小的LightWeightSet。 **推荐使用场景:** 当需要存取某个集合或是对某个集合去重时,推荐使用占用内存更小的LightWeightSet。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -92,7 +95,7 @@ add(obj: T): boolean ...@@ -92,7 +95,7 @@ add(obj: T): boolean
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = lightWeightSet.add("squirrel");
``` ```
...@@ -114,10 +117,10 @@ addAll(set: LightWeightSet&lt;T&gt;): boolean ...@@ -114,10 +117,10 @@ addAll(set: LightWeightSet&lt;T&gt;): boolean
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("sfage"); set.add("gull");
let result = lightWeightSet.addAll(set); let result = lightWeightSet.addAll(set);
``` ```
...@@ -146,10 +149,10 @@ hasAll(set: LightWeightSet&lt;T&gt;): boolean ...@@ -146,10 +149,10 @@ hasAll(set: LightWeightSet&lt;T&gt;): boolean
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let set = new LightWeightSet(); let set = new LightWeightSet();
set.add("sdfs"); set.add("sparrow");
let result = lightWeightSet.hasAll(set); let result = lightWeightSet.hasAll(set);
``` ```
...@@ -208,9 +211,9 @@ equal(obj: Object): boolean ...@@ -208,9 +211,9 @@ equal(obj: Object): boolean
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let obj = ["Ahfbrgrbgnutfodgorrogorgrogofdfdf", "sdfs"]; let obj = ["squirrel", "sparrow"];
let result = lightWeightSet.equal(obj); let result = lightWeightSet.equal(obj);
``` ```
...@@ -261,9 +264,9 @@ getIndexOf(key: T): number ...@@ -261,9 +264,9 @@ getIndexOf(key: T): number
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getIndexOf("sdfs"); let result = lightWeightSet.getIndexOf("sparrow");
``` ```
...@@ -291,9 +294,9 @@ remove(key: T): T ...@@ -291,9 +294,9 @@ remove(key: T): T
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.remove("sdfs"); let result = lightWeightSet.remove("sparrow");
``` ```
...@@ -321,8 +324,8 @@ removeAt(index: number): boolean ...@@ -321,8 +324,8 @@ removeAt(index: number): boolean
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.removeAt(1); let result = lightWeightSet.removeAt(1);
``` ```
...@@ -351,8 +354,8 @@ getValueAt(index: number): T ...@@ -351,8 +354,8 @@ getValueAt(index: number): T
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.getValueAt(1); let result = lightWeightSet.getValueAt(1);
``` ```
...@@ -369,8 +372,8 @@ clear(): void ...@@ -369,8 +372,8 @@ clear(): void
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
lightWeightSet.clear(); lightWeightSet.clear();
``` ```
...@@ -393,8 +396,8 @@ toString(): String ...@@ -393,8 +396,8 @@ toString(): String
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toString(); let result = lightWeightSet.toString();
``` ```
...@@ -417,8 +420,8 @@ toArray(): Array&lt;T&gt; ...@@ -417,8 +420,8 @@ toArray(): Array&lt;T&gt;
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let result = lightWeightSet.toArray(); let result = lightWeightSet.toArray();
``` ```
...@@ -441,8 +444,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -441,8 +444,8 @@ values(): IterableIterator&lt;T&gt;
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let iter = lightWeightSet.values(); let iter = lightWeightSet.values();
let index = 0; let index = 0;
while(index < lightWeightSet.length) { while(index < lightWeightSet.length) {
...@@ -478,8 +481,8 @@ callbackfn的参数说明: ...@@ -478,8 +481,8 @@ callbackfn的参数说明:
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
lightWeightSet.add("dfsghsf"); lightWeightSet.add("gull");
lightWeightSet.forEach((value, key) => { lightWeightSet.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -504,8 +507,8 @@ entries(): IterableIterator<[T, T]> ...@@ -504,8 +507,8 @@ entries(): IterableIterator<[T, T]>
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
let iter = lightWeightSet.entries(); let iter = lightWeightSet.entries();
let index = 0; let index = 0;
while(index < lightWeightSet.length) { while(index < lightWeightSet.length) {
...@@ -533,8 +536,8 @@ while(index < lightWeightSet.length) { ...@@ -533,8 +536,8 @@ while(index < lightWeightSet.length) {
```ts ```ts
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
lightWeightSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); lightWeightSet.add("squirrel");
lightWeightSet.add("sdfs"); lightWeightSet.add("sparrow");
// 使用方法一: // 使用方法一:
for (let item of lightWeightSet) { for (let item of lightWeightSet) {
......
...@@ -11,6 +11,9 @@ LinkedList和[ArrayList](js-apis-arraylist.md)相比,存取数据的效率不 ...@@ -11,6 +11,9 @@ LinkedList和[ArrayList](js-apis-arraylist.md)相比,存取数据的效率不
**推荐使用场景:** 当需要频繁的插入删除时,推荐使用LinkedList高效操作。 **推荐使用场景:** 当需要频繁的插入删除时,推荐使用LinkedList高效操作。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -75,7 +78,7 @@ let result = linkedList.add("a"); ...@@ -75,7 +78,7 @@ let result = linkedList.add("a");
let result1 = linkedList.add(1); let result1 = linkedList.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.add(b); linkedList.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = linkedList.add(false); let result3 = linkedList.add(false);
``` ```
...@@ -101,7 +104,7 @@ linkedList.addFirst("a"); ...@@ -101,7 +104,7 @@ linkedList.addFirst("a");
linkedList.addFirst(1); linkedList.addFirst(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
linkedList.addFirst(b); linkedList.addFirst(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
linkedList.addFirst(false); linkedList.addFirst(false);
``` ```
...@@ -153,9 +156,9 @@ has(element: T): boolean ...@@ -153,9 +156,9 @@ has(element: T): boolean
```ts ```ts
let linkedList = new LinkedList(); let linkedList = new LinkedList();
let result1 = linkedList.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = linkedList.has("squirrel");
linkedList.add("Ahfbrgrbgnutfodgorrogorg"); linkedList.add("squirrel");
let result = linkedList.has("Ahfbrgrbgnutfodgorrogorg"); let result = linkedList.has("squirrel");
``` ```
### get ### get
......
...@@ -9,6 +9,9 @@ List和[LinkedList](js-apis-linkedlist.md)相比,LinkedList是双向链表, ...@@ -9,6 +9,9 @@ List和[LinkedList](js-apis-linkedlist.md)相比,LinkedList是双向链表,
**推荐使用场景:** 当需要频繁的插入删除时,推荐使用List高效操作。 **推荐使用场景:** 当需要频繁的插入删除时,推荐使用List高效操作。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -71,7 +74,7 @@ let result = list.add("a"); ...@@ -71,7 +74,7 @@ let result = list.add("a");
let result1 = list.add(1); let result1 = list.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
list.add(b); list.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = list.add(false); let result3 = list.add(false);
``` ```
...@@ -123,9 +126,9 @@ has(element: T): boolean ...@@ -123,9 +126,9 @@ has(element: T): boolean
```ts ```ts
let list = new List(); let list = new List();
let result = list.has("Ahfbrgrbgnutfodgorrogorg"); let result = list.has("squirrel");
list.add("Ahfbrgrbgnutfodgorrogorg"); list.add("squirrel");
let result1 = list.has("Ahfbrgrbgnutfodgorrogorg"); let result1 = list.has("squirrel");
``` ```
### get ### get
...@@ -180,7 +183,7 @@ getLastIndexOf(element: T): number ...@@ -180,7 +183,7 @@ getLastIndexOf(element: T): number
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| number | 查找指定元素最后一次出现的下标值,查找失败返回-1。 | | number | 返回指定元素最后一次出现的下标值,没有找到返回-1。 |
**示例:** **示例:**
...@@ -249,7 +252,7 @@ equal(obj: Object): boolean ...@@ -249,7 +252,7 @@ equal(obj: Object): boolean
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| boolean | 如果对象与此列表相同回true,否则返回false。 | | boolean | 如果对象与此列表相同回true,否则返回false。 |
**示例:** **示例:**
...@@ -264,7 +267,7 @@ obj1.add(2); ...@@ -264,7 +267,7 @@ obj1.add(2);
obj1.add(4); obj1.add(4);
obj1.add(5); obj1.add(5);
list.equal(obj1); list.equal(obj1);
let obj2 = {name : "lala", age : "13"}; let obj2 = {name : "Dylon", age : "13"};
let result = list.equal(obj2); let result = list.equal(obj2);
``` ```
......
...@@ -11,6 +11,9 @@ PlainArray和[LightWeightMap](js-apis-lightweightmap.md)都是用来存储键值 ...@@ -11,6 +11,9 @@ PlainArray和[LightWeightMap](js-apis-lightweightmap.md)都是用来存储键值
**推荐使用场景:** 当需要存储key值为number类型的键值对时,可以使用PlainArray。 **推荐使用场景:** 当需要存储key值为number类型的键值对时,可以使用PlainArray。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -92,7 +95,7 @@ has(key: number): boolean ...@@ -92,7 +95,7 @@ has(key: number): boolean
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.has(1); plainArray.has(1);
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
let result1 = plainArray.has(1); let result1 = plainArray.has(1);
``` ```
...@@ -121,8 +124,8 @@ get(key: number): T ...@@ -121,8 +124,8 @@ get(key: number): T
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.get(1); let result = plainArray.get(1);
``` ```
...@@ -151,8 +154,8 @@ getIndexOfKey(key: number): number ...@@ -151,8 +154,8 @@ getIndexOfKey(key: number): number
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfKey(2); let result = plainArray.getIndexOfKey(2);
``` ```
...@@ -181,9 +184,9 @@ getIndexOfValue(value: T): number ...@@ -181,9 +184,9 @@ getIndexOfValue(value: T): number
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getIndexOfValue("sddfhf"); let result = plainArray.getIndexOfValue("squirrel");
``` ```
...@@ -211,8 +214,8 @@ getKeyAt(index: number): number ...@@ -211,8 +214,8 @@ getKeyAt(index: number): number
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getKeyAt(1);
``` ```
...@@ -240,8 +243,8 @@ getValueAt(index: number): T ...@@ -240,8 +243,8 @@ getValueAt(index: number): T
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.getKeyAt(1); let result = plainArray.getKeyAt(1);
``` ```
...@@ -263,8 +266,8 @@ clone(): PlainArray&lt;T&gt; ...@@ -263,8 +266,8 @@ clone(): PlainArray&lt;T&gt;
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let newPlainArray = plainArray.clone(); let newPlainArray = plainArray.clone();
``` ```
...@@ -288,7 +291,7 @@ add(key: number, value: T): void ...@@ -288,7 +291,7 @@ add(key: number, value: T): void
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
``` ```
...@@ -316,8 +319,8 @@ remove(key: number): T ...@@ -316,8 +319,8 @@ remove(key: number): T
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.remove(2); plainArray.remove(2);
let result = plainArray.remove(2); let result = plainArray.remove(2);
``` ```
...@@ -347,8 +350,8 @@ removeAt(index: number): T ...@@ -347,8 +350,8 @@ removeAt(index: number): T
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.removeAt(1); plainArray.removeAt(1);
let result = plainArray.removeAt(1); let result = plainArray.removeAt(1);
``` ```
...@@ -379,8 +382,8 @@ removeRangeFrom(index: number, size: number): number ...@@ -379,8 +382,8 @@ removeRangeFrom(index: number, size: number): number
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.removeRangeFrom(1, 3); let result = plainArray.removeRangeFrom(1, 3);
``` ```
...@@ -404,8 +407,8 @@ setValueAt(index: number, value: T): void ...@@ -404,8 +407,8 @@ setValueAt(index: number, value: T): void
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.setValueAt(1, 3546); plainArray.setValueAt(1, 3546);
``` ```
...@@ -428,8 +431,8 @@ toString(): String ...@@ -428,8 +431,8 @@ toString(): String
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
let result = plainArray.toString(); let result = plainArray.toString();
``` ```
...@@ -446,8 +449,8 @@ clear(): void ...@@ -446,8 +449,8 @@ clear(): void
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.clear(); plainArray.clear();
``` ```
...@@ -478,8 +481,8 @@ callbackfn的参数说明: ...@@ -478,8 +481,8 @@ callbackfn的参数说明:
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
plainArray.forEach((value, index) => { plainArray.forEach((value, index) => {
console.log("value:" + value, index); console.log("value:" + value, index);
}); });
...@@ -504,8 +507,8 @@ plainArray.forEach((value, index) => { ...@@ -504,8 +507,8 @@ plainArray.forEach((value, index) => {
```ts ```ts
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(1, "sddfhf"); plainArray.add(1, "squirrel");
plainArray.add(2, "sffdfhf"); plainArray.add(2, "sparrow");
// 使用方法一: // 使用方法一:
for (let item of plainArray) { for (let item of plainArray) {
......
...@@ -9,6 +9,9 @@ Queue和[Deque](js-apis-deque.md)相比,Queue只能在一端删除一端增加 ...@@ -9,6 +9,9 @@ Queue和[Deque](js-apis-deque.md)相比,Queue只能在一端删除一端增加
**推荐使用场景:** 一般符合先进先出的场景可以使用Queue。 **推荐使用场景:** 一般符合先进先出的场景可以使用Queue。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -71,7 +74,7 @@ let result1 = queue.add(1); ...@@ -71,7 +74,7 @@ let result1 = queue.add(1);
queue.add(1); queue.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
queue.add(b); queue.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = queue.add(c); let result3 = queue.add(c);
``` ```
......
...@@ -9,6 +9,9 @@ Stack和[Queue](js-apis-queue.md)相比,Queue基于循环队列实现,只能 ...@@ -9,6 +9,9 @@ Stack和[Queue](js-apis-queue.md)相比,Queue基于循环队列实现,只能
**推荐使用场景:** 一般符合先进后出的场景可以使用Stack。 **推荐使用场景:** 一般符合先进后出的场景可以使用Stack。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -72,7 +75,7 @@ let result = stack.push("a"); ...@@ -72,7 +75,7 @@ let result = stack.push("a");
let result1 = stack.push(1); let result1 = stack.push(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
stack.push(b); stack.push(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = stack.push(c); let result3 = stack.push(c);
``` ```
......
...@@ -11,6 +11,10 @@ TreeMap和[HashMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存 ...@@ -11,6 +11,10 @@ TreeMap和[HashMap](js-apis-treemap.md)相比,HashMap依据键的hashCode存
**推荐使用场景:** 一般需要存储有序键值对的场景,可以使用TreeMap。 **推荐使用场景:** 一般需要存储有序键值对的场景,可以使用TreeMap。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- K: Key, 键<br>
- V: Value, 值
## 导入模块 ## 导入模块
```ts ```ts
...@@ -95,9 +99,9 @@ hasKey(key: K): boolean ...@@ -95,9 +99,9 @@ hasKey(key: K): boolean
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
let result = treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = treeMap.hasKey("squirrel");
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
let result1 = treeMap.hasKey("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = treeMap.hasKey("squirrel");
``` ```
...@@ -126,7 +130,7 @@ hasValue(value: V): boolean ...@@ -126,7 +130,7 @@ hasValue(value: V): boolean
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
let result = treeMap.hasValue(123); let result = treeMap.hasValue(123);
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
let result1 = treeMap.hasValue(123); let result1 = treeMap.hasValue(123);
``` ```
...@@ -155,9 +159,9 @@ get(key: K): V ...@@ -155,9 +159,9 @@ get(key: K): V
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.get("sdfs"); let result = treeMap.get("sparrow");
``` ```
...@@ -179,8 +183,8 @@ getFirstKey(): K ...@@ -179,8 +183,8 @@ getFirstKey(): K
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.getFirstKey(); let result = treeMap.getFirstKey();
``` ```
...@@ -203,8 +207,8 @@ getLastKey(): K ...@@ -203,8 +207,8 @@ getLastKey(): K
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let result = treeMap.getLastKey(); let result = treeMap.getLastKey();
``` ```
...@@ -227,8 +231,8 @@ setAll(map: TreeMap<K, V>): void ...@@ -227,8 +231,8 @@ setAll(map: TreeMap<K, V>): void
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let map = new TreeMap(); let map = new TreeMap();
treeMap.setAll(map); treeMap.setAll(map);
``` ```
...@@ -259,7 +263,7 @@ set(key: K, value: V): Object ...@@ -259,7 +263,7 @@ set(key: K, value: V): Object
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
``` ```
...@@ -287,9 +291,9 @@ remove(key: K): V ...@@ -287,9 +291,9 @@ remove(key: K): V
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.remove("sdfs"); treeMap.remove("sparrow");
``` ```
...@@ -317,10 +321,10 @@ getLowerKey(key: K): K ...@@ -317,10 +321,10 @@ getLowerKey(key: K): K
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.set("zdfgsd", 356); treeMap.set("gander", 356);
let result = treeMap.getLowerKey("sdfs"); let result = treeMap.getLowerKey("sparrow");
``` ```
...@@ -348,10 +352,10 @@ getHigherKey(key: K): K ...@@ -348,10 +352,10 @@ getHigherKey(key: K): K
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.set("zdfgsd", 356); treeMap.set("gander", 356);
let result = treeMap.getHigherKey("sdfs"); let result = treeMap.getHigherKey("sparrow");
``` ```
### replace ### replace
...@@ -379,8 +383,8 @@ replace(key: K, newValue: V): boolean ...@@ -379,8 +383,8 @@ replace(key: K, newValue: V): boolean
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("sdfs", 123); treeMap.set("sparrow", 123);
let result = treeMap.replace("sdfs", 357); let result = treeMap.replace("sparrow", 357);
``` ```
...@@ -396,8 +400,8 @@ clear(): void ...@@ -396,8 +400,8 @@ clear(): void
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
treeMap.clear(); treeMap.clear();
``` ```
...@@ -420,8 +424,8 @@ keys(): IterableIterator&lt;K&gt; ...@@ -420,8 +424,8 @@ keys(): IterableIterator&lt;K&gt;
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.keys(); let iter = treeMap.keys();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -449,8 +453,8 @@ values(): IterableIterator&lt;V&gt; ...@@ -449,8 +453,8 @@ values(): IterableIterator&lt;V&gt;
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.values(); let iter = treeMap.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -486,8 +490,8 @@ callbackfn的参数说明: ...@@ -486,8 +490,8 @@ callbackfn的参数说明:
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("sdfs", 123); treeMap.set("sparrow", 123);
treeMap.set("dfsghsf", 357); treeMap.set("gull", 357);
treeMap.forEach((value, key) => { treeMap.forEach((value, key) => {
console.log("value:" + value, key); console.log("value:" + value, key);
}); });
...@@ -512,8 +516,8 @@ entries(): IterableIterator<[K, V]> ...@@ -512,8 +516,8 @@ entries(): IterableIterator<[K, V]>
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
let iter = treeMap.entries(); let iter = treeMap.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -541,8 +545,8 @@ while(temp != undefined) { ...@@ -541,8 +545,8 @@ while(temp != undefined) {
```ts ```ts
let treeMap = new TreeMap(); let treeMap = new TreeMap();
treeMap.set("Ahfbrgrbgnutfodgorrogorgrogofdfdf", 123); treeMap.set("squirrel", 123);
treeMap.set("sdfs", 356); treeMap.set("sparrow", 356);
// 使用方法一: // 使用方法一:
for (let item of treeMap) { for (let item of treeMap) {
......
...@@ -9,6 +9,9 @@ TreeSet和[HashSet](js-apis-hashset.md)相比,HashSet中的数据无序存放 ...@@ -9,6 +9,9 @@ TreeSet和[HashSet](js-apis-hashset.md)相比,HashSet中的数据无序存放
**推荐使用场景:** 一般需要存储有序集合的场景,可以使用TreeSet。 **推荐使用场景:** 一般需要存储有序集合的场景,可以使用TreeSet。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -28,7 +31,7 @@ import TreeSet from '@ohos.util.TreeSet'; ...@@ -28,7 +31,7 @@ import TreeSet from '@ohos.util.TreeSet';
### constructor ### constructor
constructor(comparator?:(firstValue: T, secondValue: T) => boolean) constructor(comparator?: (firstValue: T, secondValue: T) => boolean)
TreeSet的构造函数。 TreeSet的构造函数。
...@@ -117,8 +120,8 @@ getFirstValue(): T ...@@ -117,8 +120,8 @@ getFirstValue(): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.getFirstValue(); let result = treeSet.getFirstValue();
``` ```
...@@ -141,8 +144,8 @@ getLastValue(): T ...@@ -141,8 +144,8 @@ getLastValue(): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.getLastValue(); let result = treeSet.getLastValue();
``` ```
...@@ -171,7 +174,7 @@ add(value: T): boolean ...@@ -171,7 +174,7 @@ add(value: T): boolean
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
let result = treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = treeSet.add("squirrel");
``` ```
...@@ -199,9 +202,9 @@ remove(value: T): boolean ...@@ -199,9 +202,9 @@ remove(value: T): boolean
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.remove("sdfs"); let result = treeSet.remove("sparrow");
``` ```
...@@ -229,10 +232,10 @@ getLowerValue(key: T): T ...@@ -229,10 +232,10 @@ getLowerValue(key: T): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("zdfgsd"); treeSet.add("gander");
let result = treeSet.getLowerValue("sdfs"); let result = treeSet.getLowerValue("sparrow");
``` ```
...@@ -260,10 +263,10 @@ getHigherValue(key: T): T ...@@ -260,10 +263,10 @@ getHigherValue(key: T): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("zdfgsd"); treeSet.add("gander");
let result = treeSet.getHigherValue("sdfs"); let result = treeSet.getHigherValue("sparrow");
``` ```
...@@ -285,8 +288,8 @@ popFirst(): T ...@@ -285,8 +288,8 @@ popFirst(): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.popFirst(); let result = treeSet.popFirst();
``` ```
...@@ -309,8 +312,8 @@ popLast(): T ...@@ -309,8 +312,8 @@ popLast(): T
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let result = treeSet.popLast(); let result = treeSet.popLast();
``` ```
...@@ -327,8 +330,8 @@ clear(): void ...@@ -327,8 +330,8 @@ clear(): void
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.clear(); treeSet.clear();
``` ```
...@@ -351,8 +354,8 @@ values(): IterableIterator&lt;T&gt; ...@@ -351,8 +354,8 @@ values(): IterableIterator&lt;T&gt;
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let iter = treeSet.values(); let iter = treeSet.values();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -388,8 +391,8 @@ callbackfn的参数说明: ...@@ -388,8 +391,8 @@ callbackfn的参数说明:
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("sdfs"); treeSet.add("sparrow");
treeSet.add("dfsghsf"); treeSet.add("gull");
treeSet.forEach((value, key) => { treeSet.forEach((value, key) => {
console.log("value:" + value, key) console.log("value:" + value, key)
}); });
...@@ -414,8 +417,8 @@ entries(): IterableIterator<[T, T]> ...@@ -414,8 +417,8 @@ entries(): IterableIterator<[T, T]>
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
let iter = treeSet.entries(); let iter = treeSet.entries();
let temp = iter.next().value; let temp = iter.next().value;
while(temp != undefined) { while(temp != undefined) {
...@@ -444,8 +447,8 @@ while(temp != undefined) { ...@@ -444,8 +447,8 @@ while(temp != undefined) {
```ts ```ts
let treeSet = new TreeSet(); let treeSet = new TreeSet();
treeSet.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); treeSet.add("squirrel");
treeSet.add("sdfs"); treeSet.add("sparrow");
// 使用方法一: // 使用方法一:
for (let item of treeSet) { for (let item of treeSet) {
......
...@@ -9,6 +9,9 @@ Vector和[ArrayList](js-apis-arraylist.md)相似,都是基于数组实现, ...@@ -9,6 +9,9 @@ Vector和[ArrayList](js-apis-arraylist.md)相似,都是基于数组实现,
**推荐使用场景:** 当数据量大时,一般使用Vector来存取数据。 **推荐使用场景:** 当数据量大时,一般使用Vector来存取数据。
文档中存在泛型的使用,涉及以下泛型标记符:<br>
- T: Type, 类
## 导入模块 ## 导入模块
```ts ```ts
...@@ -70,7 +73,7 @@ let result = vector.add("a"); ...@@ -70,7 +73,7 @@ let result = vector.add("a");
let result1 = vector.add(1); let result1 = vector.add(1);
let b = [1, 2, 3]; let b = [1, 2, 3];
vector.add(b); vector.add(b);
let c = {name : "lala", age : "13"}; let c = {name : "Dylon", age : "13"};
let result3 = vector.add(c); let result3 = vector.add(c);
``` ```
...@@ -122,9 +125,9 @@ has(element: T): boolean ...@@ -122,9 +125,9 @@ has(element: T): boolean
```ts ```ts
let vector = new Vector(); let vector = new Vector();
let result = vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result = vector.has("squirrel");
vector.add("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); vector.add("squirrel");
let result1 = vector.has("Ahfbrgrbgnutfodgorrogorgrogofdfdf"); let result1 = vector.has("squirrel");
``` ```
### getIndexOf ### getIndexOf
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册