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