1# Class (BitVector) 2<!--Kit: ArkTS--> 3<!--Subsystem: CommonLibrary--> 4<!--Owner: @lijiamin2025--> 5<!--Designer: @weng-changcheng--> 6<!--Tester: @kirl75; @zsw_zhushiwei--> 7<!--Adviser: @ge-yafang--> 8> **说明:** 9> 10> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 11> 12> 此模块仅支持在ArkTS文件(文件后缀为.ets)中导入使用。 13 14BitVector是一种线性数据结构,底层基于数组实现。BitVector中存储元素为bit值,能存储和处理bit级别的操作。 15 16**装饰器类型:**\@Sendable 17 18## 导入模块 19 20```ts 21import { collections } from '@kit.ArkTS'; 22``` 23 24## 属性 25 26**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 27 28**系统能力:** SystemCapability.Utils.Lang 29 30| 名称 | 类型 | 只读 | 可选 | 说明 | 31| ------ | ------ | ---- | ---- | --------------------- | 32| length | number | 是 | 否 | BitVector的元素个数。 | 33 34 35## constructor 36 37constructor(length: number) 38 39BitVector的构造函数。 40 41**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 42 43**系统能力:** SystemCapability.Utils.Lang 44 45**参数:** 46 47| 参数名 | 类型 | 必填 | 说明 | 48| ------ | ------ | ---- | ----------------------- | 49| length | number | 是 | 初始化BitVector的长度。 | 50 51**示例:** 52 53```ts 54let bitVector: collections.BitVector = new collections.BitVector(0); 55``` 56 57 58## push 59 60push(element:number): boolean 61 62在BitVector尾部插入元素。 63 64**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 65 66**系统能力:** SystemCapability.Utils.Lang 67 68**参数:** 69 70| 参数名 | 类型 | 必填 | 说明 | 71| ------- | ------ | ---- | ----------------------------------- | 72| element | number | 是 | 待插入的元素,0表示0,其余值表示1。 | 73 74**返回值:** 75 76| 类型 | 说明 | 77| ------- | --------------------------------- | 78| boolean | 插入成功返回true,失败返回false。 | 79 80**错误码:** 81 82以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 83 84| 错误码ID | 错误信息 | 85| -------- | ------------------------------------------------------------ | 86| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 87| 10200011 | The push method cannot be bound. | 88| 10200201 | Concurrent modification error. | 89 90**示例:** 91 92```ts 93let bitVector: collections.BitVector = new collections.BitVector(0); 94bitVector.push(0); 95bitVector.push(1); 96bitVector.push(0); 97bitVector.push(1); 98bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 99``` 100 101## pop 102 103pop(): number 104 105弹出BitVector尾部的元素。 106 107**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 108 109**系统能力:** SystemCapability.Utils.Lang 110 111**返回值:** 112 113| 类型 | 说明 | 114| ------ | ------------------------------------------ | 115| number | 弹出BitVector尾部的元素,其值为对应bit值。 | 116 117**错误码:** 118 119以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 120 121| 错误码ID | 错误信息 | 122| -------- | ------------------------------- | 123| 10200011 | The pop method cannot be bound. | 124| 10200201 | Concurrent modification error. | 125 126**示例:** 127 128```ts 129let bitVector: collections.BitVector = new collections.BitVector(0); 130bitVector.push(0); 131bitVector.push(1); 132bitVector.push(0); 133bitVector.push(1); 134bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 135let res = bitVector.pop(); // bitVector: [0, 1, 0, 1] 136console.info("bitVector pop:", res); // 0 137``` 138 139## has 140 141has(element: number, fromIndex: number, toIndex: number): boolean 142 143判断范围内是否包含特定bit值。 144 145**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 146 147**系统能力:** SystemCapability.Utils.Lang 148 149**参数:** 150 151| 参数名 | 类型 | 必填 | 说明 | 152| --------- | ------ | ---- | ------------------------------------ | 153| element | number | 是 | 待判断的bit值,0表示0,其余值表示1。 | 154| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 155| toIndex | number | 是 | 范围终止索引,包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 156 157**返回值:** 158 159| 类型 | 说明 | 160| ------- | -------------------------------------- | 161| boolean | 包含特定bit值返回true,否则返回false。 | 162 163**错误码:** 164 165以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 166 167| 错误码ID | 错误信息 | 168| -------- | ------------------------------------------------------------ | 169| 10200001 | The value of fromIndex or toIndex is out of range. | 170| 10200011 | The has method cannot be bound. | 171| 10200201 | Concurrent modification error. | 172 173**示例:** 174 175```ts 176let bitVector: collections.BitVector = new collections.BitVector(0); 177bitVector.push(0); 178bitVector.push(1); 179bitVector.push(0); 180bitVector.push(1); 181bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 182let res0: boolean = bitVector.has(0, 1, 4); 183console.info("bitVector has 0:", res0); // true 184``` 185 186## setBitsByRange 187 188setBitsByRange(element: number, fromIndex: number, toIndex: number): void 189 190将BitVector中指定范围的元素均设为特定bit值。 191 192**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 193 194**系统能力:** SystemCapability.Utils.Lang 195 196**参数:** 197 198| 参数名 | 类型 | 必填 | 说明 | 199| --------- | ------ | ---- | ---------------------------------- | 200| element | number | 是 | 待设置的bit值,0表示0,其余表示1。 | 201| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 202| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 203 204**错误码:** 205 206以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 207 208| 错误码ID | 错误信息 | 209| -------- | ------------------------------------------------------------ | 210| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 211| 10200001 | The value of fromIndex or toIndex is out of range. | 212| 10200011 | The setBitsByRange method cannot be bound. | 213| 10200201 | Concurrent modification error. | 214 215**示例:** 216 217```ts 218let bitVector: collections.BitVector = new collections.BitVector(0); 219bitVector.push(0); 220bitVector.push(1); 221bitVector.push(0); 222bitVector.push(1); 223bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 224bitVector.setBitsByRange(1, 1, 3); // bitVector: [0, 1, 1, 1, 0] 225``` 226 227## setAllBits 228 229setAllBits(element: number): void 230 231将BitVector中所有元素均设为特定bit值。 232 233**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 234 235**系统能力:** SystemCapability.Utils.Lang 236 237**参数:** 238 239| 参数名 | 类型 | 必填 | 说明 | 240| ------- | ------ | ---- | ----------------------------------- | 241| element | number | 是 | 待设置的元素,0表示0,其余值表示1。 | 242 243**错误码:** 244 245以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 246 247| 错误码ID | 错误信息 | 248| -------- | ------------------------------------------------------------ | 249| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 250| 10200011 | The setAllBits method cannot be bound. | 251| 10200201 | Concurrent modification error. | 252 253**示例:** 254 255```ts 256let bitVector: collections.BitVector = new collections.BitVector(0); 257bitVector.push(0); 258bitVector.push(1); 259bitVector.push(0); 260bitVector.push(1); 261bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 262bitVector.setAllBits(1); // bitVector: [1, 1, 1, 1, 1] 263``` 264 265## getBitsByRange 266 267getBitsByRange(fromIndex: number, toIndex: number): BitVector 268 269获取指定范围内的bit值。 270 271**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 272 273**系统能力:** SystemCapability.Utils.Lang 274 275**参数:** 276 277| 参数名 | 类型 | 必填 | 说明 | 278| --------- | ------ | ---- | ------------------------------ | 279| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 280| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 281 282**返回值:** 283 284| 类型 | 说明 | 285| --------- | ---------------------------------- | 286| BitVector | 指定范围内的bit值组成的BitVector。 | 287 288**错误码:** 289 290以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 291 292| 错误码ID | 错误信息 | 293| -------- | ------------------------------------------------------------ | 294| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 295| 10200001 | The value of fromIndex or toIndex is out of range. | 296| 10200011 | The getBitsByRange method cannot be bound. | 297| 10200201 | Concurrent modification error. | 298 299**示例:** 300 301```ts 302let bitVector: collections.BitVector = new collections.BitVector(0); 303bitVector.push(0); 304bitVector.push(1); 305bitVector.push(0); 306bitVector.push(1); 307bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 308let bitVector2 = bitVector.getBitsByRange(1, 3); // bitVector2: [1, 0] 309console.info("bitVector2 length:", bitVector2.length); // 2 310``` 311 312## resize 313 314resize(size: number): void 315 316改变BitVector的长度。 317 318若size大于原BitVector的长度,则扩充原BitVector的长度,多出的部分其元素设置为0; 319 320若size小于等于原BitVector的长度,则将原BitVector按size长度大小裁剪。 321 322**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 323 324**系统能力:** SystemCapability.Utils.Lang 325 326**参数:** 327 328| 参数名 | 类型 | 必填 | 说明 | 329| ------ | ------ | ---- | ---------------- | 330| size | number | 是 | 需要改变的长度。 | 331 332**错误码:** 333 334以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 335 336| 错误码ID | 错误信息 | 337| -------- | ------------------------------------------------------------ | 338| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 339| 10200011 | The resize method cannot be bound. | 340| 10200201 | Concurrent modification error. | 341 342**示例:** 343 344```ts 345let bitVector: collections.BitVector = new collections.BitVector(0); 346bitVector.push(0); 347bitVector.push(1); 348bitVector.push(0); 349bitVector.push(1); 350bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 351bitVector.resize(10); // bitVector: [0, 1, 0, 1, 0, 0, 0, 0, 0, 0] 352console.info("bitVector get bit vector's length:", bitVector.length); // 10 353bitVector.resize(3); // bitVector: [0, 1, 0] 354console.info("bitVector get bit vector's length:", bitVector.length); // 3 355``` 356 357## getBitCountByRange 358 359getBitCountByRange(element: number, fromIndex: number, toIndex: number): number 360 361统计指定范围内获取指定bit值的数量。 362 363**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 364 365**系统能力:** SystemCapability.Utils.Lang 366 367**参数:** 368 369| 参数名 | 类型 | 必填 | 说明 | 370| --------- | ------ | ---- | ------------------------------------ | 371| element | number | 是 | 待统计的bit值,0表示0,其余值表示1。 | 372| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 373| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 374 375**返回值:** 376 377| 类型 | 说明 | 378| ------ | ----------------------------------- | 379| number | 统计指定范围内获取指定bit值的数量。 | 380 381**错误码:** 382 383以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 384 385| 错误码ID | 错误信息 | 386| -------- | ------------------------------------------------------------ | 387| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 388| 10200001 | The value of fromIndex or toIndex is out of range. | 389| 10200011 | The getBitCountByRange method cannot be bound. | 390| 10200201 | Concurrent modification error. | 391 392**示例:** 393 394```ts 395let bitVector: collections.BitVector = new collections.BitVector(0); 396bitVector.push(0); 397bitVector.push(1); 398bitVector.push(0); 399bitVector.push(1); 400bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 401let res: number = bitVector.getBitCountByRange(1, 1, 4); 402console.info("bitVector getBitCountByRange:", res); // 2 403``` 404 405## getIndexOf 406 407getIndexOf(element: number, fromIndex: number, toIndex: number): number 408 409返回指定bit值首次出现时的索引值,查找失败返回-1。 410 411**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 412 413**系统能力:** SystemCapability.Utils.Lang 414 415**参数:** 416 417| 参数名 | 类型 | 必填 | 说明 | 418| --------- | ------ | ---- | ------------------------------------ | 419| element | number | 是 | 待统计的bit值,0表示0,其余值表示1。 | 420| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 421| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 422 423**返回值:** 424 425| 类型 | 说明 | 426| ------ | ------------------------------------------------- | 427| number | 返回指定bit值首次出现时的下标值,查找失败返回-1。 | 428 429**错误码:** 430 431以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 432 433| 错误码ID | 错误信息 | 434| -------- | ------------------------------------------------------------ | 435| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 436| 10200001 | The value of fromIndex or toIndex is out of range. | 437| 10200011 | The getIndexOf method cannot be bound. | 438| 10200201 | Concurrent modification error. | 439 440**示例:** 441 442```ts 443let bitVector: collections.BitVector = new collections.BitVector(0); 444bitVector.push(0); 445bitVector.push(1); 446bitVector.push(0); 447bitVector.push(1); 448bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 449let res: number = bitVector.getIndexOf(0, 1, 4); 450console.info("bitVector getIndexOf:", res); // 2 451``` 452 453## getLastIndexOf 454 455getLastIndexOf(element: number, fromIndex: number, toIndex: number): number 456 457返回指定bit值最后一次出现时的下标值,查找失败返回-1。 458 459**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 460 461**系统能力:** SystemCapability.Utils.Lang 462 463**参数:** 464 465| 参数名 | 类型 | 必填 | 说明 | 466| --------- | ------ | ---- | ------------------------------------ | 467| element | number | 是 | 待统计的bit值,0表示0,其余值表示1。 | 468| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 469| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 470 471**返回值:** 472 473| 类型 | 说明 | 474| ------ | ----------------------------------------------------- | 475| number | 返回指定bit值最后一次出现时的下标值,查找失败返回-1。 | 476 477**错误码:** 478 479以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 480 481| 错误码ID | 错误信息 | 482| -------- | ------------------------------------------------------------ | 483| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 484| 10200001 | The value of fromIndex or toIndex is out of range. | 485| 10200011 | The getLastIndexOf method cannot be bound. | 486| 10200201 | Concurrent modification error. | 487 488**示例:** 489 490```ts 491let bitVector: collections.BitVector = new collections.BitVector(0); 492bitVector.push(0); 493bitVector.push(1); 494bitVector.push(0); 495bitVector.push(1); 496bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 497let res: number = bitVector.getLastIndexOf(0, 1, 4); 498console.info("bitVector getLastIndexOf:", res); // 2 499``` 500 501## flipBitByIndex 502 503flipBitByIndex(index: number): void 504 505翻转BitVector指定索引处的bit值,0翻转为1,1翻转为0。 506 507**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 508 509**系统能力:** SystemCapability.Utils.Lang 510 511**参数:** 512 513| 参数名 | 类型 | 必填 | 说明 | 514| ------ | ------ | ---- | ---------- | 515| index | number | 是 | 指定索引。index<0或者index>=length时,则会抛出错误。 | 516 517**错误码:** 518 519以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 520 521| 错误码ID | 错误信息 | 522| -------- | ------------------------------------------------------------ | 523| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 524| 10200001 | The value of index is out of range. | 525| 10200011 | The flipBitByIndex method cannot be bound. | 526| 10200201 | Concurrent modification error. | 527 528**示例:** 529 530```ts 531let bitVector: collections.BitVector = new collections.BitVector(0); 532bitVector.push(0); 533bitVector.push(1); 534bitVector.push(0); 535bitVector.push(1); 536bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 537bitVector.flipBitByIndex(3); // bitVector: [0, 1, 0, 0, 0] 538``` 539 540## flipBitsByRange 541 542flipBitsByRange(fromIndex: number, toIndex: number): void 543 544翻转BitVector指定范围内的bit值,0翻转为1,1翻转为0。 545 546**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 547 548**系统能力:** SystemCapability.Utils.Lang 549 550**参数:** 551 552| 参数名 | 类型 | 必填 | 说明 | 553| --------- | ------ | ---- | ------------------------------ | 554| fromIndex | number | 是 | 范围起始索引,包含本索引值。fromIndex<0或者fromIndex>=toIndex时,则会抛出错误。 | 555| toIndex | number | 是 | 范围终止索引,不包含本索引值。toIndex<0或者toIndex>=length时,则会抛出错误。 | 556 557**错误码:** 558 559以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 560 561| 错误码ID | 错误信息 | 562| -------- | ------------------------------------------------------------ | 563| 401 | Parameter error. Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. | 564| 10200001 | The value of fromIndex or toIndex is out of range. | 565| 10200011 | The flipBitsByRange method cannot be bound. | 566| 10200201 | Concurrent modification error. | 567 568**示例:** 569 570```ts 571let bitVector: collections.BitVector = new collections.BitVector(0); 572bitVector.push(0); 573bitVector.push(1); 574bitVector.push(0); 575bitVector.push(1); 576bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 577bitVector.flipBitsByRange(1, 4); // bitVector: [0, 0, 1, 0, 0] 578``` 579 580## values 581 582values(): IterableIterator\<number> 583 584返回一个新的迭代器对象,该对象包含BitVector中每个元素的值。 585 586**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。 587 588**系统能力:** SystemCapability.Utils.Lang 589 590**返回值:** 591 592| 类型 | 说明 | 593| ------------------------------ | ----------------------------- | 594| IterableIterator<number> | 返回一个BitVector迭代器对象。 | 595 596**错误码:** 597 598以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 599 600| 错误码ID | 错误信息 | 601| -------- | ---------------------------------- | 602| 10200011 | The values method cannot be bound. | 603| 10200201 | Concurrent modification error. | 604 605**示例:** 606 607```ts 608let bitVector: collections.BitVector = new collections.BitVector(0); 609bitVector.push(0); 610bitVector.push(1); 611bitVector.push(0); 612bitVector.push(1); 613bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 614let iter: IterableIterator<number> = bitVector.values(); 615let temp: IteratorResult<number> = iter.next(); 616while (!temp.done) { 617 console.info(JSON.stringify(temp.value)); 618 temp = iter.next(); 619} // 依次输出 0,1,0,1,0 620``` 621 622## [Symbol.iterator] 623 624[Symbol.iterator]\(): IterableIterator<number> 625 626返回一个迭代器,迭代器的每一项都是一个 JavaScript 对象,并返回该对象。 627 628> **说明:** 629> 630> 本接口不支持在.ets文件中使用。 631 632**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 633 634**系统能力:** SystemCapability.Utils.Lang 635 636**返回值:** 637 638| 类型 | 说明 | 639| ------------------------- | ---------------- | 640| IterableIterator<number> | 返回一个迭代器。 | 641 642**错误码:** 643 644以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 645 646| 错误码ID | 错误信息 | 647| -------- | ------------------------------------------- | 648| 10200011 | The Symbol.iterator method cannot be bound. | 649 650**示例:** 651 652```ts 653let bitVector: collections.BitVector = new collections.BitVector(0); 654bitVector.push(0); 655bitVector.push(1); 656bitVector.push(0); 657bitVector.push(1); 658bitVector.push(0); 659 660for (let item of bitVector) { 661 console.info("value: " + item); 662} 663``` 664 665## [index: number] 666 667[index: number]: number 668 669返回BitVector指定索引位置的元素。 670 671**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 672 673**系统能力:** SystemCapability.Utils.Lang 674 675**参数:** 676 677| 参数名 | 类型 | 必填 | 说明 | 678| ----- | ------ | ---- | -------------------------- | 679| index | number | 是 | 所需代码单元的从零开始的索引。| 680 681**返回值:** 682 683| 类型 | 说明 | 684| ----- | ---------------------| 685| number | 返回number数据类型。 | 686 687**示例:** 688 689```ts 690let bitVector: collections.BitVector = new collections.BitVector(0); 691bitVector.push(0); 692bitVector.push(1); 693bitVector.push(0); 694bitVector.push(1); 695bitVector.push(0); // bitVector: [0, 1, 0, 1, 0] 696console.info("BitVector Element Index at 1: " + bitVector[1]); 697```