mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
fix: Iterator supports function length or function size
This commit is contained in:
parent
5c6803b1a9
commit
6f74397f8d
|
@ -119,11 +119,11 @@ export class Deque<E> {
|
|||
*/
|
||||
constructor(elements: IterableWithSizeOrLength<E> = [], bucketSize = (1 << 12)) {
|
||||
|
||||
let _size;
|
||||
let _size: number;
|
||||
if ('length' in elements) {
|
||||
_size = elements.length;
|
||||
if (elements.length instanceof Function) _size = elements.length(); else _size = elements.length;
|
||||
} else {
|
||||
_size = elements.size;
|
||||
if (elements.size instanceof Function) _size = elements.size();else _size = elements.size;
|
||||
}
|
||||
|
||||
this._bucketSize = bucketSize;
|
||||
|
@ -991,7 +991,7 @@ export class Deque<E> {
|
|||
* Time Complexity: O(1)
|
||||
* Space Complexity: O(1)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Time Complexity: O(1)
|
||||
* Space Complexity: O(1)
|
||||
|
|
|
@ -16,11 +16,11 @@ export const enum IterateDirection {
|
|||
}
|
||||
|
||||
export interface IterableWithSize<T> extends Iterable<T> {
|
||||
size: number;
|
||||
size: number | ((...args: any[]) => number);
|
||||
}
|
||||
|
||||
export interface IterableWithLength<T> extends Iterable<T> {
|
||||
length: number;
|
||||
length: number | ((...args: any[]) => number);
|
||||
}
|
||||
|
||||
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>
|
||||
|
|
Loading…
Reference in a new issue