• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * Vector is a linear data structure that is implemented based on arrays. When the memory of a vector is used up,
23 * a larger contiguous memory area is automatically allocated, all the elements are copied to the new memory area,
24 * and the current memory area is reclaimed.
25 *
26 * @syscap SystemCapability.Utils.Lang
27 * @since 8
28 * @deprecated since 9
29 * @useinstead ohos.util.ArrayList
30 */
31declare class Vector<T> {
32  /**
33   * A constructor used to create a Vector object.
34   *
35   * @syscap SystemCapability.Utils.Lang
36   * @since 8
37   * @deprecated since 9
38   */
39  constructor();
40  /**
41   * Gets the element number of the Vector. This is a number one higher than the highest index in the vector.
42   *
43   * @syscap SystemCapability.Utils.Lang
44   * @since 8
45   * @deprecated since 9
46   */
47  length: number;
48  /**
49   * Appends the specified element to the end of this vector.
50   *
51   * @param { T } element - Element to be appended to this vector
52   * @returns { boolean } the boolean type, returns true if the addition is successful, and returns false if it fails.
53   * @syscap SystemCapability.Utils.Lang
54   * @since 8
55   * @deprecated since 9
56   */
57  add(element: T): boolean;
58  /**
59   * Inserts the specified element at the specified position in this
60   * vector. Shifts the element currently at that position (if any) and
61   * any subsequent elements to the right (adds one to their index).
62   *
63   * @param { T } element - Element at which the specified element is to be inserted
64   * @param { number } index - Index to be inserted
65   * @syscap SystemCapability.Utils.Lang
66   * @since 8
67   * @deprecated since 9
68   */
69  insert(element: T, index: number): void;
70  /**
71   * Check if vector contains the specified element
72   *
73   * @param { T } element - Element to be contained
74   * @returns { boolean } the boolean type,if vector contains the specified element,return true,else return false
75   * @syscap SystemCapability.Utils.Lang
76   * @since 8
77   * @deprecated since 9
78   */
79  has(element: T): boolean;
80  /**
81   * Returns the element at the specified position in this Vector,or returns undefined if vector is empty
82   *
83   * @param { number } index - Index to be contained
84   * @returns { T } the number type ,returns the lowest index such that or -1 if there is no such index.
85   * @syscap SystemCapability.Utils.Lang
86   * @since 8
87   * @deprecated since 9
88   */
89  get(index: number): T;
90  /**
91   * Returns the index of the first occurrence of the specified element
92   * in this vector, or -1 if this vector does not contain the element.
93   *
94   * @param { T } element - Element current index
95   * @returns { number } the number type
96   * @syscap SystemCapability.Utils.Lang
97   * @since 8
98   * @deprecated since 9
99   */
100  getIndexOf(element: T): number;
101  /**
102   * Returns the first component (the item at index 0) of this vector.
103   * or returns undefined if vector is empty
104   *
105   * @returns { T } the T type ,returns undefined if vector is empty
106   * @syscap SystemCapability.Utils.Lang
107   * @since 8
108   * @deprecated since 9
109   */
110  getFirstElement(): T;
111  /**
112   * Returns the Last component (the item at index length-1) of this vector.
113   * or returns undefined if vector is empty
114   *
115   * @returns { T } the T type ,returns undefined if vector is empty
116   * @syscap SystemCapability.Utils.Lang
117   * @since 8
118   * @deprecated since 9
119   */
120  getLastElement(): T;
121  /**
122   * Find the corresponding element according to the index,
123   * delete the element, and move the index of all elements to the right of the element forward by one.
124   *
125   * @param { number } index - The index in the vector
126   * @returns { T } the T type ,returns undefined if vector is empty,If the index is
127   * out of bounds (greater than or equal to length or less than 0), throw an exception
128   * @syscap SystemCapability.Utils.Lang
129   * @since 8
130   * @deprecated since 9
131   */
132  removeByIndex(index: number): T;
133  /**
134   * Removes the first occurrence of the specified element from this vector,
135   * if it is present.  If the vector does not contain the element, it is
136   * unchanged.  More formally, removes the element with the lowest index
137   *
138   * @param { T } element - Element to remove
139   * @returns { boolean } the boolean type ,If there is no such element, return false
140   * @syscap SystemCapability.Utils.Lang
141   * @since 8
142   * @deprecated since 9
143   */
144  remove(element: T): boolean;
145  /**
146   * Replaces the element at the specified position in this Vector with the specified element
147   *
148   * @param { number } index - Index to find
149   * @param { T } element - Element replaced element
150   * @returns { T } the T type
151   * @syscap SystemCapability.Utils.Lang
152   * @since 8
153   * @deprecated since 9
154   */
155  set(index: number, element: T): T;
156  /**
157   * Returns in the index of the last occurrence of the specified element in this vector ,
158   * or -1 if the vector does not contain the element.
159   *
160   * @param { T } element - Element to find
161   * @returns { number } The number type
162   * @syscap SystemCapability.Utils.Lang
163   * @since 8
164   * @deprecated since 9
165   */
166  getLastIndexOf(element: T): number;
167  /**
168   * Returns the index of the last occurrence of the specified element in this vector ,searching backwards from index,
169   * or returns -1 if the element is not found,or -1 if there is no such index
170   *
171   * @param { T } element - Element to find
172   * @param { number } index - Index start index
173   * @returns { number } the number type
174   * @syscap SystemCapability.Utils.Lang
175   * @since 8
176   * @deprecated since 9
177   */
178  getLastIndexFrom(element: T, index: number): number;
179  /**
180   * Returns the index of the first occurrence of the specified element in this vector ,searching forwards from index,
181   * or returns -1 if the element is not found,or -1 if there is no such index
182   *
183   * @param { T } element - Element to find
184   * @param { number } index - Index start index
185   * @returns { number } the number type
186   * @syscap SystemCapability.Utils.Lang
187   * @since 8
188   * @deprecated since 9
189   */
190  getIndexFrom(element: T, index: number): number;
191  /**
192   * Removes from this vector all of the elements whose index is between fromIndex,inclusive,and toIndex ,exclusive.
193   *
194   * @param { number } fromIndex - The starting position of the index, containing the value at that index position
195   * @param { number } toIndex - The end of the index, excluding the value at that index
196   * @syscap SystemCapability.Utils.Lang
197   * @since 8
198   * @deprecated since 9
199   */
200  removeByRange(fromIndex: number, toIndex: number): void;
201  /**
202   * Replaces each element of this vector with the result of applying the operator to that element.
203   *
204   * @param { function } callbackFn - A function that accepts up to four arguments.The function to be called
205   * for each element in the vector,Returns the result of an operation
206   * @param { Object } thisArg - The value passed to the function generally uses the
207   * "this" value.If this parameter is empty, "undefined" will be passed to the "this" value
208   * @syscap SystemCapability.Utils.Lang
209   * @since 8
210   * @deprecated since 9
211   */
212  replaceAllElements(callbackFn: (value: T, index?: number, vector?: Vector<T>) => T, thisArg?: Object): void;
213  /**
214   * Executes a provided function once for each value in the vector object.
215   *
216   * @param { function } callbackFn - callbackFn
217   * callbackFn (required) A function that accepts up to four arguments.The function to be
218   * called for each element in the vector
219   * @param { Object } thisArg - The value passed to the function generally uses the "this" value.
220   * If this parameter is empty, "undefined" will be passed to the "this" value
221   * @syscap SystemCapability.Utils.Lang
222   * @since 8
223   * @deprecated since 9
224   */
225  forEach(callbackFn: (value: T, index?: number, vector?: Vector<T>) => void, thisArg?: Object): void;
226  /**
227   * Sorts this vector according to the order induced by the specified comparator,without comparator
228   * this parameter, it will default to ASCII sorting
229   *
230   * @param { function } comparator - comparator
231   * (Optional) A function that accepts up to two arguments.Specifies the sort order.
232   * Must be a function,return number type,If it returns firstValue minus secondValue, it returns an vector sorted
233   * in ascending order;If it returns secondValue minus firstValue, it returns an vector sorted in descending order;
234   * If this parameter is empty, it will default to ASCII sorting
235   * @syscap SystemCapability.Utils.Lang
236   * @since 8
237   * @deprecated since 9
238   */
239  sort(comparator?: (firstValue: T, secondValue: T) => number): void;
240  /**
241   * Returns a view of the portion of this vector between the specified fromIndex,inclusive,and toIndex,exclusive
242   *
243   * @param { number } fromIndex - The starting position of the index, containing the value at that index position
244   * @param { number } toIndex - The end of the index, excluding the value at that index
245   * @returns { Vector<T> }
246   * @syscap SystemCapability.Utils.Lang
247   * @since 8
248   * @deprecated since 9
249   */
250  subVector(fromIndex: number, toIndex: number): Vector<T>;
251  /**
252   * Removes all of the elements from this vector.The vector will
253   * be empty after this call returns.length becomes 0
254   *
255   * @syscap SystemCapability.Utils.Lang
256   * @since 8
257   * @deprecated since 9
258   */
259  clear(): void;
260  /**
261   * Returns a shallow copy of this instance. (The elements themselves are not copied.)
262   *
263   * @returns { Vector<T> } this vector instance
264   * @syscap SystemCapability.Utils.Lang
265   * @since 8
266   * @deprecated since 9
267   */
268  clone(): Vector<T>;
269  /**
270   * Sets the length of this vector
271   *
272   * @param { number } newSize - newSize
273   * @syscap SystemCapability.Utils.Lang
274   * @since 8
275   * @deprecated since 9
276   */
277  setLength(newSize: number): void;
278  /**
279   * returns the capacity of this vector
280   *
281   * @returns { number } the number type
282   * @syscap SystemCapability.Utils.Lang
283   * @since 8
284   * @deprecated since 9
285   */
286  getCapacity(): number;
287  /**
288   * convert vector to array
289   *
290   * @returns { Array<T> } the Array type
291   * @syscap SystemCapability.Utils.Lang
292   * @since 8
293   * @deprecated since 9
294   */
295  convertToArray(): Array<T>;
296  /**
297   * Determine whether vector is empty and whether there is an element
298   *
299   * @returns { boolean } the boolean type
300   * @syscap SystemCapability.Utils.Lang
301   * @since 8
302   * @deprecated since 9
303   */
304  isEmpty(): boolean;
305  /**
306   * If the newCapacity provided by the user is greater than or equal to length,
307   * change the capacity of the vector to newCapacity, otherwise the capacity will not be changed
308   *
309   * @param { number } newCapacity - newCapacity
310   * @syscap SystemCapability.Utils.Lang
311   * @since 8
312   * @deprecated since 9
313   */
314  increaseCapacityTo(newCapacity: number): void;
315  /**
316   * Returns a string representation of this Vector,
317   * containing the String representation of each element
318   *
319   * @returns { string }
320   * @syscap SystemCapability.Utils.Lang
321   * @since 8
322   * @deprecated since 9
323   */
324  toString(): string;
325  /**
326   * Limit the capacity to the current length
327   *
328   * @syscap SystemCapability.Utils.Lang
329   * @since 8
330   * @deprecated since 9
331   */
332  trimToCurrentLength(): void;
333  /**
334   * Copies the components of this vector into the specified array,
335   * to overwrite elements of the same index
336   *
337   * @param { Array<T> } array - Replaced array
338   * @syscap SystemCapability.Utils.Lang
339   * @since 8
340   * @deprecated since 9
341   */
342  copyToArray(array: Array<T>): void;
343  /**
344   * returns an ES6 iterator.Each item of the iterator is a Javascript Object
345   *
346   * @returns { IterableIterator<T> }
347   * @syscap SystemCapability.Utils.Lang
348   * @since 8
349   * @deprecated since 9
350   */
351  [Symbol.iterator](): IterableIterator<T>;
352}
353
354export default Vector;
355