@js-sdsl/hash-map
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,6 +1,82 @@ | ||
/** | ||
* @description The iterator type including `NORMAL` and `REVERSE`. | ||
*/ | ||
declare const enum IteratorType { | ||
NORMAL = 0, | ||
REVERSE = 1 | ||
} | ||
declare abstract class ContainerIterator<T> { | ||
/** | ||
* @description Iterator's type. | ||
* @example | ||
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
*/ | ||
readonly 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. | ||
* @returns The value of the pointer's element. | ||
* @example | ||
* const val = container.begin().pointer; | ||
*/ | ||
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; | ||
*/ | ||
abstract set pointer(newValue: T); | ||
/** | ||
* @description Move `this` iterator to pre. | ||
* @returns The iterator's self. | ||
* @example | ||
* const iter = container.find(1); // container = [0, 1] | ||
* const pre = iter.pre(); | ||
* console.log(pre === iter); // true | ||
* console.log(pre.equals(iter)); // true | ||
* console.log(pre.pointer, iter.pointer); // 0, 0 | ||
*/ | ||
abstract pre(): this; | ||
/** | ||
* @description Move `this` iterator to next. | ||
* @returns The iterator's self. | ||
* @example | ||
* const iter = container.find(1); // container = [1, 2] | ||
* const next = iter.next(); | ||
* console.log(next === iter); // true | ||
* console.log(next.equals(iter)); // true | ||
* console.log(next.pointer, iter.pointer); // 2, 2 | ||
*/ | ||
abstract next(): this; | ||
/** | ||
* @description Get a copy of itself. | ||
* @returns The copy of self. | ||
* @example | ||
* const iter = container.find(1); // container = [1, 2] | ||
* const next = iter.copy().next(); | ||
* console.log(next === iter); // false | ||
* console.log(next.equals(iter)); // false | ||
* console.log(next.pointer, iter.pointer); // 2, 1 | ||
*/ | ||
abstract copy(): ContainerIterator<T>; | ||
} | ||
declare abstract class Base { | ||
/** | ||
* @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 | ||
@@ -10,3 +86,3 @@ */ | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -25,39 +101,89 @@ * container.clear(); | ||
} | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare abstract class HashContainer<K, V> extends Base { | ||
protected constructor(); | ||
clear(): void; | ||
declare abstract class Container<T> extends Base { | ||
/** | ||
* @description Remove the element of the specified key. | ||
* @param key The key you want to remove. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns Iterator pointing to the beginning element. | ||
* @example | ||
* const begin = container.begin(); | ||
* const end = container.end(); | ||
* for (const it = begin; !it.equals(end); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
eraseElementByKey(key: K, isObject?: boolean): void; | ||
abstract begin(): ContainerIterator<T>; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key The element you want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @return Boolean about if key exist in container. | ||
* @returns Iterator pointing to the super end like c++. | ||
* @example | ||
* const begin = container.begin(); | ||
* const end = container.end(); | ||
* for (const it = begin; !it.equals(end); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
find(key: K, isObject?: boolean): boolean; | ||
abstract end(): ContainerIterator<T>; | ||
/** | ||
* @returns Iterator pointing to the end element. | ||
* @example | ||
* const rBegin = container.rBegin(); | ||
* const rEnd = container.rEnd(); | ||
* for (const it = rBegin; !it.equals(rEnd); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
abstract rBegin(): ContainerIterator<T>; | ||
/** | ||
* @returns Iterator pointing to the super begin like c++. | ||
* @example | ||
* const rBegin = container.rBegin(); | ||
* const rEnd = container.rEnd(); | ||
* for (const it = rBegin; !it.equals(rEnd); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
abstract rEnd(): ContainerIterator<T>; | ||
/** | ||
* @returns The first element of the container. | ||
*/ | ||
abstract front(): T | undefined; | ||
/** | ||
* @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: K | [ | ||
K, | ||
V | ||
], index: number, hashContainer: HashContainer<K, V>) => void): void; | ||
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void; | ||
/** | ||
* @description Gets the value of the element at the specified position. | ||
* @example | ||
* const val = container.getElementByPos(-1); // throw a RangeError | ||
*/ | ||
abstract getElementByPos(pos: number): T; | ||
/** | ||
* @description Removes the element at the specified position. | ||
* @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): number; | ||
/** | ||
* @description Removes element by iterator and move `iter` to next. | ||
* @param iter - The iterator you want to erase. | ||
* @returns The next iterator. | ||
* @example | ||
* container.eraseElementByIterator(container.begin()); | ||
* container.eraseElementByIterator(container.end()); // throw a RangeError | ||
*/ | ||
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>; | ||
/** | ||
* @description Using for `for...of` syntax like Array. | ||
@@ -69,6 +195,53 @@ * @example | ||
*/ | ||
abstract [Symbol.iterator](): Generator<K | [ | ||
abstract [Symbol.iterator](): Generator<T, void>; | ||
} | ||
/** | ||
* @description The initial data type passed in when initializing the container. | ||
*/ | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare abstract class HashContainerIterator<K, V> extends ContainerIterator<K | [ | ||
K, | ||
V | ||
]> { | ||
// @ts-ignore | ||
pre(): this; | ||
// @ts-ignore | ||
next(): this; | ||
} | ||
declare abstract class HashContainer<K, V> extends Container<K | [ | ||
K, | ||
V | ||
]> { | ||
/** | ||
* @description Unique symbol used to tag object. | ||
*/ | ||
readonly HASH_TAG: symbol; | ||
clear(): void; | ||
/** | ||
* @description Remove the element of the specified key. | ||
* @param key - The key you want to remove. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns Whether erase successfully. | ||
*/ | ||
eraseElementByKey(key: K, isObject?: boolean): boolean; | ||
eraseElementByIterator(iter: HashContainerIterator<K, V>): HashContainerIterator<K, V>; | ||
eraseElementByPos(pos: number): number; | ||
} | ||
declare class HashMapIterator<K, V> extends HashContainerIterator<K, V> { | ||
get pointer(): [ | ||
K, | ||
V | ||
], void, undefined>; | ||
]; | ||
copy(): HashMapIterator<K, V>; | ||
// @ts-ignore | ||
equals(iter: HashMapIterator<K, V>): boolean; | ||
} | ||
@@ -80,18 +253,44 @@ declare class HashMap<K, V> extends HashContainer<K, V> { | ||
]>); | ||
begin(): HashMapIterator<K, V>; | ||
end(): HashMapIterator<K, V>; | ||
rBegin(): HashMapIterator<K, V>; | ||
rEnd(): HashMapIterator<K, V>; | ||
front(): [ | ||
K, | ||
V | ||
] | undefined; | ||
back(): [ | ||
K, | ||
V | ||
] | undefined; | ||
/** | ||
* @description Insert a key-value pair or set value by the given key. | ||
* @param key The key want to insert. | ||
* @param value The value want to set. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @param key - The key want to insert. | ||
* @param value - The value want to set. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns The size of container after setting. | ||
*/ | ||
setElement(key: K, value: V, isObject?: boolean): void; | ||
setElement(key: K, value: V, isObject?: boolean): number; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key - The element you want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns An iterator pointing to the element if found, or super end if not found. | ||
*/ | ||
/** | ||
* @description Get the value of the element of the specified key. | ||
* @param key The key want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example const val = container.getElementByKey(1); | ||
* @param key - The key want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example | ||
* const val = container.getElementByKey(1); | ||
*/ | ||
getElementByKey(key: K, isObject?: boolean): V | undefined; | ||
getElementByPos(pos: number): [ | ||
K, | ||
V | ||
]; | ||
find(key: K, isObject?: boolean): HashMapIterator<K, V>; | ||
forEach(callback: (element: [ | ||
@@ -104,5 +303,5 @@ K, | ||
V | ||
], void, undefined>; | ||
], void, unknown>; | ||
} | ||
export { HashMap }; | ||
export type { HashContainer }; | ||
export type { HashMapIterator, IteratorType, Container, ContainerIterator, HashContainer }; |
@@ -7,84 +7,225 @@ "use strict"; | ||
class ContainerIterator { | ||
constructor(t = 0) { | ||
this.iteratorType = t; | ||
} | ||
equals(t) { | ||
return this.i === t.i; | ||
} | ||
} | ||
class Base { | ||
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; | ||
} | ||
} | ||
class Container extends Base {} | ||
function checkObject(t) { | ||
if (t === null) return false; | ||
const e = typeof t; | ||
return e === "object" || e === "function"; | ||
return e === "object" && t !== null || e === "function"; | ||
} | ||
class HashContainer extends Base { | ||
function throwIteratorAccessError() { | ||
throw new RangeError("Iterator access denied!"); | ||
} | ||
class HashContainerIterator extends ContainerIterator { | ||
constructor(t, e, s) { | ||
super(s); | ||
this.i = t; | ||
this.o = e; | ||
if (this.iteratorType === 0) { | ||
this.pre = function() { | ||
if (this.i.u === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i = this.i.u; | ||
return this; | ||
}; | ||
this.next = function() { | ||
if (this.i === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i = this.i.l; | ||
return this; | ||
}; | ||
} else { | ||
this.pre = function() { | ||
if (this.i.l === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i = this.i.l; | ||
return this; | ||
}; | ||
this.next = function() { | ||
if (this.i === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
this.i = this.i.u; | ||
return this; | ||
}; | ||
} | ||
} | ||
} | ||
class HashContainer extends Container { | ||
constructor() { | ||
super(); | ||
this.h = []; | ||
this.p = []; | ||
this.I = {}; | ||
this.HASH_TAG = Symbol("@@HASH_TAG"); | ||
Object.setPrototypeOf(this.I, null); | ||
this.o = {}; | ||
this.HASH_KEY_TAG = Symbol("JS_SDSL_HASH_KEY_TAG"); | ||
Object.setPrototypeOf(this.o, null); | ||
this.o.u = this.o.l = this._ = this.H = this.o; | ||
} | ||
u(t, e, s) { | ||
g(t) { | ||
const {u: e, l: s} = t; | ||
e.l = s; | ||
s.u = e; | ||
if (t === this._) { | ||
this._ = s; | ||
} | ||
if (t === this.H) { | ||
this.H = e; | ||
} | ||
this.h -= 1; | ||
} | ||
m(t, e, s) { | ||
if (s === undefined) s = checkObject(t); | ||
let r; | ||
if (s) { | ||
const s = t[this.HASH_KEY_TAG]; | ||
const s = t[this.HASH_TAG]; | ||
if (s !== undefined) { | ||
this.h[s][1] = e; | ||
return; | ||
this.p[s].j = e; | ||
return this.h; | ||
} | ||
Object.defineProperty(t, this.HASH_KEY_TAG, { | ||
value: this.h.length, | ||
Object.defineProperty(t, this.HASH_TAG, { | ||
value: this.p.length, | ||
configurable: true | ||
}); | ||
this.h.push([ t, e ]); | ||
r = { | ||
M: t, | ||
j: e, | ||
u: this.H, | ||
l: this.o | ||
}; | ||
this.p.push(r); | ||
} else { | ||
const s = this.o[t]; | ||
const s = this.I[t]; | ||
if (s) { | ||
s[1] = e; | ||
return; | ||
s.j = e; | ||
return this.h; | ||
} | ||
this.o[t] = [ t, e ]; | ||
r = { | ||
M: t, | ||
j: e, | ||
u: this.H, | ||
l: this.o | ||
}; | ||
this.I[t] = r; | ||
} | ||
this.i += 1; | ||
if (this.h === 0) { | ||
this._ = r; | ||
this.o.l = r; | ||
} else { | ||
this.H.l = r; | ||
} | ||
this.H = r; | ||
this.o.u = r; | ||
return ++this.h; | ||
} | ||
A(t, e) { | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
const e = t[this.HASH_TAG]; | ||
if (e === undefined) return this.o; | ||
return this.p[e]; | ||
} else { | ||
return this.I[t] || this.o; | ||
} | ||
} | ||
clear() { | ||
const t = this; | ||
this.h.forEach((function(e) { | ||
delete e[0][t.HASH_KEY_TAG]; | ||
const t = this.HASH_TAG; | ||
this.p.forEach((function(e) { | ||
delete e.M[t]; | ||
})); | ||
this.h = []; | ||
this.o = {}; | ||
Object.setPrototypeOf(this.o, null); | ||
this.i = 0; | ||
this.p = []; | ||
this.I = {}; | ||
Object.setPrototypeOf(this.I, null); | ||
this.h = 0; | ||
this._ = this.H = this.o.u = this.o.l = this.o; | ||
} | ||
eraseElementByKey(t, e) { | ||
let s; | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
const e = t[this.HASH_KEY_TAG]; | ||
if (e === undefined) return; | ||
delete t[this.HASH_KEY_TAG]; | ||
delete this.h[e]; | ||
const e = t[this.HASH_TAG]; | ||
if (e === undefined) return false; | ||
delete t[this.HASH_TAG]; | ||
s = this.p[e]; | ||
delete this.p[e]; | ||
} else { | ||
if (this.o[t] === undefined) return; | ||
delete this.o[t]; | ||
s = this.I[t]; | ||
if (s === undefined) return false; | ||
delete this.I[t]; | ||
} | ||
this.i -= 1; | ||
this.g(s); | ||
return true; | ||
} | ||
find(t, e) { | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
return typeof t[this.HASH_KEY_TAG] === "number"; | ||
} else { | ||
return this.o[t] !== undefined; | ||
eraseElementByIterator(t) { | ||
const e = t.i; | ||
if (e === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
this.g(e); | ||
return t.next(); | ||
} | ||
eraseElementByPos(t) { | ||
if (t < 0 || t > this.h - 1) { | ||
throw new RangeError; | ||
} | ||
let e = this._; | ||
while (t--) { | ||
e = e.l; | ||
} | ||
this.g(e); | ||
return this.h; | ||
} | ||
} | ||
class HashMapIterator extends HashContainerIterator { | ||
get pointer() { | ||
if (this.i === this.o) { | ||
throwIteratorAccessError(); | ||
} | ||
const t = this; | ||
return new Proxy([], { | ||
get(e, s) { | ||
if (s === "0") return t.i.M; else if (s === "1") return t.i.j; | ||
}, | ||
set(e, s, r) { | ||
if (s !== "1") { | ||
throw new TypeError("props must be 1"); | ||
} | ||
t.i.j = r; | ||
return true; | ||
} | ||
}); | ||
} | ||
copy() { | ||
return new HashMapIterator(this.i, this.o, this.iteratorType); | ||
} | ||
} | ||
class HashMap extends HashContainer { | ||
@@ -98,4 +239,24 @@ constructor(t = []) { | ||
} | ||
begin() { | ||
return new HashMapIterator(this._, this.o); | ||
} | ||
end() { | ||
return new HashMapIterator(this.o, this.o); | ||
} | ||
rBegin() { | ||
return new HashMapIterator(this.H, this.o, 1); | ||
} | ||
rEnd() { | ||
return new HashMapIterator(this.o, this.o, 1); | ||
} | ||
front() { | ||
if (this.h === 0) return; | ||
return [ this._.M, this._.j ]; | ||
} | ||
back() { | ||
if (this.h === 0) return; | ||
return [ this.H.M, this.H.j ]; | ||
} | ||
setElement(t, e, s) { | ||
this.u(t, e, s); | ||
return this.m(t, e, s); | ||
} | ||
@@ -105,23 +266,28 @@ getElementByKey(t, e) { | ||
if (e) { | ||
const e = t[this.HASH_KEY_TAG]; | ||
return e !== undefined ? this.h[e][1] : undefined; | ||
const e = t[this.HASH_TAG]; | ||
return e !== undefined ? this.p[e].j : undefined; | ||
} | ||
const s = this.o[t]; | ||
return s ? s[1] : undefined; | ||
const s = this.I[t]; | ||
return s ? s.j : undefined; | ||
} | ||
forEach(t) { | ||
const e = this.h.length; | ||
for (let s = 0; s < e; ++s) { | ||
t(this.h[s], s, this); | ||
getElementByPos(t) { | ||
if (t < 0 || t > this.h - 1) { | ||
throw new RangeError; | ||
} | ||
const s = Object.keys(this.o); | ||
const i = s.length; | ||
let n = e; | ||
for (let e = 0; e < i; ++e) { | ||
t(this.o[s[e]], n++, this); | ||
let e = this._; | ||
while (t--) { | ||
e = e.l; | ||
} | ||
const c = Object.getOwnPropertySymbols(this.o); | ||
const h = c.length; | ||
for (let e = 0; e < h; ++e) { | ||
t(this.o[c[e]], n++, this); | ||
return [ e.M, e.j ]; | ||
} | ||
find(t, e) { | ||
const s = this.A(t, e); | ||
return new HashMapIterator(s, this.o); | ||
} | ||
forEach(t) { | ||
let e = 0; | ||
let s = this._; | ||
while (s !== this.o) { | ||
t([ s.M, s.j ], e++, this); | ||
s = s.l; | ||
} | ||
@@ -131,13 +297,7 @@ } | ||
return function*() { | ||
yield* this.h; | ||
const t = Object.keys(this.o); | ||
const e = t.length; | ||
for (let s = 0; s < e; ++s) { | ||
yield this.o[t[s]]; | ||
let t = this._; | ||
while (t !== this.o) { | ||
yield [ t.M, t.j ]; | ||
t = t.l; | ||
} | ||
const s = Object.getOwnPropertySymbols(this.o); | ||
const i = s.length; | ||
for (let t = 0; t < i; ++t) { | ||
yield this.o[s[t]]; | ||
} | ||
}.bind(this)(); | ||
@@ -144,0 +304,0 @@ } |
@@ -0,6 +1,82 @@ | ||
/** | ||
* @description The iterator type including `NORMAL` and `REVERSE`. | ||
*/ | ||
declare const enum IteratorType { | ||
NORMAL = 0, | ||
REVERSE = 1 | ||
} | ||
declare abstract class ContainerIterator<T> { | ||
/** | ||
* @description Iterator's type. | ||
* @example | ||
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true | ||
*/ | ||
readonly 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. | ||
* @returns The value of the pointer's element. | ||
* @example | ||
* const val = container.begin().pointer; | ||
*/ | ||
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; | ||
*/ | ||
abstract set pointer(newValue: T); | ||
/** | ||
* @description Move `this` iterator to pre. | ||
* @returns The iterator's self. | ||
* @example | ||
* const iter = container.find(1); // container = [0, 1] | ||
* const pre = iter.pre(); | ||
* console.log(pre === iter); // true | ||
* console.log(pre.equals(iter)); // true | ||
* console.log(pre.pointer, iter.pointer); // 0, 0 | ||
*/ | ||
abstract pre(): this; | ||
/** | ||
* @description Move `this` iterator to next. | ||
* @returns The iterator's self. | ||
* @example | ||
* const iter = container.find(1); // container = [1, 2] | ||
* const next = iter.next(); | ||
* console.log(next === iter); // true | ||
* console.log(next.equals(iter)); // true | ||
* console.log(next.pointer, iter.pointer); // 2, 2 | ||
*/ | ||
abstract next(): this; | ||
/** | ||
* @description Get a copy of itself. | ||
* @returns The copy of self. | ||
* @example | ||
* const iter = container.find(1); // container = [1, 2] | ||
* const next = iter.copy().next(); | ||
* console.log(next === iter); // false | ||
* console.log(next.equals(iter)); // false | ||
* console.log(next.pointer, iter.pointer); // 2, 1 | ||
*/ | ||
abstract copy(): ContainerIterator<T>; | ||
} | ||
declare abstract class Base { | ||
/** | ||
* @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 | ||
@@ -10,3 +86,3 @@ */ | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -25,39 +101,89 @@ * container.clear(); | ||
} | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare abstract class HashContainer<K, V> extends Base { | ||
protected constructor(); | ||
clear(): void; | ||
declare abstract class Container<T> extends Base { | ||
/** | ||
* @description Remove the element of the specified key. | ||
* @param key The key you want to remove. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns Iterator pointing to the beginning element. | ||
* @example | ||
* const begin = container.begin(); | ||
* const end = container.end(); | ||
* for (const it = begin; !it.equals(end); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
eraseElementByKey(key: K, isObject?: boolean): void; | ||
abstract begin(): ContainerIterator<T>; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key The element you want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @return Boolean about if key exist in container. | ||
* @returns Iterator pointing to the super end like c++. | ||
* @example | ||
* const begin = container.begin(); | ||
* const end = container.end(); | ||
* for (const it = begin; !it.equals(end); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
find(key: K, isObject?: boolean): boolean; | ||
abstract end(): ContainerIterator<T>; | ||
/** | ||
* @returns Iterator pointing to the end element. | ||
* @example | ||
* const rBegin = container.rBegin(); | ||
* const rEnd = container.rEnd(); | ||
* for (const it = rBegin; !it.equals(rEnd); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
abstract rBegin(): ContainerIterator<T>; | ||
/** | ||
* @returns Iterator pointing to the super begin like c++. | ||
* @example | ||
* const rBegin = container.rBegin(); | ||
* const rEnd = container.rEnd(); | ||
* for (const it = rBegin; !it.equals(rEnd); it.next()) { | ||
* doSomething(it.pointer); | ||
* } | ||
*/ | ||
abstract rEnd(): ContainerIterator<T>; | ||
/** | ||
* @returns The first element of the container. | ||
*/ | ||
abstract front(): T | undefined; | ||
/** | ||
* @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: K | [ | ||
K, | ||
V | ||
], index: number, hashContainer: HashContainer<K, V>) => void): void; | ||
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void; | ||
/** | ||
* @description Gets the value of the element at the specified position. | ||
* @example | ||
* const val = container.getElementByPos(-1); // throw a RangeError | ||
*/ | ||
abstract getElementByPos(pos: number): T; | ||
/** | ||
* @description Removes the element at the specified position. | ||
* @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): number; | ||
/** | ||
* @description Removes element by iterator and move `iter` to next. | ||
* @param iter - The iterator you want to erase. | ||
* @returns The next iterator. | ||
* @example | ||
* container.eraseElementByIterator(container.begin()); | ||
* container.eraseElementByIterator(container.end()); // throw a RangeError | ||
*/ | ||
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>; | ||
/** | ||
* @description Using for `for...of` syntax like Array. | ||
@@ -69,6 +195,53 @@ * @example | ||
*/ | ||
abstract [Symbol.iterator](): Generator<K | [ | ||
abstract [Symbol.iterator](): Generator<T, void>; | ||
} | ||
/** | ||
* @description The initial data type passed in when initializing the container. | ||
*/ | ||
type initContainer<T> = ({ | ||
size: number; | ||
} | { | ||
length: number; | ||
} | { | ||
size(): number; | ||
}) & { | ||
forEach(callback: (element: T) => void): void; | ||
}; | ||
declare abstract class HashContainerIterator<K, V> extends ContainerIterator<K | [ | ||
K, | ||
V | ||
]> { | ||
// @ts-ignore | ||
pre(): this; | ||
// @ts-ignore | ||
next(): this; | ||
} | ||
declare abstract class HashContainer<K, V> extends Container<K | [ | ||
K, | ||
V | ||
]> { | ||
/** | ||
* @description Unique symbol used to tag object. | ||
*/ | ||
readonly HASH_TAG: symbol; | ||
clear(): void; | ||
/** | ||
* @description Remove the element of the specified key. | ||
* @param key - The key you want to remove. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns Whether erase successfully. | ||
*/ | ||
eraseElementByKey(key: K, isObject?: boolean): boolean; | ||
eraseElementByIterator(iter: HashContainerIterator<K, V>): HashContainerIterator<K, V>; | ||
eraseElementByPos(pos: number): number; | ||
} | ||
declare class HashMapIterator<K, V> extends HashContainerIterator<K, V> { | ||
get pointer(): [ | ||
K, | ||
V | ||
], void, undefined>; | ||
]; | ||
copy(): HashMapIterator<K, V>; | ||
// @ts-ignore | ||
equals(iter: HashMapIterator<K, V>): boolean; | ||
} | ||
@@ -80,18 +253,44 @@ declare class HashMap<K, V> extends HashContainer<K, V> { | ||
]>); | ||
begin(): HashMapIterator<K, V>; | ||
end(): HashMapIterator<K, V>; | ||
rBegin(): HashMapIterator<K, V>; | ||
rEnd(): HashMapIterator<K, V>; | ||
front(): [ | ||
K, | ||
V | ||
] | undefined; | ||
back(): [ | ||
K, | ||
V | ||
] | undefined; | ||
/** | ||
* @description Insert a key-value pair or set value by the given key. | ||
* @param key The key want to insert. | ||
* @param value The value want to set. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @param key - The key want to insert. | ||
* @param value - The value want to set. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns The size of container after setting. | ||
*/ | ||
setElement(key: K, value: V, isObject?: boolean): void; | ||
setElement(key: K, value: V, isObject?: boolean): number; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key - The element you want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns An iterator pointing to the element if found, or super end if not found. | ||
*/ | ||
/** | ||
* @description Get the value of the element of the specified key. | ||
* @param key The key want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example const val = container.getElementByKey(1); | ||
* @param key - The key want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example | ||
* const val = container.getElementByKey(1); | ||
*/ | ||
getElementByKey(key: K, isObject?: boolean): V | undefined; | ||
getElementByPos(pos: number): [ | ||
K, | ||
V | ||
]; | ||
find(key: K, isObject?: boolean): HashMapIterator<K, V>; | ||
forEach(callback: (element: [ | ||
@@ -104,5 +303,5 @@ K, | ||
V | ||
], void, undefined>; | ||
], void, unknown>; | ||
} | ||
export { HashMap }; | ||
export type { HashContainer }; | ||
export type { HashMapIterator, IteratorType, Container, ContainerIterator, HashContainer }; |
@@ -1,22 +0,22 @@ | ||
var extendStatics = function(t, e) { | ||
var extendStatics = function(t, r) { | ||
extendStatics = Object.setPrototypeOf || { | ||
__proto__: [] | ||
} instanceof Array && function(t, e) { | ||
t.__proto__ = e; | ||
} || function(t, e) { | ||
for (var n in e) if (Object.prototype.hasOwnProperty.call(e, n)) t[n] = e[n]; | ||
} instanceof Array && function(t, r) { | ||
t.__proto__ = r; | ||
} || function(t, r) { | ||
for (var n in r) if (Object.prototype.hasOwnProperty.call(r, n)) t[n] = r[n]; | ||
}; | ||
return extendStatics(t, e); | ||
return extendStatics(t, r); | ||
}; | ||
function __extends(t, e) { | ||
if (typeof e !== "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null"); | ||
extendStatics(t, e); | ||
function __extends(t, r) { | ||
if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null"); | ||
extendStatics(t, r); | ||
function __() { | ||
this.constructor = t; | ||
} | ||
t.prototype = e === null ? Object.create(e) : (__.prototype = e.prototype, new __); | ||
t.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __); | ||
} | ||
function __generator(t, e) { | ||
function __generator(t, r) { | ||
var n = { | ||
@@ -30,3 +30,3 @@ label: 0, | ||
ops: [] | ||
}, r, i, s, a; | ||
}, e, i, s, a; | ||
return a = { | ||
@@ -40,16 +40,16 @@ next: verb(0), | ||
function verb(t) { | ||
return function(e) { | ||
return step([ t, e ]); | ||
return function(r) { | ||
return step([ t, r ]); | ||
}; | ||
} | ||
function step(u) { | ||
if (r) throw new TypeError("Generator is already executing."); | ||
while (a && (a = 0, u[0] && (n = 0)), n) try { | ||
if (r = 1, i && (s = u[0] & 2 ? i["return"] : u[0] ? i["throw"] || ((s = i["return"]) && s.call(i), | ||
0) : i.next) && !(s = s.call(i, u[1])).done) return s; | ||
if (i = 0, s) u = [ u[0] & 2, s.value ]; | ||
switch (u[0]) { | ||
function step(h) { | ||
if (e) throw new TypeError("Generator is already executing."); | ||
while (a && (a = 0, h[0] && (n = 0)), n) try { | ||
if (e = 1, i && (s = h[0] & 2 ? i["return"] : h[0] ? i["throw"] || ((s = i["return"]) && s.call(i), | ||
0) : i.next) && !(s = s.call(i, h[1])).done) return s; | ||
if (i = 0, s) h = [ h[0] & 2, s.value ]; | ||
switch (h[0]) { | ||
case 0: | ||
case 1: | ||
s = u; | ||
s = h; | ||
break; | ||
@@ -60,3 +60,3 @@ | ||
return { | ||
value: u[1], | ||
value: h[1], | ||
done: false | ||
@@ -67,8 +67,8 @@ }; | ||
n.label++; | ||
i = u[1]; | ||
u = [ 0 ]; | ||
i = h[1]; | ||
h = [ 0 ]; | ||
continue; | ||
case 7: | ||
u = n.ops.pop(); | ||
h = n.ops.pop(); | ||
n.trys.pop(); | ||
@@ -78,13 +78,13 @@ continue; | ||
default: | ||
if (!(s = n.trys, s = s.length > 0 && s[s.length - 1]) && (u[0] === 6 || u[0] === 2)) { | ||
if (!(s = n.trys, s = s.length > 0 && s[s.length - 1]) && (h[0] === 6 || h[0] === 2)) { | ||
n = 0; | ||
continue; | ||
} | ||
if (u[0] === 3 && (!s || u[1] > s[0] && u[1] < s[3])) { | ||
n.label = u[1]; | ||
if (h[0] === 3 && (!s || h[1] > s[0] && h[1] < s[3])) { | ||
n.label = h[1]; | ||
break; | ||
} | ||
if (u[0] === 6 && n.label < s[1]) { | ||
if (h[0] === 6 && n.label < s[1]) { | ||
n.label = s[1]; | ||
s = u; | ||
s = h; | ||
break; | ||
@@ -94,3 +94,3 @@ } | ||
n.label = s[2]; | ||
n.ops.push(u); | ||
n.ops.push(h); | ||
break; | ||
@@ -102,12 +102,12 @@ } | ||
} | ||
u = e.call(t, n); | ||
h = r.call(t, n); | ||
} catch (t) { | ||
u = [ 6, t ]; | ||
h = [ 6, t ]; | ||
i = 0; | ||
} finally { | ||
r = s = 0; | ||
e = s = 0; | ||
} | ||
if (u[0] & 5) throw u[1]; | ||
if (h[0] & 5) throw h[1]; | ||
return { | ||
value: u[0] ? u[1] : void 0, | ||
value: h[0] ? h[1] : void 0, | ||
done: true | ||
@@ -118,26 +118,31 @@ }; | ||
function __values(t) { | ||
var e = typeof Symbol === "function" && Symbol.iterator, n = e && t[e], r = 0; | ||
if (n) return n.call(t); | ||
if (t && typeof t.length === "number") return { | ||
next: function() { | ||
if (t && r >= t.length) t = void 0; | ||
return { | ||
value: t && t[r++], | ||
done: !t | ||
}; | ||
var ContainerIterator = function() { | ||
function ContainerIterator(t) { | ||
if (t === void 0) { | ||
t = 0; | ||
} | ||
this.iteratorType = t; | ||
} | ||
ContainerIterator.prototype.equals = function(t) { | ||
return this.t === t.t; | ||
}; | ||
throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
} | ||
return ContainerIterator; | ||
}(); | ||
var Base = function() { | ||
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; | ||
}; | ||
@@ -147,3 +152,3 @@ return Base; | ||
(function(t) { | ||
var Container = function(t) { | ||
__extends(Container, t); | ||
@@ -154,117 +159,281 @@ function Container() { | ||
return Container; | ||
})(Base); | ||
}(Base); | ||
function checkObject(t) { | ||
if (t === null) return false; | ||
var e = typeof t; | ||
return e === "object" || e === "function"; | ||
var r = typeof t; | ||
return r === "object" && t !== null || r === "function"; | ||
} | ||
function throwIteratorAccessError() { | ||
throw new RangeError("Iterator access denied!"); | ||
} | ||
var HashContainerIterator = function(t) { | ||
__extends(HashContainerIterator, t); | ||
function HashContainerIterator(r, n, e) { | ||
var i = t.call(this, e) || this; | ||
i.t = r; | ||
i.h = n; | ||
if (i.iteratorType === 0) { | ||
i.pre = function() { | ||
if (this.t.o === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
this.t = this.t.o; | ||
return this; | ||
}; | ||
i.next = function() { | ||
if (this.t === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
this.t = this.t.u; | ||
return this; | ||
}; | ||
} else { | ||
i.pre = function() { | ||
if (this.t.u === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
this.t = this.t.u; | ||
return this; | ||
}; | ||
i.next = function() { | ||
if (this.t === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
this.t = this.t.o; | ||
return this; | ||
}; | ||
} | ||
return i; | ||
} | ||
return HashContainerIterator; | ||
}(ContainerIterator); | ||
var HashContainer = function(t) { | ||
__extends(HashContainer, t); | ||
function HashContainer() { | ||
var e = t.call(this) || this; | ||
e.i = []; | ||
e.u = {}; | ||
e.HASH_KEY_TAG = Symbol("JS_SDSL_HASH_KEY_TAG"); | ||
Object.setPrototypeOf(e.u, null); | ||
return e; | ||
var r = t.call(this) || this; | ||
r.l = []; | ||
r.H = {}; | ||
r.HASH_TAG = Symbol("@@HASH_TAG"); | ||
Object.setPrototypeOf(r.H, null); | ||
r.h = {}; | ||
r.h.o = r.h.u = r.v = r.p = r.h; | ||
return r; | ||
} | ||
HashContainer.prototype.o = function(t, e, n) { | ||
HashContainer.prototype._ = function(t) { | ||
var r = t.o, n = t.u; | ||
r.u = n; | ||
n.o = r; | ||
if (t === this.v) { | ||
this.v = n; | ||
} | ||
if (t === this.p) { | ||
this.p = r; | ||
} | ||
this.i -= 1; | ||
}; | ||
HashContainer.prototype.I = function(t, r, n) { | ||
if (n === undefined) n = checkObject(t); | ||
var e; | ||
if (n) { | ||
var r = t[this.HASH_KEY_TAG]; | ||
if (r !== undefined) { | ||
this.i[r][1] = e; | ||
return; | ||
var i = t[this.HASH_TAG]; | ||
if (i !== undefined) { | ||
this.l[i].M = r; | ||
return this.i; | ||
} | ||
Object.defineProperty(t, this.HASH_KEY_TAG, { | ||
value: this.i.length, | ||
Object.defineProperty(t, this.HASH_TAG, { | ||
value: this.l.length, | ||
configurable: true | ||
}); | ||
this.i.push([ t, e ]); | ||
e = { | ||
C: t, | ||
M: r, | ||
o: this.p, | ||
u: this.h | ||
}; | ||
this.l.push(e); | ||
} else { | ||
var i = this.u[t]; | ||
if (i) { | ||
i[1] = e; | ||
return; | ||
var s = this.H[t]; | ||
if (s) { | ||
s.M = r; | ||
return this.i; | ||
} | ||
this.u[t] = [ t, e ]; | ||
e = { | ||
C: t, | ||
M: r, | ||
o: this.p, | ||
u: this.h | ||
}; | ||
this.H[t] = e; | ||
} | ||
this.t += 1; | ||
if (this.i === 0) { | ||
this.v = e; | ||
this.h.u = e; | ||
} else { | ||
this.p.u = e; | ||
} | ||
this.p = e; | ||
this.h.o = e; | ||
return ++this.i; | ||
}; | ||
HashContainer.prototype.g = function(t, r) { | ||
if (r === undefined) r = checkObject(t); | ||
if (r) { | ||
var n = t[this.HASH_TAG]; | ||
if (n === undefined) return this.h; | ||
return this.l[n]; | ||
} else { | ||
return this.H[t] || this.h; | ||
} | ||
}; | ||
HashContainer.prototype.clear = function() { | ||
var t = this; | ||
this.i.forEach((function(e) { | ||
delete e[0][t.HASH_KEY_TAG]; | ||
var t = this.HASH_TAG; | ||
this.l.forEach((function(r) { | ||
delete r.C[t]; | ||
})); | ||
this.i = []; | ||
this.u = {}; | ||
Object.setPrototypeOf(this.u, null); | ||
this.t = 0; | ||
this.l = []; | ||
this.H = {}; | ||
Object.setPrototypeOf(this.H, null); | ||
this.i = 0; | ||
this.v = this.p = this.h.o = this.h.u = this.h; | ||
}; | ||
HashContainer.prototype.eraseElementByKey = function(t, e) { | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
var n = t[this.HASH_KEY_TAG]; | ||
if (n === undefined) return; | ||
delete t[this.HASH_KEY_TAG]; | ||
delete this.i[n]; | ||
HashContainer.prototype.eraseElementByKey = function(t, r) { | ||
var n; | ||
if (r === undefined) r = checkObject(t); | ||
if (r) { | ||
var e = t[this.HASH_TAG]; | ||
if (e === undefined) return false; | ||
delete t[this.HASH_TAG]; | ||
n = this.l[e]; | ||
delete this.l[e]; | ||
} else { | ||
if (this.u[t] === undefined) return; | ||
delete this.u[t]; | ||
n = this.H[t]; | ||
if (n === undefined) return false; | ||
delete this.H[t]; | ||
} | ||
this.t -= 1; | ||
this._(n); | ||
return true; | ||
}; | ||
HashContainer.prototype.find = function(t, e) { | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
return typeof t[this.HASH_KEY_TAG] === "number"; | ||
} else { | ||
return this.u[t] !== undefined; | ||
HashContainer.prototype.eraseElementByIterator = function(t) { | ||
var r = t.t; | ||
if (r === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
this._(r); | ||
return t.next(); | ||
}; | ||
HashContainer.prototype.eraseElementByPos = function(t) { | ||
if (t < 0 || t > this.i - 1) { | ||
throw new RangeError; | ||
} | ||
var r = this.v; | ||
while (t--) { | ||
r = r.u; | ||
} | ||
this._(r); | ||
return this.i; | ||
}; | ||
return HashContainer; | ||
}(Base); | ||
}(Container); | ||
var HashMapIterator = function(t) { | ||
__extends(HashMapIterator, t); | ||
function HashMapIterator() { | ||
return t !== null && t.apply(this, arguments) || this; | ||
} | ||
Object.defineProperty(HashMapIterator.prototype, "pointer", { | ||
get: function() { | ||
if (this.t === this.h) { | ||
throwIteratorAccessError(); | ||
} | ||
var t = this; | ||
return new Proxy([], { | ||
get: function(r, n) { | ||
if (n === "0") return t.t.C; else if (n === "1") return t.t.M; | ||
}, | ||
set: function(r, n, e) { | ||
if (n !== "1") { | ||
throw new TypeError("props must be 1"); | ||
} | ||
t.t.M = e; | ||
return true; | ||
} | ||
}); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
HashMapIterator.prototype.copy = function() { | ||
return new HashMapIterator(this.t, this.h, this.iteratorType); | ||
}; | ||
return HashMapIterator; | ||
}(HashContainerIterator); | ||
var HashMap = function(t) { | ||
__extends(HashMap, t); | ||
function HashMap(e) { | ||
if (e === void 0) { | ||
e = []; | ||
function HashMap(r) { | ||
if (r === void 0) { | ||
r = []; | ||
} | ||
var n = t.call(this) || this; | ||
var r = n; | ||
e.forEach((function(t) { | ||
r.setElement(t[0], t[1]); | ||
var e = n; | ||
r.forEach((function(t) { | ||
e.setElement(t[0], t[1]); | ||
})); | ||
return n; | ||
} | ||
HashMap.prototype.setElement = function(t, e, n) { | ||
this.o(t, e, n); | ||
HashMap.prototype.begin = function() { | ||
return new HashMapIterator(this.v, this.h); | ||
}; | ||
HashMap.prototype.getElementByKey = function(t, e) { | ||
if (e === undefined) e = checkObject(t); | ||
if (e) { | ||
var n = t[this.HASH_KEY_TAG]; | ||
return n !== undefined ? this.i[n][1] : undefined; | ||
HashMap.prototype.end = function() { | ||
return new HashMapIterator(this.h, this.h); | ||
}; | ||
HashMap.prototype.rBegin = function() { | ||
return new HashMapIterator(this.p, this.h, 1); | ||
}; | ||
HashMap.prototype.rEnd = function() { | ||
return new HashMapIterator(this.h, this.h, 1); | ||
}; | ||
HashMap.prototype.front = function() { | ||
if (this.i === 0) return; | ||
return [ this.v.C, this.v.M ]; | ||
}; | ||
HashMap.prototype.back = function() { | ||
if (this.i === 0) return; | ||
return [ this.p.C, this.p.M ]; | ||
}; | ||
HashMap.prototype.setElement = function(t, r, n) { | ||
return this.I(t, r, n); | ||
}; | ||
HashMap.prototype.getElementByKey = function(t, r) { | ||
if (r === undefined) r = checkObject(t); | ||
if (r) { | ||
var n = t[this.HASH_TAG]; | ||
return n !== undefined ? this.l[n].M : undefined; | ||
} | ||
var r = this.u[t]; | ||
return r ? r[1] : undefined; | ||
var e = this.H[t]; | ||
return e ? e.M : undefined; | ||
}; | ||
HashMap.prototype.forEach = function(t) { | ||
var e = this.i.length; | ||
for (var n = 0; n < e; ++n) { | ||
t(this.i[n], n, this); | ||
HashMap.prototype.getElementByPos = function(t) { | ||
if (t < 0 || t > this.i - 1) { | ||
throw new RangeError; | ||
} | ||
var r = Object.keys(this.u); | ||
var i = r.length; | ||
var s = e; | ||
for (var n = 0; n < i; ++n) { | ||
t(this.u[r[n]], s++, this); | ||
var r = this.v; | ||
while (t--) { | ||
r = r.u; | ||
} | ||
var a = Object.getOwnPropertySymbols(this.u); | ||
var u = a.length; | ||
for (var n = 0; n < u; ++n) { | ||
t(this.u[a[n]], s++, this); | ||
return [ r.C, r.M ]; | ||
}; | ||
HashMap.prototype.find = function(t, r) { | ||
var n = this.g(t, r); | ||
return new HashMapIterator(n, this.h); | ||
}; | ||
HashMap.prototype.forEach = function(t) { | ||
var r = 0; | ||
var n = this.v; | ||
while (n !== this.h) { | ||
t([ n.C, n.M ], r++, this); | ||
n = n.u; | ||
} | ||
@@ -274,46 +443,19 @@ }; | ||
return function() { | ||
var t, e, n, r, i, n; | ||
return __generator(this, (function(s) { | ||
switch (s.label) { | ||
var t; | ||
return __generator(this, (function(r) { | ||
switch (r.label) { | ||
case 0: | ||
return [ 5, __values(this.i) ]; | ||
t = this.v; | ||
r.label = 1; | ||
case 1: | ||
s.sent(); | ||
t = Object.keys(this.u); | ||
e = t.length; | ||
n = 0; | ||
s.label = 2; | ||
if (!(t !== this.h)) return [ 3, 3 ]; | ||
return [ 4, [ t.C, t.M ] ]; | ||
case 2: | ||
if (!(n < e)) return [ 3, 5 ]; | ||
return [ 4, this.u[t[n]] ]; | ||
r.sent(); | ||
t = t.u; | ||
return [ 3, 1 ]; | ||
case 3: | ||
s.sent(); | ||
s.label = 4; | ||
case 4: | ||
++n; | ||
return [ 3, 2 ]; | ||
case 5: | ||
r = Object.getOwnPropertySymbols(this.u); | ||
i = r.length; | ||
n = 0; | ||
s.label = 6; | ||
case 6: | ||
if (!(n < i)) return [ 3, 9 ]; | ||
return [ 4, this.u[r[n]] ]; | ||
case 7: | ||
s.sent(); | ||
s.label = 8; | ||
case 8: | ||
++n; | ||
return [ 3, 6 ]; | ||
case 9: | ||
return [ 2 ]; | ||
@@ -320,0 +462,0 @@ } |
/*! | ||
* @js-sdsl/hash-map v4.2.0-beta.1 | ||
* @js-sdsl/hash-map v4.2.0 | ||
* https://github.com/js-sdsl/js-sdsl | ||
@@ -136,19 +136,24 @@ * (c) 2021-present ZLY201 <zilongyao1366@gmail.com> | ||
} | ||
function __values(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, | ||
m = s && o[s], | ||
i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { | ||
value: o && o[i++], | ||
done: !o | ||
}; | ||
var ContainerIterator = /** @class */function () { | ||
/** | ||
* @internal | ||
*/ | ||
function ContainerIterator(iteratorType) { | ||
if (iteratorType === void 0) { | ||
iteratorType = 0 /* IteratorType.NORMAL */; | ||
} | ||
this.iteratorType = iteratorType; | ||
} | ||
/** | ||
* @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; | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
} | ||
return ContainerIterator; | ||
}(); | ||
var Base = /** @class */function () { | ||
@@ -162,4 +167,17 @@ function Base() { | ||
} | ||
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 | ||
@@ -173,3 +191,3 @@ * const container = new Vector([1, 2]); | ||
/** | ||
* @return Boolean about if the container is empty. | ||
* @returns Whether the container is empty. | ||
* @example | ||
@@ -184,3 +202,3 @@ * container.clear(); | ||
}(); | ||
/** @class */(function (_super) { | ||
var Container = /** @class */function (_super) { | ||
__extends(Container, _super); | ||
@@ -191,18 +209,72 @@ function Container() { | ||
return Container; | ||
})(Base); | ||
}(Base); | ||
/** | ||
* @description Determine whether the type of key is `object`. | ||
* @param key The key want to check. | ||
* @return Boolean about whether the type of key is `object`. | ||
* @param key - The key want to check. | ||
* @returns Whether the type of key is `object`. | ||
* @internal | ||
*/ | ||
function checkObject(key) { | ||
if (key === null) return false; | ||
var t = typeof key; | ||
return t === 'object' || t === 'function'; | ||
return t === 'object' && key !== null || t === 'function'; | ||
} | ||
/** | ||
* @description Throw an iterator access error. | ||
* @internal | ||
*/ | ||
function throwIteratorAccessError() { | ||
throw new RangeError('Iterator access denied!'); | ||
} | ||
var HashContainerIterator = /** @class */function (_super) { | ||
__extends(HashContainerIterator, _super); | ||
/** | ||
* @internal | ||
*/ | ||
function HashContainerIterator(node, header, iteratorType) { | ||
var _this = _super.call(this, iteratorType) || this; | ||
_this._node = node; | ||
_this._header = header; | ||
if (_this.iteratorType === 0 /* IteratorType.NORMAL */) { | ||
_this.pre = function () { | ||
if (this._node._pre === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
this._node = this._node._pre; | ||
return this; | ||
}; | ||
_this.next = function () { | ||
if (this._node === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
this._node = this._node._next; | ||
return this; | ||
}; | ||
} else { | ||
_this.pre = function () { | ||
if (this._node._next === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
this._node = this._node._next; | ||
return this; | ||
}; | ||
_this.next = function () { | ||
if (this._node === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
this._node = this._node._pre; | ||
return this; | ||
}; | ||
} | ||
return _this; | ||
} | ||
return HashContainerIterator; | ||
}(ContainerIterator); | ||
var HashContainer = /** @class */function (_super) { | ||
__extends(HashContainer, _super); | ||
/** | ||
* @internal | ||
*/ | ||
function HashContainer() { | ||
@@ -219,6 +291,8 @@ var _this = _super.call(this) || this; | ||
/** | ||
* @internal | ||
* @description Unique symbol used to tag object. | ||
*/ | ||
_this.HASH_KEY_TAG = Symbol('JS_SDSL_HASH_KEY_TAG'); | ||
_this.HASH_TAG = Symbol('@@HASH_TAG'); | ||
Object.setPrototypeOf(_this._originMap, null); | ||
_this._header = {}; | ||
_this._header._pre = _this._header._next = _this._head = _this._tail = _this._header; | ||
return _this; | ||
@@ -229,29 +303,79 @@ } | ||
*/ | ||
HashContainer.prototype._eraseNode = function (node) { | ||
var _pre = node._pre, | ||
_next = node._next; | ||
_pre._next = _next; | ||
_next._pre = _pre; | ||
if (node === this._head) { | ||
this._head = _next; | ||
} | ||
if (node === this._tail) { | ||
this._tail = _pre; | ||
} | ||
this._length -= 1; | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
HashContainer.prototype._set = function (key, value, isObject) { | ||
if (isObject === undefined) isObject = checkObject(key); | ||
var newTail; | ||
if (isObject) { | ||
var index = key[this.HASH_KEY_TAG]; | ||
var index = key[this.HASH_TAG]; | ||
if (index !== undefined) { | ||
this._objMap[index][1] = value; | ||
return; | ||
this._objMap[index]._value = value; | ||
return this._length; | ||
} | ||
Object.defineProperty(key, this.HASH_KEY_TAG, { | ||
Object.defineProperty(key, this.HASH_TAG, { | ||
value: this._objMap.length, | ||
configurable: true | ||
}); | ||
this._objMap.push([key, value]); | ||
newTail = { | ||
_key: key, | ||
_value: value, | ||
_pre: this._tail, | ||
_next: this._header | ||
}; | ||
this._objMap.push(newTail); | ||
} else { | ||
var originValue = this._originMap[key]; | ||
if (originValue) { | ||
originValue[1] = value; | ||
return; | ||
var node = this._originMap[key]; | ||
if (node) { | ||
node._value = value; | ||
return this._length; | ||
} | ||
this._originMap[key] = [key, value]; | ||
newTail = { | ||
_key: key, | ||
_value: value, | ||
_pre: this._tail, | ||
_next: this._header | ||
}; | ||
this._originMap[key] = newTail; | ||
} | ||
this._length += 1; | ||
if (this._length === 0) { | ||
this._head = newTail; | ||
this._header._next = newTail; | ||
} else { | ||
this._tail._next = newTail; | ||
} | ||
this._tail = newTail; | ||
this._header._pre = newTail; | ||
return ++this._length; | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
HashContainer.prototype._findElementNode = function (key, isObject) { | ||
if (isObject === undefined) isObject = checkObject(key); | ||
if (isObject) { | ||
var index = key[this.HASH_TAG]; | ||
if (index === undefined) return this._header; | ||
return this._objMap[index]; | ||
} else { | ||
return this._originMap[key] || this._header; | ||
} | ||
}; | ||
HashContainer.prototype.clear = function () { | ||
var self = this; | ||
var HASH_TAG = this.HASH_TAG; | ||
this._objMap.forEach(function (el) { | ||
delete el[0][self.HASH_KEY_TAG]; | ||
delete el._key[HASH_TAG]; | ||
}); | ||
@@ -262,40 +386,82 @@ this._objMap = []; | ||
this._length = 0; | ||
this._head = this._tail = this._header._pre = this._header._next = this._header; | ||
}; | ||
/** | ||
* @description Remove the element of the specified key. | ||
* @param key The key you want to remove. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @param key - The key you want to remove. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns Whether erase successfully. | ||
*/ | ||
HashContainer.prototype.eraseElementByKey = function (key, isObject) { | ||
var node; | ||
if (isObject === undefined) isObject = checkObject(key); | ||
if (isObject) { | ||
var index = key[this.HASH_KEY_TAG]; | ||
if (index === undefined) return; | ||
delete key[this.HASH_KEY_TAG]; | ||
var index = key[this.HASH_TAG]; | ||
if (index === undefined) return false; | ||
delete key[this.HASH_TAG]; | ||
node = this._objMap[index]; | ||
delete this._objMap[index]; | ||
} else { | ||
if (this._originMap[key] === undefined) return; | ||
node = this._originMap[key]; | ||
if (node === undefined) return false; | ||
delete this._originMap[key]; | ||
} | ||
this._length -= 1; | ||
this._eraseNode(node); | ||
return true; | ||
}; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key The element you want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @return Boolean about if key exist in container. | ||
*/ | ||
HashContainer.prototype.find = function (key, isObject) { | ||
if (isObject === undefined) isObject = checkObject(key); | ||
if (isObject) { | ||
return typeof key[this.HASH_KEY_TAG] === 'number'; | ||
} else { | ||
return this._originMap[key] !== undefined; | ||
HashContainer.prototype.eraseElementByIterator = function (iter) { | ||
var node = iter._node; | ||
if (node === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
this._eraseNode(node); | ||
return iter.next(); | ||
}; | ||
HashContainer.prototype.eraseElementByPos = function (pos) { | ||
if (pos < 0 || pos > this._length - 1) { | ||
throw new RangeError(); | ||
} | ||
var node = this._head; | ||
while (pos--) { | ||
node = node._next; | ||
} | ||
this._eraseNode(node); | ||
return this._length; | ||
}; | ||
return HashContainer; | ||
}(Base); | ||
}(Container); | ||
var HashMapIterator = /** @class */function (_super) { | ||
__extends(HashMapIterator, _super); | ||
function HashMapIterator() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Object.defineProperty(HashMapIterator.prototype, "pointer", { | ||
get: function () { | ||
if (this._node === this._header) { | ||
throwIteratorAccessError(); | ||
} | ||
var self = this; | ||
return new Proxy([], { | ||
get: function (_, props) { | ||
if (props === '0') return self._node._key;else if (props === '1') return self._node._value; | ||
}, | ||
set: function (_, props, newValue) { | ||
if (props !== '1') { | ||
throw new TypeError('props must be 1'); | ||
} | ||
self._node._value = newValue; | ||
return true; | ||
} | ||
}); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
HashMapIterator.prototype.copy = function () { | ||
return new HashMapIterator(this._node, this._header, this.iteratorType); | ||
}; | ||
return HashMapIterator; | ||
}(HashContainerIterator); | ||
var HashMap = /** @class */function (_super) { | ||
@@ -314,18 +480,49 @@ __extends(HashMap, _super); | ||
} | ||
HashMap.prototype.begin = function () { | ||
return new HashMapIterator(this._head, this._header); | ||
}; | ||
HashMap.prototype.end = function () { | ||
return new HashMapIterator(this._header, this._header); | ||
}; | ||
HashMap.prototype.rBegin = function () { | ||
return new HashMapIterator(this._tail, this._header, 1 /* IteratorType.REVERSE */); | ||
}; | ||
HashMap.prototype.rEnd = function () { | ||
return new HashMapIterator(this._header, this._header, 1 /* IteratorType.REVERSE */); | ||
}; | ||
HashMap.prototype.front = function () { | ||
if (this._length === 0) return; | ||
return [this._head._key, this._head._value]; | ||
}; | ||
HashMap.prototype.back = function () { | ||
if (this._length === 0) return; | ||
return [this._tail._key, this._tail._value]; | ||
}; | ||
/** | ||
* @description Insert a key-value pair or set value by the given key. | ||
* @param key The key want to insert. | ||
* @param value The value want to set. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @param key - The key want to insert. | ||
* @param value - The value want to set. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns The size of container after setting. | ||
*/ | ||
HashMap.prototype.setElement = function (key, value, isObject) { | ||
this._set(key, value, isObject); | ||
return this._set(key, value, isObject); | ||
}; | ||
/** | ||
* @description Check key if exist in container. | ||
* @param key - The element you want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @returns An iterator pointing to the element if found, or super end if not found. | ||
*/ | ||
/** | ||
* @description Get the value of the element of the specified key. | ||
* @param key The key want to search. | ||
* @param isObject Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example const val = container.getElementByKey(1); | ||
* @param key - The key want to search. | ||
* @param isObject - Tell us if the type of inserted key is `object` to improve efficiency.<br/> | ||
* If a `undefined` value is passed in, the type will be automatically judged. | ||
* @example | ||
* const val = container.getElementByKey(1); | ||
*/ | ||
@@ -335,23 +532,28 @@ HashMap.prototype.getElementByKey = function (key, isObject) { | ||
if (isObject) { | ||
var index = key[this.HASH_KEY_TAG]; | ||
return index !== undefined ? this._objMap[index][1] : undefined; | ||
var index = key[this.HASH_TAG]; | ||
return index !== undefined ? this._objMap[index]._value : undefined; | ||
} | ||
var value = this._originMap[key]; | ||
return value ? value[1] : undefined; | ||
var node = this._originMap[key]; | ||
return node ? node._value : undefined; | ||
}; | ||
HashMap.prototype.forEach = function (callback) { | ||
var objMapLength = this._objMap.length; | ||
for (var i = 0; i < objMapLength; ++i) { | ||
callback(this._objMap[i], i, this); | ||
HashMap.prototype.getElementByPos = function (pos) { | ||
if (pos < 0 || pos > this._length - 1) { | ||
throw new RangeError(); | ||
} | ||
var keys = Object.keys(this._originMap); | ||
var originMapLength = keys.length; | ||
var index = objMapLength; | ||
for (var i = 0; i < originMapLength; ++i) { | ||
callback(this._originMap[keys[i]], index++, this); | ||
var node = this._head; | ||
while (pos--) { | ||
node = node._next; | ||
} | ||
var symbols = Object.getOwnPropertySymbols(this._originMap); | ||
var symbolsLength = symbols.length; | ||
for (var i = 0; i < symbolsLength; ++i) { | ||
callback(this._originMap[symbols[i]], index++, this); | ||
return [node._key, node._value]; | ||
}; | ||
HashMap.prototype.find = function (key, isObject) { | ||
var node = this._findElementNode(key, isObject); | ||
return new HashMapIterator(node, this._header); | ||
}; | ||
HashMap.prototype.forEach = function (callback) { | ||
var index = 0; | ||
var node = this._head; | ||
while (node !== this._header) { | ||
callback([node._key, node._value], index++, this); | ||
node = node._next; | ||
} | ||
@@ -361,37 +563,16 @@ }; | ||
return function () { | ||
var keys, originMapLength, i, symbols, symbolsLength, i; | ||
var node; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
return [5 /*yield**/, __values(this._objMap)]; | ||
node = this._head; | ||
_a.label = 1; | ||
case 1: | ||
if (!(node !== this._header)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, [node._key, node._value]]; | ||
case 2: | ||
_a.sent(); | ||
keys = Object.keys(this._originMap); | ||
originMapLength = keys.length; | ||
i = 0; | ||
_a.label = 2; | ||
case 2: | ||
if (!(i < originMapLength)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this._originMap[keys[i]]]; | ||
node = node._next; | ||
return [3 /*break*/, 1]; | ||
case 3: | ||
_a.sent(); | ||
_a.label = 4; | ||
case 4: | ||
++i; | ||
return [3 /*break*/, 2]; | ||
case 5: | ||
symbols = Object.getOwnPropertySymbols(this._originMap); | ||
symbolsLength = symbols.length; | ||
i = 0; | ||
_a.label = 6; | ||
case 6: | ||
if (!(i < symbolsLength)) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, this._originMap[symbols[i]]]; | ||
case 7: | ||
_a.sent(); | ||
_a.label = 8; | ||
case 8: | ||
++i; | ||
return [3 /*break*/, 6]; | ||
case 9: | ||
return [2 /*return*/]; | ||
@@ -398,0 +579,0 @@ } |
/*! | ||
* @js-sdsl/hash-map v4.2.0-beta.1 | ||
* @js-sdsl/hash-map 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 o=function(t,e){return(o=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}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function s(o,r){var i,s,u,l={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]},c={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function t(n){return function(t){var e=[n,t];if(i)throw new TypeError("Generator is already executing.");for(;l=c&&e[c=0]?0:l;)try{if(i=1,s&&(u=2&e[0]?s.return:e[0]?s.throw||((u=s.return)&&u.call(s),0):s.next)&&!(u=u.call(s,e[1])).done)return u;switch(s=0,(e=u?[2&e[0],u.value]:e)[0]){case 0:case 1:u=e;break;case 4:return l.label++,{value:e[1],done:!1};case 5:l.label++,s=e[1],e=[0];continue;case 7:e=l.ops.pop(),l.trys.pop();continue;default:if(!(u=0<(u=l.trys).length&&u[u.length-1])&&(6===e[0]||2===e[0])){l=0;continue}if(3===e[0]&&(!u||e[1]>u[0]&&e[1]<u[3]))l.label=e[1];else if(6===e[0]&&l.label<u[1])l.label=u[1],u=e;else{if(!(u&&l.label<u[2])){u[2]&&l.ops.pop(),l.trys.pop();continue}l.label=u[2],l.ops.push(e)}}e=r.call(o,l)}catch(t){e=[6,t],s=0}finally{i=u=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}i.prototype.size=function(){return this.t},i.prototype.empty=function(){return 0===this.t};var n,r=i;function i(){this.t=0}function u(){return null!==n&&n.apply(this,arguments)||this}function l(t){return null!==t&&("object"==(t=typeof t)||"function"==t)}e(u,n=r);e(f,c=r),f.prototype.o=function(t,e,n){if(n=void 0===n?l(t):n){n=t[this.HASH_KEY_TAG];if(void 0!==n)return void(this.i[n][1]=e);Object.defineProperty(t,this.HASH_KEY_TAG,{value:this.i.length,configurable:!0}),this.i.push([t,e])}else{n=this.u[t];if(n)return void(n[1]=e);this.u[t]=[t,e]}this.t+=1},f.prototype.clear=function(){var e=this;this.i.forEach(function(t){delete t[0][e.HASH_KEY_TAG]}),this.i=[],this.u={},Object.setPrototypeOf(this.u,null),this.t=0},f.prototype.eraseElementByKey=function(t,e){if(e=void 0===e?l(t):e){e=t[this.HASH_KEY_TAG];if(void 0===e)return;delete t[this.HASH_KEY_TAG],delete this.i[e]}else{if(void 0===this.u[t])return;delete this.u[t]}--this.t},f.prototype.find=function(t,e){return(e=void 0===e?l(t):e)?"number"==typeof t[this.HASH_KEY_TAG]:void 0!==this.u[t]};var c,r=f;function f(){var t=c.call(this)||this;return t.i=[],t.u={},t.HASH_KEY_TAG=Symbol("JS_SDSL_HASH_KEY_TAG"),Object.setPrototypeOf(t.u,null),t}e(h,a=r),h.prototype.setElement=function(t,e,n){this.o(t,e,n)},h.prototype.getElementByKey=function(t,e){return(e=void 0===e?l(t):e)?void 0!==(e=t[this.HASH_KEY_TAG])?this.i[e][1]:void 0:(e=this.u[t])?e[1]:void 0},h.prototype.forEach=function(t){for(var e=this.i.length,n=0;n<e;++n)t(this.i[n],n,this);for(var o=Object.keys(this.u),r=o.length,i=e,n=0;n<r;++n)t(this.u[o[n]],i++,this);for(var s=Object.getOwnPropertySymbols(this.u),u=s.length,n=0;n<u;++n)t(this.u[s[n]],i++,this)},h.prototype[Symbol.iterator]=function(){return function(){var e,n,o,r,i;return s(this,function(t){switch(t.label){case 0:return[5,function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&o>=t.length?void 0:t)&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.i)];case 1:t.sent(),e=Object.keys(this.u),n=e.length,i=0,t.label=2;case 2:return i<n?[4,this.u[e[i]]]:[3,5];case 3:t.sent(),t.label=4;case 4:return++i,[3,2];case 5:o=Object.getOwnPropertySymbols(this.u),r=o.length,i=0,t.label=6;case 6:return i<r?[4,this.u[o[i]]]:[3,9];case 7:t.sent(),t.label=8;case 8:return++i,[3,6];case 9:return[2]}})}.bind(this)()};var a,r=h;function h(t){void 0===t&&(t=[]);var e=a.call(this)||this,n=e;return t.forEach(function(t){n.setElement(t[0],t[1])}),e}t.HashMap=r,Object.defineProperty(t,"h",{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 n=function(t,e){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}))(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 i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}function i(n,r){var o,s,h,u={label:0,sent:function(){if(1&h[0])throw h[1];return h[1]},trys:[],ops:[]},p={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(p[Symbol.iterator]=function(){return this}),p;function t(i){return function(t){var e=[i,t];if(o)throw new TypeError("Generator is already executing.");for(;u=p&&e[p=0]?0:u;)try{if(o=1,s&&(h=2&e[0]?s.return:e[0]?s.throw||((h=s.return)&&h.call(s),0):s.next)&&!(h=h.call(s,e[1])).done)return h;switch(s=0,(e=h?[2&e[0],h.value]:e)[0]){case 0:case 1:h=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(!(h=0<(h=u.trys).length&&h[h.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!h||e[1]>h[0]&&e[1]<h[3]))u.label=e[1];else if(6===e[0]&&u.label<h[1])u.label=h[1],h=e;else{if(!(h&&u.label<h[2])){h[2]&&u.ops.pop(),u.trys.pop();continue}u.label=h[2],u.ops.push(e)}}e=r.call(n,u)}catch(t){e=[6,t],s=0}finally{o=h=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}o.prototype.equals=function(t){return this.t===t.t};var r=o;function o(t){this.iteratorType=t=void 0===t?0:t}function s(){this.i=0}Object.defineProperty(s.prototype,"length",{get:function(){return this.i},enumerable:!1,configurable:!0}),s.prototype.size=function(){return this.i},s.prototype.empty=function(){return 0===this.i};e(p,h=s);var h,u=p;function p(){return null!==h&&h.apply(this,arguments)||this}function f(t){var e=typeof t;return"object"==e&&null!==t||"function"==e}function c(){throw new RangeError("Iterator access denied!")}e(a,l=r);var l,r=a;function a(t,e,i){i=l.call(this,i)||this;return i.t=t,i.h=e,0===i.iteratorType?(i.pre=function(){return this.t.u===this.h&&c(),this.t=this.t.u,this},i.next=function(){return this.t===this.h&&c(),this.t=this.t.o,this}):(i.pre=function(){return this.t.o===this.h&&c(),this.t=this.t.o,this},i.next=function(){return this.t===this.h&&c(),this.t=this.t.u,this}),i}e(v,y=u),v.prototype.H=function(t){var e=t.u,i=t.o;(e.o=i).u=e,t===this.p&&(this.p=i),t===this._&&(this._=e),--this.i},v.prototype.M=function(t,e,i){var n;if(i=void 0===i?f(t):i){i=t[this.HASH_TAG];if(void 0!==i)return this.l[i].C=e,this.i;Object.defineProperty(t,this.HASH_TAG,{value:this.l.length,configurable:!0}),n={I:t,C:e,u:this._,o:this.h},this.l.push(n)}else{i=this.v[t];if(i)return i.C=e,this.i;n={I:t,C:e,u:this._,o:this.h},this.v[t]=n}return 0===this.i?(this.p=n,this.h.o=n):this._.o=n,this._=n,this.h.u=n,++this.i},v.prototype.g=function(t,e){return(e=void 0===e?f(t):e)?void 0===(e=t[this.HASH_TAG])?this.h:this.l[e]:this.v[t]||this.h},v.prototype.clear=function(){var e=this.HASH_TAG;this.l.forEach(function(t){delete t.I[e]}),this.l=[],this.v={},Object.setPrototypeOf(this.v,null),this.i=0,this.p=this._=this.h.u=this.h.o=this.h},v.prototype.eraseElementByKey=function(t,e){var i;if(e=void 0===e?f(t):e){e=t[this.HASH_TAG];if(void 0===e)return!1;delete t[this.HASH_TAG],i=this.l[e],delete this.l[e]}else{if(void 0===(i=this.v[t]))return!1;delete this.v[t]}return this.H(i),!0},v.prototype.eraseElementByIterator=function(t){var e=t.t;return e===this.h&&c(),this.H(e),t.next()},v.prototype.eraseElementByPos=function(t){if(t<0||t>this.i-1)throw new RangeError;for(var e=this.p;t--;)e=e.o;return this.H(e),this.i};var y,u=v;function v(){var t=y.call(this)||this;return t.l=[],t.v={},t.HASH_TAG=Symbol("@@HASH_TAG"),Object.setPrototypeOf(t.v,null),t.h={},t.h.u=t.h.o=t.p=t._=t.h,t}e(_,d=r),Object.defineProperty(_.prototype,"pointer",{get:function(){this.t===this.h&&c();var n=this;return new Proxy([],{get:function(t,e){return"0"===e?n.t.I:"1"===e?n.t.C:void 0},set:function(t,e,i){if("1"!==e)throw new TypeError("props must be 1");return n.t.C=i,!0}})},enumerable:!1,configurable:!0}),_.prototype.copy=function(){return new _(this.t,this.h,this.iteratorType)};var d,b=_;function _(){return null!==d&&d.apply(this,arguments)||this}e(g,w=u),g.prototype.begin=function(){return new b(this.p,this.h)},g.prototype.end=function(){return new b(this.h,this.h)},g.prototype.rBegin=function(){return new b(this._,this.h,1)},g.prototype.rEnd=function(){return new b(this.h,this.h,1)},g.prototype.front=function(){if(0!==this.i)return[this.p.I,this.p.C]},g.prototype.back=function(){if(0!==this.i)return[this._.I,this._.C]},g.prototype.setElement=function(t,e,i){return this.M(t,e,i)},g.prototype.getElementByKey=function(t,e){return(e=void 0===e?f(t):e)?void 0!==(e=t[this.HASH_TAG])?this.l[e].C:void 0:(e=this.v[t])?e.C:void 0},g.prototype.getElementByPos=function(t){if(t<0||t>this.i-1)throw new RangeError;for(var e=this.p;t--;)e=e.o;return[e.I,e.C]},g.prototype.find=function(t,e){t=this.g(t,e);return new b(t,this.h)},g.prototype.forEach=function(t){for(var e=0,i=this.p;i!==this.h;)t([i.I,i.C],e++,this),i=i.o},g.prototype[Symbol.iterator]=function(){return function(){var e;return i(this,function(t){switch(t.label){case 0:e=this.p,t.label=1;case 1:return e===this.h?[3,3]:[4,[e.I,e.C]];case 2:return t.sent(),e=e.o,[3,1];case 3:return[2]}})}.bind(this)()};var w,r=g;function g(t){void 0===t&&(t=[]);var e=w.call(this)||this,i=e;return t.forEach(function(t){i.setElement(t[0],t[1])}),e}t.HashMap=r,Object.defineProperty(t,"j",{value:!0})}); | ||
//# sourceMappingURL=hash-map.min.js.map |
{ | ||
"name": "@js-sdsl/hash-map", | ||
"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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
215356
1931
0