@js-sdsl/vector
Advanced tools
Comparing version 4.2.0-beta.1 to 4.2.0
@@ -7,2 +7,24 @@ # Change Log | ||
## [4.2.0] - 2022.11.20 | ||
### Changed | ||
- Optimized the structure of class `TreeNodeEnableIndex`. | ||
- Change the `iterator access denied` error message to reduce the packing size. | ||
- Change the internal storage of the hash container to the form of a linked list, traversing in insertion order. | ||
- Standardize hash container. Make it extends from `Container` and add general functions. | ||
- Refactor `LinkList` to do optimization. | ||
### Added | ||
- Add public `length` property to all the container. | ||
- Add returned value to `pop` function including `popBack` and `popFront` to all the container which has such function. | ||
- Add returned value to `eraseElementByKey` which means whether erase successfully. | ||
- Add returned value to `push` or `insert` function which means the size of the container. | ||
### Fixed | ||
- Fixed wrong error type when `updateKeyByIterator`. | ||
- Fixed wrong iterator was returned when erase tree reverse iterator. | ||
## [4.2.0-beta.1] - 2022.11.06 | ||
@@ -9,0 +31,0 @@ |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @description The iterator type including `NORMAL` and `REVERSE`. | ||
*/ | ||
declare const enum IteratorType { | ||
@@ -8,10 +11,18 @@ NORMAL = 0, | ||
* @description Iterator's type. | ||
* @example console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
* @example | ||
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
*/ | ||
readonly iteratorType: IteratorType; | ||
protected constructor(iteratorType?: IteratorType); | ||
/** | ||
* @param iter - The other iterator you want to compare. | ||
* @returns Whether this equals to obj. | ||
* @example | ||
* container.find(1).equals(container.end()); | ||
*/ | ||
equals(iter: ContainerIterator<T>): boolean; | ||
/** | ||
* @description Pointers to element. | ||
* @return The value of the pointer's element. | ||
* @example const val = container.begin().pointer; | ||
* @returns The value of the pointer's element. | ||
* @example | ||
* const val = container.begin().pointer; | ||
*/ | ||
@@ -21,4 +32,5 @@ abstract get pointer(): T; | ||
* @description Set pointer's value (some containers are unavailable). | ||
* @param newValue The new value you want to set. | ||
* @example (<LinkList<number>>container).begin().pointer = 1; | ||
* @param newValue - The new value you want to set. | ||
* @example | ||
* (<LinkList<number>>container).begin().pointer = 1; | ||
*/ | ||
@@ -28,2 +40,3 @@ abstract set pointer(newValue: T); | ||
* @description Move `this` iterator to pre. | ||
* @returns The iterator's self. | ||
* @example | ||
@@ -39,2 +52,3 @@ * const iter = container.find(1); // container = [0, 1] | ||
* @description Move `this` iterator to next. | ||
* @returns The iterator's self. | ||
* @example | ||
@@ -49,10 +63,4 @@ * const iter = container.find(1); // container = [1, 2] | ||
/** | ||
* @param obj The other iterator you want to compare. | ||
* @return Boolean about if this equals to obj. | ||
* @example container.find(1).equals(container.end()); | ||
*/ | ||
abstract equals(obj: ContainerIterator<T>): boolean; | ||
/** | ||
* @description Get a copy of itself. | ||
* @return The copy of self. | ||
* @returns The copy of self. | ||
* @example | ||
@@ -69,5 +77,12 @@ * const iter = container.find(1); // container = [1, 2] | ||
/** | ||
* @return The size of the container. | ||
* @returns The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.length); // 2 | ||
*/ | ||
get length(): number; | ||
/** | ||
* @returns The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.size()); // 2 | ||
@@ -77,3 +92,3 @@ */ | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -94,3 +109,3 @@ * container.clear(); | ||
/** | ||
* @return Iterator pointing to the beginning element. | ||
* @returns Iterator pointing to the beginning element. | ||
* @example | ||
@@ -105,3 +120,3 @@ * const begin = container.begin(); | ||
/** | ||
* @return Iterator pointing to the super end like c++. | ||
* @returns Iterator pointing to the super end like c++. | ||
* @example | ||
@@ -116,3 +131,3 @@ * const begin = container.begin(); | ||
/** | ||
* @return Iterator pointing to the end element. | ||
* @returns Iterator pointing to the end element. | ||
* @example | ||
@@ -127,3 +142,3 @@ * const rBegin = container.rBegin(); | ||
/** | ||
* @return Iterator pointing to the super begin like c++. | ||
* @returns Iterator pointing to the super begin like c++. | ||
* @example | ||
@@ -138,22 +153,24 @@ * const rBegin = container.rBegin(); | ||
/** | ||
* @return The first element of the container. | ||
* @returns The first element of the container. | ||
*/ | ||
abstract front(): T | undefined; | ||
/** | ||
* @return The last element of the container. | ||
* @returns The last element of the container. | ||
*/ | ||
abstract back(): T | undefined; | ||
/** | ||
* @param element - The element you want to find. | ||
* @returns An iterator pointing to the element if found, or super end if not found. | ||
* @example | ||
* container.find(1).equals(container.end()); | ||
*/ | ||
abstract find(element: T): ContainerIterator<T>; | ||
/** | ||
* @description Iterate over all elements in the container. | ||
* @param callback Callback function like Array.forEach. | ||
* @example container.forEach((element, index) => console.log(element, index)); | ||
* @param callback - Callback function like Array.forEach. | ||
* @example | ||
* container.forEach((element, index) => console.log(element, index)); | ||
*/ | ||
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void; | ||
/** | ||
* @param element The element you want to find. | ||
* @return An iterator pointing to the element if found, or super end if not found. | ||
* @example container.find(1).equals(container.end()); | ||
*/ | ||
abstract find(element: T): ContainerIterator<T>; | ||
/** | ||
* @description Gets the value of the element at the specified position. | ||
@@ -166,9 +183,12 @@ * @example | ||
* @description Removes the element at the specified position. | ||
* @param pos The element's position you want to remove. | ||
* @param pos - The element's position you want to remove. | ||
* @returns The container length after erasing. | ||
* @example | ||
* container.eraseElementByPos(-1); // throw a RangeError | ||
*/ | ||
abstract eraseElementByPos(pos: number): void; | ||
abstract eraseElementByPos(pos: number): number; | ||
/** | ||
* @description Removes element by iterator and move `iter` to next. | ||
* @param iter The iterator you want to erase. | ||
* @param iter - The iterator you want to erase. | ||
* @returns The next iterator. | ||
* @example | ||
@@ -186,4 +206,7 @@ * container.eraseElementByIterator(container.begin()); | ||
*/ | ||
abstract [Symbol.iterator](): Generator<T, void, undefined>; | ||
abstract [Symbol.iterator](): Generator<T, void>; | ||
} | ||
/** | ||
* @description The initial data type passed in when initializing the container. | ||
*/ | ||
type initContainer<T> = ({ | ||
@@ -201,14 +224,17 @@ size: number; | ||
* @description Push the element to the back. | ||
* @param element The element you want to push. | ||
* @param element - The element you want to push. | ||
* @returns The size of container after pushing. | ||
*/ | ||
abstract pushBack(element: T): void; | ||
abstract pushBack(element: T): number; | ||
/** | ||
* @description Removes the last element. | ||
* @returns The element you popped. | ||
*/ | ||
abstract popBack(): void; | ||
abstract popBack(): T | undefined; | ||
/** | ||
* @description Sets element by position. | ||
* @param pos The position you want to change. | ||
* @param element The element's value you want to update. | ||
* @example container.setElementByPos(-1, 1); // throw a RangeError | ||
* @param pos - The position you want to change. | ||
* @param element - The element's value you want to update. | ||
* @example | ||
* container.setElementByPos(-1, 1); // throw a RangeError | ||
*/ | ||
@@ -218,11 +244,14 @@ abstract setElementByPos(pos: number, element: T): void; | ||
* @description Removes the elements of the specified value. | ||
* @param value The value you want to remove. | ||
* @example container.eraseElementByValue(-1); | ||
* @param value - The value you want to remove. | ||
* @returns The size of container after erasing. | ||
* @example | ||
* container.eraseElementByValue(-1); | ||
*/ | ||
abstract eraseElementByValue(value: T): void; | ||
abstract eraseElementByValue(value: T): number; | ||
/** | ||
* @description Insert several elements after the specified position. | ||
* @param pos The position you want to insert. | ||
* @param element The element you want to insert. | ||
* @param num The number of elements you want to insert (default 1). | ||
* @param pos - The position you want to insert. | ||
* @param element - The element you want to insert. | ||
* @param num - The number of elements you want to insert (default 1). | ||
* @returns The size of container after inserting. | ||
* @example | ||
@@ -233,3 +262,3 @@ * const container = new Vector([1, 2, 3]); | ||
*/ | ||
abstract insert(pos: number, element: T, num?: number): void; | ||
abstract insert(pos: number, element: T, num?: number): number; | ||
/** | ||
@@ -244,2 +273,3 @@ * @description Reverses the container. | ||
* @description Removes the duplication of elements in the container. | ||
* @returns The size of container after inserting. | ||
* @example | ||
@@ -249,6 +279,6 @@ * const container = new Vector([1, 1, 3, 2, 2, 5, 5, 2]); | ||
*/ | ||
abstract unique(): void; | ||
abstract unique(): number; | ||
/** | ||
* @description Sort the container. | ||
* @param cmp Comparison function. | ||
* @param cmp - Comparison function to sort. | ||
* @example | ||
@@ -262,17 +292,19 @@ * const container = new Vector([3, 1, 10]); | ||
declare abstract class RandomIterator<T> extends ContainerIterator<T> { | ||
pre: () => this; | ||
next: () => this; | ||
get pointer(): T; | ||
set pointer(newValue: T); | ||
equals(obj: RandomIterator<T>): boolean; | ||
// @ts-ignore | ||
pre(): this; | ||
// @ts-ignore | ||
next(): this; | ||
} | ||
declare class VectorIterator<T> extends RandomIterator<T> { | ||
copy(): VectorIterator<T>; | ||
// @ts-ignore | ||
equals(iter: VectorIterator<T>): boolean; | ||
} | ||
declare class Vector<T> extends SequentialContainer<T> { | ||
/** | ||
* @description Vector's constructor. | ||
* @param container Initialize container, must have a forEach function. | ||
* @param copy When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
* @param container - Initialize container, must have a forEach function. | ||
* @param copy - When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
*/ | ||
@@ -287,18 +319,18 @@ constructor(container?: initContainer<T>, copy?: boolean); | ||
back(): T | undefined; | ||
forEach(callback: (element: T, index: number, vector: Vector<T>) => void): void; | ||
getElementByPos(pos: number): T; | ||
eraseElementByPos(pos: number): void; | ||
eraseElementByValue(value: T): void; | ||
eraseElementByPos(pos: number): number; | ||
eraseElementByValue(value: T): number; | ||
eraseElementByIterator(iter: VectorIterator<T>): VectorIterator<T>; | ||
pushBack(element: T): void; | ||
popBack(): void; | ||
pushBack(element: T): number; | ||
popBack(): T | undefined; | ||
setElementByPos(pos: number, element: T): void; | ||
insert(pos: number, element: T, num?: number): void; | ||
insert(pos: number, element: T, num?: number): number; | ||
find(element: T): VectorIterator<T>; | ||
reverse(): void; | ||
unique(): void; | ||
unique(): number; | ||
sort(cmp?: (x: T, y: T) => number): void; | ||
[Symbol.iterator](): Generator<T, any, undefined>; | ||
forEach(callback: (element: T, index: number, vector: Vector<T>) => void): void; | ||
[Symbol.iterator](): Generator<T, void, undefined>; | ||
} | ||
export { Vector }; | ||
export type { VectorIterator, IteratorType, Container, ContainerIterator, SequentialContainer }; |
@@ -11,2 +11,5 @@ "use strict"; | ||
} | ||
equals(t) { | ||
return this.i === t.i; | ||
} | ||
} | ||
@@ -16,9 +19,12 @@ | ||
constructor() { | ||
this.i = 0; | ||
this.h = 0; | ||
} | ||
get length() { | ||
return this.h; | ||
} | ||
size() { | ||
return this.i; | ||
return this.h; | ||
} | ||
empty() { | ||
return this.i === 0; | ||
return this.h === 0; | ||
} | ||
@@ -31,22 +37,26 @@ } | ||
function throwIteratorAccessError() { | ||
throw new RangeError("Iterator access denied!"); | ||
} | ||
class RandomIterator extends ContainerIterator { | ||
constructor(t, s, r, e, i) { | ||
constructor(t, r, s, e, i) { | ||
super(i); | ||
this.h = t; | ||
this.o = s; | ||
this.u = r; | ||
this.i = t; | ||
this.o = r; | ||
this.u = s; | ||
this.l = e; | ||
if (this.iteratorType === 0) { | ||
this.pre = function() { | ||
if (this.h === 0) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.i === 0) { | ||
throwIteratorAccessError(); | ||
} | ||
this.h -= 1; | ||
this.i -= 1; | ||
return this; | ||
}; | ||
this.next = function() { | ||
if (this.h === this.o()) { | ||
throw new RangeError("Random Iterator access denied!"); | ||
if (this.i === this.o()) { | ||
throwIteratorAccessError(); | ||
} | ||
this.h += 1; | ||
this.i += 1; | ||
return this; | ||
@@ -56,13 +66,13 @@ }; | ||
this.pre = function() { | ||
if (this.h === this.o() - 1) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.i === this.o() - 1) { | ||
throwIteratorAccessError(); | ||
} | ||
this.h += 1; | ||
this.i += 1; | ||
return this; | ||
}; | ||
this.next = function() { | ||
if (this.h === -1) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.i === -1) { | ||
throwIteratorAccessError(); | ||
} | ||
this.h -= 1; | ||
this.i -= 1; | ||
return this; | ||
@@ -73,16 +83,13 @@ }; | ||
get pointer() { | ||
if (this.h < 0 || this.h > this.o() - 1) { | ||
if (this.i < 0 || this.i > this.o() - 1) { | ||
throw new RangeError; | ||
} | ||
return this.u(this.h); | ||
return this.u(this.i); | ||
} | ||
set pointer(t) { | ||
if (this.h < 0 || this.h > this.o() - 1) { | ||
if (this.i < 0 || this.i > this.o() - 1) { | ||
throw new RangeError; | ||
} | ||
this.l(this.h, t); | ||
this.l(this.i, t); | ||
} | ||
equals(t) { | ||
return this.h === t.h; | ||
} | ||
} | ||
@@ -92,3 +99,3 @@ | ||
copy() { | ||
return new VectorIterator(this.h, this.o, this.u, this.l, this.iteratorType); | ||
return new VectorIterator(this.i, this.o, this.u, this.l, this.iteratorType); | ||
} | ||
@@ -98,12 +105,12 @@ } | ||
class Vector extends SequentialContainer { | ||
constructor(t = [], s = true) { | ||
constructor(t = [], r = true) { | ||
super(); | ||
if (Array.isArray(t)) { | ||
this.R = s ? [ ...t ] : t; | ||
this.i = t.length; | ||
this.I = r ? [ ...t ] : t; | ||
this.h = t.length; | ||
} else { | ||
this.R = []; | ||
const s = this; | ||
this.I = []; | ||
const r = this; | ||
t.forEach((function(t) { | ||
s.pushBack(t); | ||
r.pushBack(t); | ||
})); | ||
@@ -116,4 +123,4 @@ } | ||
clear() { | ||
this.i = 0; | ||
this.R.length = 0; | ||
this.h = 0; | ||
this.I.length = 0; | ||
} | ||
@@ -124,6 +131,6 @@ begin() { | ||
end() { | ||
return new VectorIterator(this.i, this.size, this.getElementByPos, this.setElementByPos); | ||
return new VectorIterator(this.h, this.size, this.getElementByPos, this.setElementByPos); | ||
} | ||
rBegin() { | ||
return new VectorIterator(this.i - 1, this.size, this.getElementByPos, this.setElementByPos, 1); | ||
return new VectorIterator(this.h - 1, this.size, this.getElementByPos, this.setElementByPos, 1); | ||
} | ||
@@ -134,66 +141,65 @@ rEnd() { | ||
front() { | ||
return this.R[0]; | ||
return this.I[0]; | ||
} | ||
back() { | ||
return this.R[this.i - 1]; | ||
return this.I[this.h - 1]; | ||
} | ||
forEach(t) { | ||
for (let s = 0; s < this.i; ++s) { | ||
t(this.R[s], s, this); | ||
} | ||
} | ||
getElementByPos(t) { | ||
if (t < 0 || t > this.i - 1) { | ||
if (t < 0 || t > this.h - 1) { | ||
throw new RangeError; | ||
} | ||
return this.R[t]; | ||
return this.I[t]; | ||
} | ||
eraseElementByPos(t) { | ||
if (t < 0 || t > this.i - 1) { | ||
if (t < 0 || t > this.h - 1) { | ||
throw new RangeError; | ||
} | ||
this.R.splice(t, 1); | ||
this.i -= 1; | ||
this.I.splice(t, 1); | ||
this.h -= 1; | ||
return this.h; | ||
} | ||
eraseElementByValue(t) { | ||
let s = 0; | ||
for (let r = 0; r < this.i; ++r) { | ||
if (this.R[r] !== t) { | ||
this.R[s++] = this.R[r]; | ||
let r = 0; | ||
for (let s = 0; s < this.h; ++s) { | ||
if (this.I[s] !== t) { | ||
this.I[r++] = this.I[s]; | ||
} | ||
} | ||
this.i = this.R.length = s; | ||
this.h = this.I.length = r; | ||
return this.h; | ||
} | ||
eraseElementByIterator(t) { | ||
const s = t.h; | ||
const r = t.i; | ||
t = t.next(); | ||
this.eraseElementByPos(s); | ||
this.eraseElementByPos(r); | ||
return t; | ||
} | ||
pushBack(t) { | ||
this.R.push(t); | ||
this.i += 1; | ||
this.I.push(t); | ||
this.h += 1; | ||
return this.h; | ||
} | ||
popBack() { | ||
if (!this.i) return; | ||
this.R.pop(); | ||
this.i -= 1; | ||
if (this.h === 0) return; | ||
this.h -= 1; | ||
return this.I.pop(); | ||
} | ||
setElementByPos(t, s) { | ||
if (t < 0 || t > this.i - 1) { | ||
setElementByPos(t, r) { | ||
if (t < 0 || t > this.h - 1) { | ||
throw new RangeError; | ||
} | ||
this.R[t] = s; | ||
this.I[t] = r; | ||
} | ||
insert(t, s, r = 1) { | ||
if (t < 0 || t > this.i) { | ||
insert(t, r, s = 1) { | ||
if (t < 0 || t > this.h) { | ||
throw new RangeError; | ||
} | ||
this.R.splice(t, 0, ...new Array(r).fill(s)); | ||
this.i += r; | ||
this.I.splice(t, 0, ...new Array(s).fill(r)); | ||
this.h += s; | ||
return this.h; | ||
} | ||
find(t) { | ||
for (let s = 0; s < this.i; ++s) { | ||
if (this.R[s] === t) { | ||
return new VectorIterator(s, this.size, this.getElementByPos, this.getElementByPos); | ||
for (let r = 0; r < this.h; ++r) { | ||
if (this.I[r] === t) { | ||
return new VectorIterator(r, this.size, this.getElementByPos, this.getElementByPos); | ||
} | ||
@@ -204,19 +210,25 @@ } | ||
reverse() { | ||
this.R.reverse(); | ||
this.I.reverse(); | ||
} | ||
unique() { | ||
let t = 1; | ||
for (let s = 1; s < this.i; ++s) { | ||
if (this.R[s] !== this.R[s - 1]) { | ||
this.R[t++] = this.R[s]; | ||
for (let r = 1; r < this.h; ++r) { | ||
if (this.I[r] !== this.I[r - 1]) { | ||
this.I[t++] = this.I[r]; | ||
} | ||
} | ||
this.i = this.R.length = t; | ||
this.h = this.I.length = t; | ||
return this.h; | ||
} | ||
sort(t) { | ||
this.R.sort(t); | ||
this.I.sort(t); | ||
} | ||
forEach(t) { | ||
for (let r = 0; r < this.h; ++r) { | ||
t(this.I[r], r, this); | ||
} | ||
} | ||
[Symbol.iterator]() { | ||
return function*() { | ||
return yield* this.R; | ||
yield* this.I; | ||
}.bind(this)(); | ||
@@ -223,0 +235,0 @@ } |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @description The iterator type including `NORMAL` and `REVERSE`. | ||
*/ | ||
declare const enum IteratorType { | ||
@@ -8,10 +11,18 @@ NORMAL = 0, | ||
* @description Iterator's type. | ||
* @example console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
* @example | ||
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
*/ | ||
readonly iteratorType: IteratorType; | ||
protected constructor(iteratorType?: IteratorType); | ||
/** | ||
* @param iter - The other iterator you want to compare. | ||
* @returns Whether this equals to obj. | ||
* @example | ||
* container.find(1).equals(container.end()); | ||
*/ | ||
equals(iter: ContainerIterator<T>): boolean; | ||
/** | ||
* @description Pointers to element. | ||
* @return The value of the pointer's element. | ||
* @example const val = container.begin().pointer; | ||
* @returns The value of the pointer's element. | ||
* @example | ||
* const val = container.begin().pointer; | ||
*/ | ||
@@ -21,4 +32,5 @@ abstract get pointer(): T; | ||
* @description Set pointer's value (some containers are unavailable). | ||
* @param newValue The new value you want to set. | ||
* @example (<LinkList<number>>container).begin().pointer = 1; | ||
* @param newValue - The new value you want to set. | ||
* @example | ||
* (<LinkList<number>>container).begin().pointer = 1; | ||
*/ | ||
@@ -28,2 +40,3 @@ abstract set pointer(newValue: T); | ||
* @description Move `this` iterator to pre. | ||
* @returns The iterator's self. | ||
* @example | ||
@@ -39,2 +52,3 @@ * const iter = container.find(1); // container = [0, 1] | ||
* @description Move `this` iterator to next. | ||
* @returns The iterator's self. | ||
* @example | ||
@@ -49,10 +63,4 @@ * const iter = container.find(1); // container = [1, 2] | ||
/** | ||
* @param obj The other iterator you want to compare. | ||
* @return Boolean about if this equals to obj. | ||
* @example container.find(1).equals(container.end()); | ||
*/ | ||
abstract equals(obj: ContainerIterator<T>): boolean; | ||
/** | ||
* @description Get a copy of itself. | ||
* @return The copy of self. | ||
* @returns The copy of self. | ||
* @example | ||
@@ -69,5 +77,12 @@ * const iter = container.find(1); // container = [1, 2] | ||
/** | ||
* @return The size of the container. | ||
* @returns The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.length); // 2 | ||
*/ | ||
get length(): number; | ||
/** | ||
* @returns The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.size()); // 2 | ||
@@ -77,3 +92,3 @@ */ | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -94,3 +109,3 @@ * container.clear(); | ||
/** | ||
* @return Iterator pointing to the beginning element. | ||
* @returns Iterator pointing to the beginning element. | ||
* @example | ||
@@ -105,3 +120,3 @@ * const begin = container.begin(); | ||
/** | ||
* @return Iterator pointing to the super end like c++. | ||
* @returns Iterator pointing to the super end like c++. | ||
* @example | ||
@@ -116,3 +131,3 @@ * const begin = container.begin(); | ||
/** | ||
* @return Iterator pointing to the end element. | ||
* @returns Iterator pointing to the end element. | ||
* @example | ||
@@ -127,3 +142,3 @@ * const rBegin = container.rBegin(); | ||
/** | ||
* @return Iterator pointing to the super begin like c++. | ||
* @returns Iterator pointing to the super begin like c++. | ||
* @example | ||
@@ -138,22 +153,24 @@ * const rBegin = container.rBegin(); | ||
/** | ||
* @return The first element of the container. | ||
* @returns The first element of the container. | ||
*/ | ||
abstract front(): T | undefined; | ||
/** | ||
* @return The last element of the container. | ||
* @returns The last element of the container. | ||
*/ | ||
abstract back(): T | undefined; | ||
/** | ||
* @param element - The element you want to find. | ||
* @returns An iterator pointing to the element if found, or super end if not found. | ||
* @example | ||
* container.find(1).equals(container.end()); | ||
*/ | ||
abstract find(element: T): ContainerIterator<T>; | ||
/** | ||
* @description Iterate over all elements in the container. | ||
* @param callback Callback function like Array.forEach. | ||
* @example container.forEach((element, index) => console.log(element, index)); | ||
* @param callback - Callback function like Array.forEach. | ||
* @example | ||
* container.forEach((element, index) => console.log(element, index)); | ||
*/ | ||
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void; | ||
/** | ||
* @param element The element you want to find. | ||
* @return An iterator pointing to the element if found, or super end if not found. | ||
* @example container.find(1).equals(container.end()); | ||
*/ | ||
abstract find(element: T): ContainerIterator<T>; | ||
/** | ||
* @description Gets the value of the element at the specified position. | ||
@@ -166,9 +183,12 @@ * @example | ||
* @description Removes the element at the specified position. | ||
* @param pos The element's position you want to remove. | ||
* @param pos - The element's position you want to remove. | ||
* @returns The container length after erasing. | ||
* @example | ||
* container.eraseElementByPos(-1); // throw a RangeError | ||
*/ | ||
abstract eraseElementByPos(pos: number): void; | ||
abstract eraseElementByPos(pos: number): number; | ||
/** | ||
* @description Removes element by iterator and move `iter` to next. | ||
* @param iter The iterator you want to erase. | ||
* @param iter - The iterator you want to erase. | ||
* @returns The next iterator. | ||
* @example | ||
@@ -186,4 +206,7 @@ * container.eraseElementByIterator(container.begin()); | ||
*/ | ||
abstract [Symbol.iterator](): Generator<T, void, undefined>; | ||
abstract [Symbol.iterator](): Generator<T, void>; | ||
} | ||
/** | ||
* @description The initial data type passed in when initializing the container. | ||
*/ | ||
type initContainer<T> = ({ | ||
@@ -201,14 +224,17 @@ size: number; | ||
* @description Push the element to the back. | ||
* @param element The element you want to push. | ||
* @param element - The element you want to push. | ||
* @returns The size of container after pushing. | ||
*/ | ||
abstract pushBack(element: T): void; | ||
abstract pushBack(element: T): number; | ||
/** | ||
* @description Removes the last element. | ||
* @returns The element you popped. | ||
*/ | ||
abstract popBack(): void; | ||
abstract popBack(): T | undefined; | ||
/** | ||
* @description Sets element by position. | ||
* @param pos The position you want to change. | ||
* @param element The element's value you want to update. | ||
* @example container.setElementByPos(-1, 1); // throw a RangeError | ||
* @param pos - The position you want to change. | ||
* @param element - The element's value you want to update. | ||
* @example | ||
* container.setElementByPos(-1, 1); // throw a RangeError | ||
*/ | ||
@@ -218,11 +244,14 @@ abstract setElementByPos(pos: number, element: T): void; | ||
* @description Removes the elements of the specified value. | ||
* @param value The value you want to remove. | ||
* @example container.eraseElementByValue(-1); | ||
* @param value - The value you want to remove. | ||
* @returns The size of container after erasing. | ||
* @example | ||
* container.eraseElementByValue(-1); | ||
*/ | ||
abstract eraseElementByValue(value: T): void; | ||
abstract eraseElementByValue(value: T): number; | ||
/** | ||
* @description Insert several elements after the specified position. | ||
* @param pos The position you want to insert. | ||
* @param element The element you want to insert. | ||
* @param num The number of elements you want to insert (default 1). | ||
* @param pos - The position you want to insert. | ||
* @param element - The element you want to insert. | ||
* @param num - The number of elements you want to insert (default 1). | ||
* @returns The size of container after inserting. | ||
* @example | ||
@@ -233,3 +262,3 @@ * const container = new Vector([1, 2, 3]); | ||
*/ | ||
abstract insert(pos: number, element: T, num?: number): void; | ||
abstract insert(pos: number, element: T, num?: number): number; | ||
/** | ||
@@ -244,2 +273,3 @@ * @description Reverses the container. | ||
* @description Removes the duplication of elements in the container. | ||
* @returns The size of container after inserting. | ||
* @example | ||
@@ -249,6 +279,6 @@ * const container = new Vector([1, 1, 3, 2, 2, 5, 5, 2]); | ||
*/ | ||
abstract unique(): void; | ||
abstract unique(): number; | ||
/** | ||
* @description Sort the container. | ||
* @param cmp Comparison function. | ||
* @param cmp - Comparison function to sort. | ||
* @example | ||
@@ -262,17 +292,19 @@ * const container = new Vector([3, 1, 10]); | ||
declare abstract class RandomIterator<T> extends ContainerIterator<T> { | ||
pre: () => this; | ||
next: () => this; | ||
get pointer(): T; | ||
set pointer(newValue: T); | ||
equals(obj: RandomIterator<T>): boolean; | ||
// @ts-ignore | ||
pre(): this; | ||
// @ts-ignore | ||
next(): this; | ||
} | ||
declare class VectorIterator<T> extends RandomIterator<T> { | ||
copy(): VectorIterator<T>; | ||
// @ts-ignore | ||
equals(iter: VectorIterator<T>): boolean; | ||
} | ||
declare class Vector<T> extends SequentialContainer<T> { | ||
/** | ||
* @description Vector's constructor. | ||
* @param container Initialize container, must have a forEach function. | ||
* @param copy When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
* @param container - Initialize container, must have a forEach function. | ||
* @param copy - When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
*/ | ||
@@ -287,18 +319,18 @@ constructor(container?: initContainer<T>, copy?: boolean); | ||
back(): T | undefined; | ||
forEach(callback: (element: T, index: number, vector: Vector<T>) => void): void; | ||
getElementByPos(pos: number): T; | ||
eraseElementByPos(pos: number): void; | ||
eraseElementByValue(value: T): void; | ||
eraseElementByPos(pos: number): number; | ||
eraseElementByValue(value: T): number; | ||
eraseElementByIterator(iter: VectorIterator<T>): VectorIterator<T>; | ||
pushBack(element: T): void; | ||
popBack(): void; | ||
pushBack(element: T): number; | ||
popBack(): T | undefined; | ||
setElementByPos(pos: number, element: T): void; | ||
insert(pos: number, element: T, num?: number): void; | ||
insert(pos: number, element: T, num?: number): number; | ||
find(element: T): VectorIterator<T>; | ||
reverse(): void; | ||
unique(): void; | ||
unique(): number; | ||
sort(cmp?: (x: T, y: T) => number): void; | ||
[Symbol.iterator](): Generator<T, any, undefined>; | ||
forEach(callback: (element: T, index: number, vector: Vector<T>) => void): void; | ||
[Symbol.iterator](): Generator<T, void, undefined>; | ||
} | ||
export { Vector }; | ||
export type { VectorIterator, IteratorType, Container, ContainerIterator, SequentialContainer }; |
@@ -43,12 +43,12 @@ var extendStatics = function(t, r) { | ||
} | ||
function step(a) { | ||
function step(u) { | ||
if (e) throw new TypeError("Generator is already executing."); | ||
while (s && (s = 0, a[0] && (n = 0)), n) try { | ||
if (e = 1, i && (o = a[0] & 2 ? i["return"] : a[0] ? i["throw"] || ((o = i["return"]) && o.call(i), | ||
0) : i.next) && !(o = o.call(i, a[1])).done) return o; | ||
if (i = 0, o) a = [ a[0] & 2, o.value ]; | ||
switch (a[0]) { | ||
while (s && (s = 0, u[0] && (n = 0)), n) try { | ||
if (e = 1, i && (o = u[0] & 2 ? i["return"] : u[0] ? i["throw"] || ((o = i["return"]) && o.call(i), | ||
0) : i.next) && !(o = o.call(i, u[1])).done) return o; | ||
if (i = 0, o) u = [ u[0] & 2, o.value ]; | ||
switch (u[0]) { | ||
case 0: | ||
case 1: | ||
o = a; | ||
o = u; | ||
break; | ||
@@ -59,3 +59,3 @@ | ||
return { | ||
value: a[1], | ||
value: u[1], | ||
done: false | ||
@@ -66,8 +66,8 @@ }; | ||
n.label++; | ||
i = a[1]; | ||
a = [ 0 ]; | ||
i = u[1]; | ||
u = [ 0 ]; | ||
continue; | ||
case 7: | ||
a = n.ops.pop(); | ||
u = n.ops.pop(); | ||
n.trys.pop(); | ||
@@ -77,13 +77,13 @@ continue; | ||
default: | ||
if (!(o = n.trys, o = o.length > 0 && o[o.length - 1]) && (a[0] === 6 || a[0] === 2)) { | ||
if (!(o = n.trys, o = o.length > 0 && o[o.length - 1]) && (u[0] === 6 || u[0] === 2)) { | ||
n = 0; | ||
continue; | ||
} | ||
if (a[0] === 3 && (!o || a[1] > o[0] && a[1] < o[3])) { | ||
n.label = a[1]; | ||
if (u[0] === 3 && (!o || u[1] > o[0] && u[1] < o[3])) { | ||
n.label = u[1]; | ||
break; | ||
} | ||
if (a[0] === 6 && n.label < o[1]) { | ||
if (u[0] === 6 && n.label < o[1]) { | ||
n.label = o[1]; | ||
o = a; | ||
o = u; | ||
break; | ||
@@ -93,3 +93,3 @@ } | ||
n.label = o[2]; | ||
n.ops.push(a); | ||
n.ops.push(u); | ||
break; | ||
@@ -101,5 +101,5 @@ } | ||
} | ||
a = r.call(t, n); | ||
u = r.call(t, n); | ||
} catch (t) { | ||
a = [ 6, t ]; | ||
u = [ 6, t ]; | ||
i = 0; | ||
@@ -109,5 +109,5 @@ } finally { | ||
} | ||
if (a[0] & 5) throw a[1]; | ||
if (u[0] & 5) throw u[1]; | ||
return { | ||
value: a[0] ? a[1] : void 0, | ||
value: u[0] ? u[1] : void 0, | ||
done: true | ||
@@ -170,2 +170,5 @@ }; | ||
} | ||
ContainerIterator.prototype.equals = function(t) { | ||
return this.t === t.t; | ||
}; | ||
return ContainerIterator; | ||
@@ -176,9 +179,16 @@ }(); | ||
function Base() { | ||
this.t = 0; | ||
this.i = 0; | ||
} | ||
Object.defineProperty(Base.prototype, "length", { | ||
get: function() { | ||
return this.i; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Base.prototype.size = function() { | ||
return this.t; | ||
return this.i; | ||
}; | ||
Base.prototype.empty = function() { | ||
return this.t === 0; | ||
return this.i === 0; | ||
}; | ||
@@ -204,2 +214,6 @@ return Base; | ||
function throwIteratorAccessError() { | ||
throw new RangeError("Iterator access denied!"); | ||
} | ||
var RandomIterator = function(t) { | ||
@@ -209,3 +223,3 @@ __extends(RandomIterator, t); | ||
var s = t.call(this, o) || this; | ||
s.i = r; | ||
s.t = r; | ||
s.o = n; | ||
@@ -216,13 +230,13 @@ s.u = e; | ||
s.pre = function() { | ||
if (this.i === 0) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.t === 0) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i -= 1; | ||
this.t -= 1; | ||
return this; | ||
}; | ||
s.next = function() { | ||
if (this.i === this.o()) { | ||
throw new RangeError("Random Iterator access denied!"); | ||
if (this.t === this.o()) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i += 1; | ||
this.t += 1; | ||
return this; | ||
@@ -232,13 +246,13 @@ }; | ||
s.pre = function() { | ||
if (this.i === this.o() - 1) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.t === this.o() - 1) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i += 1; | ||
this.t += 1; | ||
return this; | ||
}; | ||
s.next = function() { | ||
if (this.i === -1) { | ||
throw new RangeError("Random iterator access denied!"); | ||
if (this.t === -1) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i -= 1; | ||
this.t -= 1; | ||
return this; | ||
@@ -251,12 +265,12 @@ }; | ||
get: function() { | ||
if (this.i < 0 || this.i > this.o() - 1) { | ||
if (this.t < 0 || this.t > this.o() - 1) { | ||
throw new RangeError; | ||
} | ||
return this.u(this.i); | ||
return this.u(this.t); | ||
}, | ||
set: function(t) { | ||
if (this.i < 0 || this.i > this.o() - 1) { | ||
if (this.t < 0 || this.t > this.o() - 1) { | ||
throw new RangeError; | ||
} | ||
this.h(this.i, t); | ||
this.h(this.t, t); | ||
}, | ||
@@ -266,5 +280,2 @@ enumerable: false, | ||
}); | ||
RandomIterator.prototype.equals = function(t) { | ||
return this.i === t.i; | ||
}; | ||
return RandomIterator; | ||
@@ -279,3 +290,3 @@ }(ContainerIterator); | ||
VectorIterator.prototype.copy = function() { | ||
return new VectorIterator(this.i, this.o, this.u, this.h, this.iteratorType); | ||
return new VectorIterator(this.t, this.o, this.u, this.h, this.iteratorType); | ||
}; | ||
@@ -297,3 +308,3 @@ return VectorIterator; | ||
e.l = n ? __spreadArray([], __read(r), false) : r; | ||
e.t = r.length; | ||
e.i = r.length; | ||
} else { | ||
@@ -312,3 +323,3 @@ e.l = []; | ||
Vector.prototype.clear = function() { | ||
this.t = 0; | ||
this.i = 0; | ||
this.l.length = 0; | ||
@@ -320,6 +331,6 @@ }; | ||
Vector.prototype.end = function() { | ||
return new VectorIterator(this.t, this.size, this.getElementByPos, this.setElementByPos); | ||
return new VectorIterator(this.i, this.size, this.getElementByPos, this.setElementByPos); | ||
}; | ||
Vector.prototype.rBegin = function() { | ||
return new VectorIterator(this.t - 1, this.size, this.getElementByPos, this.setElementByPos, 1); | ||
return new VectorIterator(this.i - 1, this.size, this.getElementByPos, this.setElementByPos, 1); | ||
}; | ||
@@ -333,11 +344,6 @@ Vector.prototype.rEnd = function() { | ||
Vector.prototype.back = function() { | ||
return this.l[this.t - 1]; | ||
return this.l[this.i - 1]; | ||
}; | ||
Vector.prototype.forEach = function(t) { | ||
for (var r = 0; r < this.t; ++r) { | ||
t(this.l[r], r, this); | ||
} | ||
}; | ||
Vector.prototype.getElementByPos = function(t) { | ||
if (t < 0 || t > this.t - 1) { | ||
if (t < 0 || t > this.i - 1) { | ||
throw new RangeError; | ||
@@ -348,11 +354,12 @@ } | ||
Vector.prototype.eraseElementByPos = function(t) { | ||
if (t < 0 || t > this.t - 1) { | ||
if (t < 0 || t > this.i - 1) { | ||
throw new RangeError; | ||
} | ||
this.l.splice(t, 1); | ||
this.t -= 1; | ||
this.i -= 1; | ||
return this.i; | ||
}; | ||
Vector.prototype.eraseElementByValue = function(t) { | ||
var r = 0; | ||
for (var n = 0; n < this.t; ++n) { | ||
for (var n = 0; n < this.i; ++n) { | ||
if (this.l[n] !== t) { | ||
@@ -362,6 +369,7 @@ this.l[r++] = this.l[n]; | ||
} | ||
this.t = this.l.length = r; | ||
this.i = this.l.length = r; | ||
return this.i; | ||
}; | ||
Vector.prototype.eraseElementByIterator = function(t) { | ||
var r = t.i; | ||
var r = t.t; | ||
t = t.next(); | ||
@@ -373,11 +381,12 @@ this.eraseElementByPos(r); | ||
this.l.push(t); | ||
this.t += 1; | ||
this.i += 1; | ||
return this.i; | ||
}; | ||
Vector.prototype.popBack = function() { | ||
if (!this.t) return; | ||
this.l.pop(); | ||
this.t -= 1; | ||
if (this.i === 0) return; | ||
this.i -= 1; | ||
return this.l.pop(); | ||
}; | ||
Vector.prototype.setElementByPos = function(t, r) { | ||
if (t < 0 || t > this.t - 1) { | ||
if (t < 0 || t > this.i - 1) { | ||
throw new RangeError; | ||
@@ -392,10 +401,11 @@ } | ||
} | ||
if (t < 0 || t > this.t) { | ||
if (t < 0 || t > this.i) { | ||
throw new RangeError; | ||
} | ||
(e = this.l).splice.apply(e, __spreadArray([ t, 0 ], __read(new Array(n).fill(r)), false)); | ||
this.t += n; | ||
this.i += n; | ||
return this.i; | ||
}; | ||
Vector.prototype.find = function(t) { | ||
for (var r = 0; r < this.t; ++r) { | ||
for (var r = 0; r < this.i; ++r) { | ||
if (this.l[r] === t) { | ||
@@ -412,3 +422,3 @@ return new VectorIterator(r, this.size, this.getElementByPos, this.getElementByPos); | ||
var t = 1; | ||
for (var r = 1; r < this.t; ++r) { | ||
for (var r = 1; r < this.i; ++r) { | ||
if (this.l[r] !== this.l[r - 1]) { | ||
@@ -418,3 +428,4 @@ this.l[t++] = this.l[r]; | ||
} | ||
this.t = this.l.length = t; | ||
this.i = this.l.length = t; | ||
return this.i; | ||
}; | ||
@@ -424,2 +435,7 @@ Vector.prototype.sort = function(t) { | ||
}; | ||
Vector.prototype.forEach = function(t) { | ||
for (var r = 0; r < this.i; ++r) { | ||
t(this.l[r], r, this); | ||
} | ||
}; | ||
Vector.prototype[Symbol.iterator] = function() { | ||
@@ -433,3 +449,4 @@ return function() { | ||
case 1: | ||
return [ 2, t.sent() ]; | ||
t.sent(); | ||
return [ 2 ]; | ||
} | ||
@@ -436,0 +453,0 @@ })); |
/*! | ||
* @js-sdsl/vector v4.2.0-beta.1 | ||
* @js-sdsl/vector v4.2.0 | ||
* https://github.com/js-sdsl/js-sdsl | ||
@@ -185,2 +185,5 @@ * (c) 2021-present ZLY201 <zilongyao1366@gmail.com> | ||
var ContainerIterator = /** @class */function () { | ||
/** | ||
* @internal | ||
*/ | ||
function ContainerIterator(iteratorType) { | ||
@@ -192,2 +195,11 @@ if (iteratorType === void 0) { | ||
} | ||
/** | ||
* @param iter - The other iterator you want to compare. | ||
* @returns Whether this equals to obj. | ||
* @example | ||
* container.find(1).equals(container.end()); | ||
*/ | ||
ContainerIterator.prototype.equals = function (iter) { | ||
return this._node === iter._node; | ||
}; | ||
return ContainerIterator; | ||
@@ -203,4 +215,17 @@ }(); | ||
} | ||
Object.defineProperty(Base.prototype, "length", { | ||
/** | ||
* @returns The size of the container. | ||
* @example | ||
* const container = new Vector([1, 2]); | ||
* console.log(container.length); // 2 | ||
*/ | ||
get: function () { | ||
return this._length; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* @return The size of the container. | ||
* @returns The size of the container. | ||
* @example | ||
@@ -214,3 +239,3 @@ * const container = new Vector([1, 2]); | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -241,2 +266,10 @@ * container.clear(); | ||
/** | ||
* @description Throw an iterator access error. | ||
* @internal | ||
*/ | ||
function throwIteratorAccessError() { | ||
throw new RangeError('Iterator access denied!'); | ||
} | ||
var RandomIterator = /** @class */function (_super) { | ||
@@ -256,3 +289,3 @@ __extends(RandomIterator, _super); | ||
if (this._node === 0) { | ||
throw new RangeError('Random iterator access denied!'); | ||
throwIteratorAccessError(); | ||
} | ||
@@ -264,3 +297,3 @@ this._node -= 1; | ||
if (this._node === this._size()) { | ||
throw new RangeError('Random Iterator access denied!'); | ||
throwIteratorAccessError(); | ||
} | ||
@@ -273,3 +306,3 @@ this._node += 1; | ||
if (this._node === this._size() - 1) { | ||
throw new RangeError('Random iterator access denied!'); | ||
throwIteratorAccessError(); | ||
} | ||
@@ -281,3 +314,3 @@ this._node += 1; | ||
if (this._node === -1) { | ||
throw new RangeError('Random iterator access denied!'); | ||
throwIteratorAccessError(); | ||
} | ||
@@ -294,3 +327,5 @@ this._node -= 1; | ||
throw new RangeError(); | ||
} | ||
} /** | ||
* @internal | ||
*/ | ||
return this._getElementByPos(this._node); | ||
@@ -301,3 +336,5 @@ }, | ||
throw new RangeError(); | ||
} | ||
} /** | ||
* @internal | ||
*/ | ||
this._setElementByPos(this._node, newValue); | ||
@@ -308,5 +345,2 @@ }, | ||
}); | ||
RandomIterator.prototype.equals = function (obj) { | ||
return this._node === obj._node; | ||
}; | ||
return RandomIterator; | ||
@@ -328,6 +362,5 @@ }(ContainerIterator); | ||
/** | ||
* @description Vector's constructor. | ||
* @param container Initialize container, must have a forEach function. | ||
* @param copy When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
* @param container - Initialize container, must have a forEach function. | ||
* @param copy - When the container is an array, you can choose to directly operate on the original object of | ||
* the array or perform a shallow copy. The default is shallow copy. | ||
*/ | ||
@@ -381,7 +414,2 @@ function Vector(container, copy) { | ||
}; | ||
Vector.prototype.forEach = function (callback) { | ||
for (var i = 0; i < this._length; ++i) { | ||
callback(this._vector[i], i, this); | ||
} | ||
}; | ||
Vector.prototype.getElementByPos = function (pos) { | ||
@@ -399,2 +427,3 @@ if (pos < 0 || pos > this._length - 1) { | ||
this._length -= 1; | ||
return this._length; | ||
}; | ||
@@ -409,2 +438,3 @@ Vector.prototype.eraseElementByValue = function (value) { | ||
this._length = this._vector.length = index; | ||
return this._length; | ||
}; | ||
@@ -420,7 +450,8 @@ Vector.prototype.eraseElementByIterator = function (iter) { | ||
this._length += 1; | ||
return this._length; | ||
}; | ||
Vector.prototype.popBack = function () { | ||
if (!this._length) return; | ||
this._vector.pop(); | ||
if (this._length === 0) return; | ||
this._length -= 1; | ||
return this._vector.pop(); | ||
}; | ||
@@ -443,2 +474,3 @@ Vector.prototype.setElementByPos = function (pos, element) { | ||
this._length += num; | ||
return this._length; | ||
}; | ||
@@ -464,2 +496,3 @@ Vector.prototype.find = function (element) { | ||
this._length = this._vector.length = index; | ||
return this._length; | ||
}; | ||
@@ -469,2 +502,7 @@ Vector.prototype.sort = function (cmp) { | ||
}; | ||
Vector.prototype.forEach = function (callback) { | ||
for (var i = 0; i < this._length; ++i) { | ||
callback(this._vector[i], i, this); | ||
} | ||
}; | ||
Vector.prototype[Symbol.iterator] = function () { | ||
@@ -477,3 +515,4 @@ return function () { | ||
case 1: | ||
return [2 /*return*/, _a.sent()]; | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
@@ -480,0 +519,0 @@ }); |
/*! | ||
* @js-sdsl/vector v4.2.0-beta.1 | ||
* @js-sdsl/vector v4.2.0 | ||
* https://github.com/js-sdsl/js-sdsl | ||
@@ -7,3 +7,3 @@ * (c) 2021-present ZLY201 <zilongyao1366@gmail.com> | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).sdsl={})}(this,function(t){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}))(t,e)};function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function n(r,i){var o,s,l,h={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},u={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function t(n){return function(t){var e=[n,t];if(o)throw new TypeError("Generator is already executing.");for(;h=u&&e[u=0]?0:h;)try{if(o=1,s&&(l=2&e[0]?s.return:e[0]?s.throw||((l=s.return)&&l.call(s),0):s.next)&&!(l=l.call(s,e[1])).done)return l;switch(s=0,(e=l?[2&e[0],l.value]:e)[0]){case 0:case 1:l=e;break;case 4:return h.label++,{value:e[1],done:!1};case 5:h.label++,s=e[1],e=[0];continue;case 7:e=h.ops.pop(),h.trys.pop();continue;default:if(!(l=0<(l=h.trys).length&&l[l.length-1])&&(6===e[0]||2===e[0])){h=0;continue}if(3===e[0]&&(!l||e[1]>l[0]&&e[1]<l[3]))h.label=e[1];else if(6===e[0]&&h.label<l[1])h.label=l[1],l=e;else{if(!(l&&h.label<l[2])){l[2]&&h.ops.pop(),h.trys.pop();continue}h.label=l[2],h.ops.push(e)}}e=i.call(r,h)}catch(t){e=[6,t],s=0}finally{o=l=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function o(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||((r=r||Array.prototype.slice.call(e,0,i))[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function s(t){this.iteratorType=t=void 0===t?0:t}function l(){this.t=0}l.prototype.size=function(){return this.t},l.prototype.empty=function(){return 0===this.t};e(a,h=l);var h,u=a;function a(){return null!==h&&h.apply(this,arguments)||this}e(f,c=u);var c,u=f;function f(){return null!==c&&c.apply(this,arguments)||this}e(d,p=s),Object.defineProperty(d.prototype,"pointer",{get:function(){if(this.i<0||this.i>this.o()-1)throw new RangeError;return this.u(this.i)},set:function(t){if(this.i<0||this.i>this.o()-1)throw new RangeError;this.h(this.i,t)},enumerable:!1,configurable:!0}),d.prototype.equals=function(t){return this.i===t.i};var p,y=d;function d(t,e,n,r,i){i=p.call(this,i)||this;return i.i=t,i.o=e,i.u=n,i.h=r,0===i.iteratorType?(i.pre=function(){if(0===this.i)throw new RangeError("Random iterator access denied!");return--this.i,this},i.next=function(){if(this.i===this.o())throw new RangeError("Random Iterator access denied!");return this.i+=1,this}):(i.pre=function(){if(this.i===this.o()-1)throw new RangeError("Random iterator access denied!");return this.i+=1,this},i.next=function(){if(-1===this.i)throw new RangeError("Random iterator access denied!");return--this.i,this}),i}e(g,w=y),g.prototype.copy=function(){return new g(this.i,this.o,this.u,this.h,this.iteratorType)};var w,b=g;function g(){return null!==w&&w.apply(this,arguments)||this}e(v,m=u),v.prototype.clear=function(){this.t=0,this.l.length=0},v.prototype.begin=function(){return new b(0,this.size,this.getElementByPos,this.setElementByPos)},v.prototype.end=function(){return new b(this.t,this.size,this.getElementByPos,this.setElementByPos)},v.prototype.rBegin=function(){return new b(this.t-1,this.size,this.getElementByPos,this.setElementByPos,1)},v.prototype.rEnd=function(){return new b(-1,this.size,this.getElementByPos,this.setElementByPos,1)},v.prototype.front=function(){return this.l[0]},v.prototype.back=function(){return this.l[this.t-1]},v.prototype.forEach=function(t){for(var e=0;e<this.t;++e)t(this.l[e],e,this)},v.prototype.getElementByPos=function(t){if(t<0||t>this.t-1)throw new RangeError;return this.l[t]},v.prototype.eraseElementByPos=function(t){if(t<0||t>this.t-1)throw new RangeError;this.l.splice(t,1),--this.t},v.prototype.eraseElementByValue=function(t){for(var e=0,n=0;n<this.t;++n)this.l[n]!==t&&(this.l[e++]=this.l[n]);this.t=this.l.length=e},v.prototype.eraseElementByIterator=function(t){var e=t.i;return t=t.next(),this.eraseElementByPos(e),t},v.prototype.pushBack=function(t){this.l.push(t),this.t+=1},v.prototype.popBack=function(){this.t&&(this.l.pop(),--this.t)},v.prototype.setElementByPos=function(t,e){if(t<0||t>this.t-1)throw new RangeError;this.l[t]=e},v.prototype.insert=function(t,e,n){var r;if(void 0===n&&(n=1),t<0||t>this.t)throw new RangeError;(r=this.l).splice.apply(r,o([t,0],i(new Array(n).fill(e)),!1)),this.t+=n},v.prototype.find=function(t){for(var e=0;e<this.t;++e)if(this.l[e]===t)return new b(e,this.size,this.getElementByPos,this.getElementByPos);return this.end()},v.prototype.reverse=function(){this.l.reverse()},v.prototype.unique=function(){for(var t=1,e=1;e<this.t;++e)this.l[e]!==this.l[e-1]&&(this.l[t++]=this.l[e]);this.t=this.l.length=t},v.prototype.sort=function(t){this.l.sort(t)},v.prototype[Symbol.iterator]=function(){return function(){return n(this,function(t){switch(t.label){case 0:return[5,function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.l)];case 1:return[2,t.sent()]}})}.bind(this)()};var m,y=v;function v(t,e){void 0===t&&(t=[]),void 0===e&&(e=!0);var n,r=m.call(this)||this;return Array.isArray(t)?(r.l=e?o([],i(t),!1):t,r.t=t.length):(r.l=[],n=r,t.forEach(function(t){n.pushBack(t)})),r.size=r.size.bind(r),r.getElementByPos=r.getElementByPos.bind(r),r.setElementByPos=r.setElementByPos.bind(r),r}t.Vector=y,Object.defineProperty(t,"_",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).sdsl={})}(this,function(t){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}))(t,e)};function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function n(r,i){var o,s,l,u={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},h={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(h[Symbol.iterator]=function(){return this}),h;function t(n){return function(t){var e=[n,t];if(o)throw new TypeError("Generator is already executing.");for(;u=h&&e[h=0]?0:u;)try{if(o=1,s&&(l=2&e[0]?s.return:e[0]?s.throw||((l=s.return)&&l.call(s),0):s.next)&&!(l=l.call(s,e[1])).done)return l;switch(s=0,(e=l?[2&e[0],l.value]:e)[0]){case 0:case 1:l=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,s=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(l=0<(l=u.trys).length&&l[l.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!l||e[1]>l[0]&&e[1]<l[3]))u.label=e[1];else if(6===e[0]&&u.label<l[1])u.label=l[1],l=e;else{if(!(l&&u.label<l[2])){l[2]&&u.ops.pop(),u.trys.pop();continue}u.label=l[2],u.ops.push(e)}}e=i.call(r,u)}catch(t){e=[6,t],s=0}finally{o=l=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function o(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||((r=r||Array.prototype.slice.call(e,0,i))[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}l.prototype.equals=function(t){return this.t===t.t};var s=l;function l(t){this.iteratorType=t=void 0===t?0:t}function u(){this.i=0}Object.defineProperty(u.prototype,"length",{get:function(){return this.i},enumerable:!1,configurable:!0}),u.prototype.size=function(){return this.i},u.prototype.empty=function(){return 0===this.i};e(p,h=u);var h,c=p;function p(){return null!==h&&h.apply(this,arguments)||this}e(a,f=c);var f,c=a;function a(){return null!==f&&f.apply(this,arguments)||this}function y(){throw new RangeError("Iterator access denied!")}e(b,d=s),Object.defineProperty(b.prototype,"pointer",{get:function(){if(this.t<0||this.t>this.o()-1)throw new RangeError;return this.u(this.t)},set:function(t){if(this.t<0||this.t>this.o()-1)throw new RangeError;this.h(this.t,t)},enumerable:!1,configurable:!0});var d,s=b;function b(t,e,n,r,i){i=d.call(this,i)||this;return i.t=t,i.o=e,i.u=n,i.h=r,0===i.iteratorType?(i.pre=function(){return 0===this.t&&y(),--this.t,this},i.next=function(){return this.t===this.o()&&y(),this.t+=1,this}):(i.pre=function(){return this.t===this.o()-1&&y(),this.t+=1,this},i.next=function(){return-1===this.t&&y(),--this.t,this}),i}e(w,g=s),w.prototype.copy=function(){return new w(this.t,this.o,this.u,this.h,this.iteratorType)};var g,v=w;function w(){return null!==g&&g.apply(this,arguments)||this}e(E,m=c),E.prototype.clear=function(){this.i=0,this.l.length=0},E.prototype.begin=function(){return new v(0,this.size,this.getElementByPos,this.setElementByPos)},E.prototype.end=function(){return new v(this.i,this.size,this.getElementByPos,this.setElementByPos)},E.prototype.rBegin=function(){return new v(this.i-1,this.size,this.getElementByPos,this.setElementByPos,1)},E.prototype.rEnd=function(){return new v(-1,this.size,this.getElementByPos,this.setElementByPos,1)},E.prototype.front=function(){return this.l[0]},E.prototype.back=function(){return this.l[this.i-1]},E.prototype.getElementByPos=function(t){if(t<0||t>this.i-1)throw new RangeError;return this.l[t]},E.prototype.eraseElementByPos=function(t){if(t<0||t>this.i-1)throw new RangeError;return this.l.splice(t,1),--this.i,this.i},E.prototype.eraseElementByValue=function(t){for(var e=0,n=0;n<this.i;++n)this.l[n]!==t&&(this.l[e++]=this.l[n]);return this.i=this.l.length=e,this.i},E.prototype.eraseElementByIterator=function(t){var e=t.t;return t=t.next(),this.eraseElementByPos(e),t},E.prototype.pushBack=function(t){return this.l.push(t),this.i+=1,this.i},E.prototype.popBack=function(){if(0!==this.i)return--this.i,this.l.pop()},E.prototype.setElementByPos=function(t,e){if(t<0||t>this.i-1)throw new RangeError;this.l[t]=e},E.prototype.insert=function(t,e,n){var r;if(void 0===n&&(n=1),t<0||t>this.i)throw new RangeError;return(r=this.l).splice.apply(r,o([t,0],i(new Array(n).fill(e)),!1)),this.i+=n,this.i},E.prototype.find=function(t){for(var e=0;e<this.i;++e)if(this.l[e]===t)return new v(e,this.size,this.getElementByPos,this.getElementByPos);return this.end()},E.prototype.reverse=function(){this.l.reverse()},E.prototype.unique=function(){for(var t=1,e=1;e<this.i;++e)this.l[e]!==this.l[e-1]&&(this.l[t++]=this.l[e]);return this.i=this.l.length=t,this.i},E.prototype.sort=function(t){this.l.sort(t)},E.prototype.forEach=function(t){for(var e=0;e<this.i;++e)t(this.l[e],e,this)},E.prototype[Symbol.iterator]=function(){return function(){return n(this,function(t){switch(t.label){case 0:return[5,function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.l)];case 1:return t.sent(),[2]}})}.bind(this)()};var m,s=E;function E(t,e){void 0===t&&(t=[]),void 0===e&&(e=!0);var n,r=m.call(this)||this;return Array.isArray(t)?(r.l=e?o([],i(t),!1):t,r.i=t.length):(r.l=[],n=r,t.forEach(function(t){n.pushBack(t)})),r.size=r.size.bind(r),r.getElementByPos=r.getElementByPos.bind(r),r.setElementByPos=r.setElementByPos.bind(r),r}t.Vector=s,Object.defineProperty(t,"_",{value:!0})}); | ||
//# sourceMappingURL=vector.min.js.map |
{ | ||
"name": "@js-sdsl/vector", | ||
"version": "4.2.0-beta.1", | ||
"version": "4.2.0", | ||
"description": "javascript standard data structure library which benchmark against C++ STL", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
<p align="center"> | ||
<a href="https://js-sdsl.org/" target="_blank" rel="noopener noreferrer"> | ||
<img src="https://js-sdsl.org/assets/logo-removebg.png" alt="js-sdsl logo" width="120" /> | ||
<img src="https://js-sdsl.org/assets/image/logo/logo-removebg.png" alt="js-sdsl logo" width="120" /> | ||
</a> | ||
@@ -45,23 +45,23 @@ </p> | ||
<td> | ||
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" /> | ||
<img alt="IE / Edge" src="https://js-sdsl.org/assets/image/platform/edge.png" /> | ||
<div>IE / Edge</div> | ||
</td> | ||
<td> | ||
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" /> | ||
<img alt="Firefox" src="https://js-sdsl.org/assets/image/platform/firefox.png" /> | ||
<div>Firefox</div> | ||
</td> | ||
<td> | ||
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" /> | ||
<img alt="Chrome" src="https://js-sdsl.org/assets/image/platform/chrome.png" /> | ||
<div>Chrome</div> | ||
</td> | ||
<td> | ||
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" /> | ||
<img alt="Safari" src="https://js-sdsl.org/assets/image/platform/safari.png" /> | ||
<div>Safari</div> | ||
</td> | ||
<td> | ||
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" /> | ||
<img alt="Opera" src="https://js-sdsl.org/assets/image/platform/opera.png" /> | ||
<div>Opera</div> | ||
</td> | ||
<td> | ||
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" /> | ||
<img alt="NodeJs" src="https://js-sdsl.org/assets/image/platform/nodejs.png" /> | ||
<div>NodeJs</div> | ||
@@ -217,3 +217,3 @@ </td> | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/image/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
@@ -220,0 +220,0 @@ Thanks also give to these sponsors or backers: |
<p align="center"> | ||
<a href="https://js-sdsl.org/" target="_blank" rel="noopener noreferrer"> | ||
<img src="https://js-sdsl.org/assets/logo-removebg.png" alt="js-sdsl logo" width="120" /> | ||
<img src="https://js-sdsl.org/assets/image/logo/logo-removebg.png" alt="js-sdsl logo" width="120" /> | ||
</a> | ||
@@ -47,23 +47,23 @@ </p> | ||
<td> | ||
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" /> | ||
<img alt="IE / Edge" src="https://js-sdsl.org/assets/image/platform/edge.png" /> | ||
<div>IE / Edge</div> | ||
</td> | ||
<td> | ||
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" /> | ||
<img alt="Firefox" src="https://js-sdsl.org/assets/image/platform/firefox.png" /> | ||
<div>Firefox</div> | ||
</td> | ||
<td> | ||
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" /> | ||
<img alt="Chrome" src="https://js-sdsl.org/assets/image/platform/chrome.png" /> | ||
<div>Chrome</div> | ||
</td> | ||
<td> | ||
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" /> | ||
<img alt="Safari" src="https://js-sdsl.org/assets/image/platform/safari.png" /> | ||
<div>Safari</div> | ||
</td> | ||
<td> | ||
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" /> | ||
<img alt="Opera" src="https://js-sdsl.org/assets/image/platform/opera.png" /> | ||
<div>Opera</div> | ||
</td> | ||
<td> | ||
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" /> | ||
<img alt="NodeJs" src="https://js-sdsl.org/assets/image/platform/nodejs.png" /> | ||
<div>NodeJs</div> | ||
@@ -219,3 +219,3 @@ </td> | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/image/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a> | ||
@@ -222,0 +222,0 @@ 同样感谢这些赞助商和支持者们: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
200416
1786
0