1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ArkTS 19 */ 20 21/** 22 * Double-ended queue (deque) is a sequence container implemented based on the queue data structure that 23 * follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). 24 * It allows insertion and removal of elements at both the ends. 25 * 26 * @syscap SystemCapability.Utils.Lang 27 * @since 8 28 */ 29/** 30 * Double-ended queue (deque) is a sequence container implemented based on the queue data structure that 31 * follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). 32 * It allows insertion and removal of elements at both the ends. 33 * 34 * @syscap SystemCapability.Utils.Lang 35 * @crossplatform 36 * @since 10 37 */ 38/** 39 * Double-ended queue (deque) is a sequence container implemented based on the queue data structure that 40 * follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). 41 * It allows insertion and removal of elements at both the ends. 42 * 43 * @syscap SystemCapability.Utils.Lang 44 * @crossplatform 45 * @atomicservice 46 * @since arkts {'1.1':'12', '1.2':'20'} 47 * @arkts 1.1&1.2 48 */ 49declare class Deque<T> { 50 /** 51 * A constructor used to create a Deque object. 52 * 53 * @throws { BusinessError } 10200012 - The Deque's constructor cannot be directly invoked. 54 * @syscap SystemCapability.Utils.Lang 55 * @since 8 56 */ 57 /** 58 * A constructor used to create a Deque object. 59 * 60 * @throws { BusinessError } 10200012 - The Deque's constructor cannot be directly invoked. 61 * @syscap SystemCapability.Utils.Lang 62 * @crossplatform 63 * @since 10 64 */ 65 /** 66 * A constructor used to create a Deque object. 67 * 68 * @throws { BusinessError } 10200012 - The Deque's constructor cannot be directly invoked. 69 * @syscap SystemCapability.Utils.Lang 70 * @crossplatform 71 * @atomicservice 72 * @since arkts {'1.1':'12', '1.2':'20'} 73 * @arkts 1.1&1.2 74 */ 75 constructor(); 76 /** 77 * Gets the element number of the Deque.This is a number one higher than the highest index in the deque. 78 * 79 * @type { number } 80 * @syscap SystemCapability.Utils.Lang 81 * @since 8 82 */ 83 /** 84 * Gets the element number of the Deque.This is a number one higher than the highest index in the deque. 85 * 86 * @type { number } 87 * @syscap SystemCapability.Utils.Lang 88 * @crossplatform 89 * @since 10 90 */ 91 /** 92 * Gets the element number of the Deque.This is a number one higher than the highest index in the deque. 93 * 94 * @type { number } 95 * @syscap SystemCapability.Utils.Lang 96 * @crossplatform 97 * @atomicservice 98 * @since 12 99 */ 100 length: number; 101 /** 102 * Gets the element number of the Deque. 103 * 104 * @type { number } 105 * @syscap SystemCapability.Utils.Lang 106 * @crossplatform 107 * @atomicservice 108 * @since 20 109 * @arkts 1.2 110 */ 111 get length(): number; 112 /** 113 * Inserts an element into the deque header. 114 * 115 * @param { T } element - element element to be appended to this deque 116 * @throws { BusinessError } 10200011 - The insertFront method cannot be bound. 117 * @syscap SystemCapability.Utils.Lang 118 * @since 8 119 */ 120 /** 121 * Inserts an element into the deque header. 122 * 123 * @param { T } element - element element to be appended to this deque 124 * @throws { BusinessError } 10200011 - The insertFront method cannot be bound. 125 * @syscap SystemCapability.Utils.Lang 126 * @crossplatform 127 * @since 10 128 */ 129 /** 130 * Inserts an element into the deque header. 131 * 132 * @param { T } element - element element to be appended to this deque 133 * @throws { BusinessError } 10200011 - The insertFront method cannot be bound. 134 * @syscap SystemCapability.Utils.Lang 135 * @crossplatform 136 * @atomicservice 137 * @since arkts {'1.1':'12', '1.2':'20'} 138 * @arkts 1.1&1.2 139 */ 140 insertFront(element: T): void; 141 /** 142 * Inserting an element at the end of a deque 143 * 144 * @param { T } element - element element to be appended to this deque 145 * @throws { BusinessError } 10200011 - The insertEnd method cannot be bound. 146 * @syscap SystemCapability.Utils.Lang 147 * @since 8 148 */ 149 /** 150 * Inserting an element at the end of a deque 151 * 152 * @param { T } element - element element to be appended to this deque 153 * @throws { BusinessError } 10200011 - The insertEnd method cannot be bound. 154 * @syscap SystemCapability.Utils.Lang 155 * @crossplatform 156 * @since 10 157 */ 158 /** 159 * Inserting an element at the end of a deque 160 * 161 * @param { T } element - element element to be appended to this deque 162 * @throws { BusinessError } 10200011 - The insertEnd method cannot be bound. 163 * @syscap SystemCapability.Utils.Lang 164 * @crossplatform 165 * @atomicservice 166 * @since arkts {'1.1':'12', '1.2':'20'} 167 * @arkts 1.1&1.2 168 */ 169 insertEnd(element: T): void; 170 /** 171 * Check if deque contains the specified element 172 * 173 * @param { T } element - element element to be contained 174 * @returns { boolean } the boolean type,if deque contains the specified element,return true,else return false 175 * @throws { BusinessError } 10200011 - The has method cannot be bound. 176 * @syscap SystemCapability.Utils.Lang 177 * @since 8 178 */ 179 /** 180 * Check if deque contains the specified element 181 * 182 * @param { T } element - element element to be contained 183 * @returns { boolean } the boolean type,if deque contains the specified element,return true,else return false 184 * @throws { BusinessError } 10200011 - The has method cannot be bound. 185 * @syscap SystemCapability.Utils.Lang 186 * @crossplatform 187 * @since 10 188 */ 189 /** 190 * Check if deque contains the specified element 191 * 192 * @param { T } element - element element to be contained 193 * @returns { boolean } the boolean type,if deque contains the specified element,return true,else return false 194 * @throws { BusinessError } 10200011 - The has method cannot be bound. 195 * @syscap SystemCapability.Utils.Lang 196 * @crossplatform 197 * @atomicservice 198 * @since arkts {'1.1':'12', '1.2':'20'} 199 * @arkts 1.1&1.2 200 */ 201 has(element: T): boolean; 202 /** 203 * Obtains the header element of a deque. 204 * 205 * @returns { T } the T type 206 * @throws { BusinessError } 10200011 - The getFirst method cannot be bound. 207 * @syscap SystemCapability.Utils.Lang 208 * @since 8 209 */ 210 /** 211 * Obtains the header element of a deque. 212 * 213 * @returns { T } the T type 214 * @throws { BusinessError } 10200011 - The getFirst method cannot be bound. 215 * @syscap SystemCapability.Utils.Lang 216 * @crossplatform 217 * @since 10 218 */ 219 /** 220 * Obtains the header element of a deque. 221 * 222 * @returns { T } the T type 223 * @throws { BusinessError } 10200011 - The getFirst method cannot be bound. 224 * @syscap SystemCapability.Utils.Lang 225 * @crossplatform 226 * @atomicservice 227 * @since 12 228 */ 229 getFirst(): T; 230 231 /** 232 * Obtains the header element of a deque. 233 * 234 * @returns { T | undefined } the first element of the deque if it exists, otherwise returns undefined. 235 * @syscap SystemCapability.Utils.Lang 236 * @crossplatform 237 * @atomicservice 238 * @since 20 239 * @arkts 1.2 240 */ 241 getFirst(): T | undefined; 242 243 /** 244 * Obtains the end element of a deque. 245 * 246 * @returns { T } the T type 247 * @throws { BusinessError } 10200011 - The getLast method cannot be bound. 248 * @syscap SystemCapability.Utils.Lang 249 * @since 8 250 */ 251 /** 252 * Obtains the end element of a deque. 253 * 254 * @returns { T } the T type 255 * @throws { BusinessError } 10200011 - The getLast method cannot be bound. 256 * @syscap SystemCapability.Utils.Lang 257 * @crossplatform 258 * @since 10 259 */ 260 /** 261 * Obtains the end element of a deque. 262 * 263 * @returns { T } the T type 264 * @throws { BusinessError } 10200011 - The getLast method cannot be bound. 265 * @syscap SystemCapability.Utils.Lang 266 * @crossplatform 267 * @atomicservice 268 * @since 12 269 */ 270 getLast(): T; 271 272 /** 273 * Obtains the end element of a deque. 274 * 275 * @returns { T | undefined } the last element of the deque if it exists, otherwise returns undefined. 276 * @syscap SystemCapability.Utils.Lang 277 * @crossplatform 278 * @atomicservice 279 * @since 20 280 * @arkts 1.2 281 */ 282 getLast(): T | undefined; 283 284 /** 285 * Obtains the header element of a deque and delete the element. 286 * 287 * @returns { T } the T type 288 * @throws { BusinessError } 10200011 - The popFirst method cannot be bound. 289 * @syscap SystemCapability.Utils.Lang 290 * @since 8 291 */ 292 /** 293 * Obtains the header element of a deque and delete the element. 294 * 295 * @returns { T } the T type 296 * @throws { BusinessError } 10200011 - The popFirst method cannot be bound. 297 * @syscap SystemCapability.Utils.Lang 298 * @crossplatform 299 * @since 10 300 */ 301 /** 302 * Obtains the header element of a deque and delete the element. 303 * 304 * @returns { T } the T type 305 * @throws { BusinessError } 10200011 - The popFirst method cannot be bound. 306 * @syscap SystemCapability.Utils.Lang 307 * @crossplatform 308 * @atomicservice 309 * @since 12 310 */ 311 popFirst(): T; 312 313 /** 314 * Obtains the header element of a deque and delete the element. 315 * 316 * @returns { T | undefined } the deleted element of the deque if it exists, otherwise returns undefined. 317 * @syscap SystemCapability.Utils.Lang 318 * @crossplatform 319 * @atomicservice 320 * @since 20 321 * @arkts 1.2 322 */ 323 popFirst(): T | undefined; 324 325 /** 326 * Obtains the end element of a deque and delete the element. 327 * 328 * @returns { T } the T type 329 * @throws { BusinessError } 10200011 - The popLast method cannot be bound. 330 * @syscap SystemCapability.Utils.Lang 331 * @since 8 332 */ 333 /** 334 * Obtains the end element of a deque and delete the element. 335 * 336 * @returns { T } the T type 337 * @throws { BusinessError } 10200011 - The popLast method cannot be bound. 338 * @syscap SystemCapability.Utils.Lang 339 * @crossplatform 340 * @since 10 341 */ 342 /** 343 * Obtains the end element of a deque and delete the element. 344 * 345 * @returns { T } the T type 346 * @throws { BusinessError } 10200011 - The popLast method cannot be bound. 347 * @syscap SystemCapability.Utils.Lang 348 * @crossplatform 349 * @atomicservice 350 * @since 12 351 */ 352 popLast(): T; 353 354 /** 355 * Obtains the end element of a deque and delete the element. 356 * 357 * @returns { T | undefined } the deleted element of the deque if it exists, otherwise returns undefined. 358 * @syscap SystemCapability.Utils.Lang 359 * @crossplatform 360 * @atomicservice 361 * @since 20 362 * @arkts 1.2 363 */ 364 popLast(): T | undefined; 365 366 /** 367 * Executes a provided function once for each value in the deque object. 368 * 369 * @param { function } callbackFn - callbackFn 370 * callbackFn (required) A function that accepts up to three arguments. 371 * The function to be called for each element. 372 * @param { Object } [thisArg] - thisArg 373 * thisArg (Optional) The value to be used as this value for when callbackFn is called. 374 * If thisArg is omitted, undefined is used as the this value. 375 * @throws { BusinessError } 401 - Parameter error. Possible causes: 376 * 1.Mandatory parameters are left unspecified; 377 * 2.Incorrect parameter types. 378 * @throws { BusinessError } 10200011 - The forEach method cannot be bound. 379 * @syscap SystemCapability.Utils.Lang 380 * @since 8 381 */ 382 /** 383 * Executes a provided function once for each value in the deque object. 384 * 385 * @param { function } callbackFn - callbackFn 386 * callbackFn (required) A function that accepts up to three arguments. 387 * The function to be called for each element. 388 * @param { Object } [thisArg] - thisArg 389 * thisArg (Optional) The value to be used as this value for when callbackFn is called. 390 * If thisArg is omitted, undefined is used as the this value. 391 * @throws { BusinessError } 401 - Parameter error. Possible causes: 392 * 1.Mandatory parameters are left unspecified; 393 * 2.Incorrect parameter types. 394 * @throws { BusinessError } 10200011 - The forEach method cannot be bound. 395 * @syscap SystemCapability.Utils.Lang 396 * @crossplatform 397 * @since 10 398 */ 399 /** 400 * Executes a provided function once for each value in the deque object. 401 * 402 * @param { function } callbackFn - callbackFn 403 * callbackFn (required) A function that accepts up to three arguments. 404 * The function to be called for each element. 405 * @param { Object } [thisArg] - thisArg 406 * thisArg (Optional) The value to be used as this value for when callbackFn is called. 407 * If thisArg is omitted, undefined is used as the this value. 408 * @throws { BusinessError } 401 - Parameter error. Possible causes: 409 * 1.Mandatory parameters are left unspecified; 410 * 2.Incorrect parameter types. 411 * @throws { BusinessError } 10200011 - The forEach method cannot be bound. 412 * @syscap SystemCapability.Utils.Lang 413 * @crossplatform 414 * @atomicservice 415 * @since 12 416 */ 417 forEach(callbackFn: (value: T, index?: number, deque?: Deque<T>) => void, thisArg?: Object): void; 418 419 /** 420 * Iterates over elements in a generic Deque (double-ended queue) and executes a callback function for each element. 421 * 422 * @param { DequeCbFnforEach<T> } callbackFn - A callback function to execute for each element. 423 * @syscap SystemCapability.Utils.Lang 424 * @crossplatform 425 * @atomicservice 426 * @since 20 427 * @arkts 1.2 428 */ 429 forEach(callbackFn: DequeCbFnforEach<T>): void; 430 /** 431 * Returns the byte at the specified index. 432 * 433 * @param { number } index - The zero-based index of the desired code unit. 434 * @returns { T } The element in the deque matching the given index. 435 * @syscap SystemCapability.Utils.Lang 436 * @crossplatform 437 * @atomicservice 438 * @since 20 439 * @arkts 1.2 440 */ 441 $_get(index: number): T; 442 443 /** 444 * Sets the byte at the specified index. 445 * 446 * @param { number } index – The index of the element to set. 447 * @param { T } value – The value to set at the specified index. 448 * @syscap SystemCapability.Utils.Lang 449 * @crossplatform 450 * @atomicservice 451 * @since 20 452 * @arkts 1.2 453 */ 454 $_set(index: number, value: T): void; 455 456 /** 457 * returns an iterator.Each item of the iterator is a Javascript Object 458 * 459 * @returns { IterableIterator<T> } 460 * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound. 461 * @syscap SystemCapability.Utils.Lang 462 * @since 8 463 */ 464 /** 465 * returns an iterator.Each item of the iterator is a Javascript Object 466 * 467 * @returns { IterableIterator<T> } 468 * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound. 469 * @syscap SystemCapability.Utils.Lang 470 * @crossplatform 471 * @since 10 472 */ 473 /** 474 * returns an iterator.Each item of the iterator is a Javascript Object 475 * 476 * @returns { IterableIterator<T> } 477 * @throws { BusinessError } 10200011 - The Symbol.iterator method cannot be bound. 478 * @syscap SystemCapability.Utils.Lang 479 * @crossplatform 480 * @atomicservice 481 * @since 12 482 */ 483 [Symbol.iterator](): IterableIterator<T>; 484 485 /** 486 * Returns an iterator. Each item of the iterator is a ArkTS Object 487 * 488 * @returns { IterableIterator<T> } 489 * @syscap SystemCapability.Utils.Lang 490 * @crossplatform 491 * @atomicservice 492 * @since 20 493 * @arkts 1.2 494 */ 495 $_iterator(): IterableIterator<T>; 496} 497 498 /** 499 * The type of Deque forEach callback function. 500 * 501 * @typedef { function } DequeCbFnforEach 502 * @param { T } value - The current element being processed 503 * @param { number } index - The index of the current element 504 * @param { Deque<T> } deque - The Deque instance being traversed 505 * @returns { void } This callback does not return a value 506 * @syscap SystemCapability.Utils.Lang 507 * @atomicservice 508 * @since 20 509 * @arkts 1.2 510 */ 511 type DequeCbFnforEach<T> = (value: T, index: number, deque: Deque<T>) => void; 512 513export default Deque; 514