🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@js-sdsl/ordered-map

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-sdsl/ordered-map - npm Package Compare versions

Comparing version

to
4.2.0-beta.0

dist/cjs/index.js.map

337

dist/cjs/index.d.ts

@@ -1,4 +0,333 @@

export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
export type { OrderedMapIterator } from "./container/TreeContainer/OrderedMap";
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase";
export type { default as TreeContainer } from "./container/TreeContainer/Base";
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;
protected constructor(iteratorType?: IteratorType);
/**
* @description Pointers to element.
* @return 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.
* @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.
* @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;
/**
* @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.
* @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.
* @example
* const container = new Vector([1, 2]);
* console.log(container.size()); // 2
*/
size(): number;
/**
* @return Boolean about if the container is empty.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
empty(): boolean;
/**
* @description Clear the container.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
abstract clear(): void;
}
declare abstract class Container<T> extends Base {
/**
* @return 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);
* }
*/
abstract begin(): ContainerIterator<T>;
/**
* @return 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);
* }
*/
abstract end(): ContainerIterator<T>;
/**
* @return 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>;
/**
* @return 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>;
/**
* @return The first element of the container.
*/
abstract front(): T | undefined;
/**
* @return The last element of the container.
*/
abstract back(): T | undefined;
/**
* @description Iterate over all elements in the container.
* @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.
* @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.
* container.eraseElementByPos(-1); // throw a RangeError
*/
abstract eraseElementByPos(pos: number): void;
/**
* @description Removes element by iterator and move `iter` to next.
* @param iter The iterator you want to erase.
* @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.
* @example
* for (const element of container) {
* console.log(element);
* }
*/
abstract [Symbol.iterator](): Generator<T, void, undefined>;
}
type initContainer<T> = ({
size: number;
} | {
length: number;
} | {
size(): number;
}) & {
forEach(callback: (element: T) => void): void;
};
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [
K,
V
]> {
pre: () => this;
next: () => this;
/**
* @description Get the sequential index of the iterator in the tree container.<br/>
* <strong>
* Note:
* </strong>
* This function only takes effect when the specified tree container `enableIndex = true`.
* @example
* const st = new OrderedSet([1, 2, 3], true);
* console.log(st.begin().next().index); // 1
*/
get index(): number;
equals(obj: TreeIterator<K, V>): boolean;
}
declare abstract class TreeContainer<K, V> extends Container<K | [
K,
V
]> {
/**
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
*/
protected constructor(cmp?: (x: K, y: K) => number, enableIndex?: boolean);
/**
* @param key The given key you want to compare.
* @return An iterator to the first element not less than the given key.
*/
abstract lowerBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element greater than the given key.
*/
abstract upperBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element not greater than the given key.
*/
abstract reverseLowerBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element less than the given key.
*/
abstract reverseUpperBound(key: K): TreeIterator<K, V>;
/**
* @description Union the other tree to self.
* @param other The other tree container you want to merge.
*/
abstract union(other: TreeContainer<K, V>): void;
clear(): void;
/**
* @description Update node's key by iterator.
* @param iter The iterator you want to change.
* @param key The key you want to update.
* @return Boolean about if the modification is successful.
* @example
* const st = new orderedSet([1, 2, 5]);
* const iter = st.find(2);
* st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
*/
updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
eraseElementByPos(pos: number): void;
/**
* @description Remove the element of the specified _key.
* @param key The _key you want to remove.
*/
eraseElementByKey(key: K): void;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
/**
* @description Get the height of the tree.
* @return Number about the height of the RB-tree.
*/
getHeight(): number;
}
declare class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
get pointer(): [
K,
V
];
copy(): OrderedMapIterator<K, V>;
}
declare class OrderedMap<K, V> extends TreeContainer<K, V> {
/**
* @param container The initialization container.
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
* @example
* new OrderedMap();
* new OrderedMap([[0, 1], [2, 1]]);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y, true);
*/
constructor(container?: initContainer<[
K,
V
]>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedMapIterator<K, V>;
end(): OrderedMapIterator<K, V>;
rBegin(): OrderedMapIterator<K, V>;
rEnd(): OrderedMapIterator<K, V>;
front(): [
K,
V
] | undefined;
back(): [
K,
V
] | undefined;
forEach(callback: (element: [
K,
V
], index: number, map: OrderedMap<K, V>) => void): void;
lowerBound(key: K): OrderedMapIterator<K, V>;
upperBound(key: K): OrderedMapIterator<K, V>;
reverseLowerBound(key: K): OrderedMapIterator<K, V>;
reverseUpperBound(key: K): OrderedMapIterator<K, V>;
/**
* @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 hint You can give an iterator hint to improve insertion efficiency.
* @example
* const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
* const iter = mp.begin();
* mp.setElement(1, 0);
* mp.setElement(3, 0, iter); // give a hint will be faster.
*/
setElement(key: K, value: V, hint?: OrderedMapIterator<K, V>): void;
find(key: K): OrderedMapIterator<K, V>;
/**
* @description Get the value of the element of the specified key.
* @example const val = container.getElementByKey(1);
*/
getElementByKey(key: K): V | undefined;
getElementByPos(pos: number): [
K,
V
];
union(other: OrderedMap<K, V>): void;
[Symbol.iterator](): Generator<[
K,
V
], void, undefined>;
}
export { OrderedMap };
export type { OrderedMapIterator, IteratorType, Container, ContainerIterator, TreeContainer };

@@ -7,15 +7,773 @@ "use strict";

Object.defineProperty(exports, "OrderedMap", {
enumerable: true,
get: function() {
return _OrderedMap.default;
class ContainerIterator {
constructor(e = 0) {
this.iteratorType = e;
}
});
}
var _OrderedMap = _interopRequireDefault(require("./container/TreeContainer/OrderedMap"));
class Base {
constructor() {
this.i = 0;
}
size() {
return this.i;
}
empty() {
return this.i === 0;
}
}
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
class Container extends Base {}
class TreeNode {
constructor(e, t) {
this.h = 1;
this.u = undefined;
this.o = undefined;
this.l = undefined;
this.p = undefined;
this.g = undefined;
this.u = e;
this.o = t;
}
pre() {
let e = this;
if (e.h === 1 && e.g.g === e) {
e = e.p;
} else if (e.l) {
e = e.l;
while (e.p) {
e = e.p;
}
} else {
let t = e.g;
while (t.l === e) {
e = t;
t = e.g;
}
e = t;
}
return e;
}
next() {
let e = this;
if (e.p) {
e = e.p;
while (e.l) {
e = e.l;
}
return e;
} else {
let t = e.g;
while (t.p === e) {
e = t;
t = e.g;
}
if (e.p !== t) {
return t;
} else return e;
}
}
rotateLeft() {
const e = this.g;
const t = this.p;
const i = t.l;
if (e.g === this) e.g = t; else if (e.l === this) e.l = t; else e.p = t;
t.g = e;
t.l = this;
this.g = t;
this.p = i;
if (i) i.g = this;
return t;
}
rotateRight() {
const e = this.g;
const t = this.l;
const i = t.p;
if (e.g === this) e.g = t; else if (e.l === this) e.l = t; else e.p = t;
t.g = e;
t.p = this;
this.g = t;
this.l = i;
if (i) i.g = this;
return t;
}
}
class TreeNodeEnableIndex extends TreeNode {
constructor() {
super(...arguments);
this.l = undefined;
this.p = undefined;
this.g = undefined;
this.I = 1;
}
rotateLeft() {
const e = super.rotateLeft();
this.recount();
e.recount();
return e;
}
rotateRight() {
const e = super.rotateRight();
this.recount();
e.recount();
return e;
}
recount() {
this.I = 1;
if (this.l) this.I += this.l.I;
if (this.p) this.I += this.p.I;
}
}
class TreeContainer extends Container {
constructor(e = ((e, t) => {
if (e < t) return -1;
if (e > t) return 1;
return 0;
}), t = false) {
super();
this.B = undefined;
this.M = (e, t) => {
if (e === undefined) return false;
const i = this.M(e.l, t);
if (i) return true;
if (t(e)) return true;
return this.M(e.p, t);
};
this.N = e;
if (t) {
this.O = TreeNodeEnableIndex;
this.T = function(e, t, i) {
const s = this._(e, t, i);
if (s) {
let e = s.g;
while (e !== this.m) {
e.I += 1;
e = e.g;
}
const t = this.R(s);
if (t) {
const {parentNode: e, grandParent: i, curNode: s} = t;
e.recount();
i.recount();
s.recount();
}
}
};
this.v = function(e) {
let t = this.C(e);
while (t !== this.m) {
t.I -= 1;
t = t.g;
}
};
} else {
this.O = TreeNode;
this.T = function(e, t, i) {
const s = this._(e, t, i);
if (s) this.R(s);
};
this.v = this.C;
}
this.m = new this.O;
}
P(e, t) {
let i;
while (e) {
const s = this.N(e.u, t);
if (s < 0) {
e = e.p;
} else if (s > 0) {
i = e;
e = e.l;
} else return e;
}
return i === undefined ? this.m : i;
}
k(e, t) {
let i;
while (e) {
const s = this.N(e.u, t);
if (s <= 0) {
e = e.p;
} else {
i = e;
e = e.l;
}
}
return i === undefined ? this.m : i;
}
L(e, t) {
let i;
while (e) {
const s = this.N(e.u, t);
if (s < 0) {
i = e;
e = e.p;
} else if (s > 0) {
e = e.l;
} else return e;
}
return i === undefined ? this.m : i;
}
S(e, t) {
let i;
while (e) {
const s = this.N(e.u, t);
if (s < 0) {
i = e;
e = e.p;
} else {
e = e.l;
}
}
return i === undefined ? this.m : i;
}
K(e) {
while (true) {
const t = e.g;
if (t === this.m) return;
if (e.h === 1) {
e.h = 0;
return;
}
if (e === t.l) {
const i = t.p;
if (i.h === 1) {
i.h = 0;
t.h = 1;
if (t === this.B) {
this.B = t.rotateLeft();
} else t.rotateLeft();
} else {
if (i.p && i.p.h === 1) {
i.h = t.h;
t.h = 0;
i.p.h = 0;
if (t === this.B) {
this.B = t.rotateLeft();
} else t.rotateLeft();
return;
} else if (i.l && i.l.h === 1) {
i.h = 1;
i.l.h = 0;
i.rotateRight();
} else {
i.h = 1;
e = t;
}
}
} else {
const i = t.l;
if (i.h === 1) {
i.h = 0;
t.h = 1;
if (t === this.B) {
this.B = t.rotateRight();
} else t.rotateRight();
} else {
if (i.l && i.l.h === 1) {
i.h = t.h;
t.h = 0;
i.l.h = 0;
if (t === this.B) {
this.B = t.rotateRight();
} else t.rotateRight();
return;
} else if (i.p && i.p.h === 1) {
i.h = 1;
i.p.h = 0;
i.rotateLeft();
} else {
i.h = 1;
e = t;
}
}
}
}
}
C(e) {
if (this.i === 1) {
this.clear();
return this.m;
}
let t = e;
while (t.l || t.p) {
if (t.p) {
t = t.p;
while (t.l) t = t.l;
} else {
t = t.l;
}
[e.u, t.u] = [ t.u, e.u ];
[e.o, t.o] = [ t.o, e.o ];
e = t;
}
if (this.m.l === t) {
this.m.l = t.g;
} else if (this.m.p === t) {
this.m.p = t.g;
}
this.K(t);
const i = t.g;
if (t === i.l) {
i.l = undefined;
} else i.p = undefined;
this.i -= 1;
this.B.h = 0;
return i;
}
R(e) {
while (true) {
const t = e.g;
if (t.h === 0) return;
const i = t.g;
if (t === i.l) {
const s = i.p;
if (s && s.h === 1) {
s.h = t.h = 0;
if (i === this.B) return;
i.h = 1;
e = i;
continue;
} else if (e === t.p) {
e.h = 0;
if (e.l) e.l.g = t;
if (e.p) e.p.g = i;
t.p = e.l;
i.l = e.p;
e.l = t;
e.p = i;
if (i === this.B) {
this.B = e;
this.m.g = e;
} else {
const t = i.g;
if (t.l === i) {
t.l = e;
} else t.p = e;
}
e.g = i.g;
t.g = e;
i.g = e;
i.h = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.h = 0;
if (i === this.B) {
this.B = i.rotateRight();
} else i.rotateRight();
i.h = 1;
}
} else {
const s = i.l;
if (s && s.h === 1) {
s.h = t.h = 0;
if (i === this.B) return;
i.h = 1;
e = i;
continue;
} else if (e === t.l) {
e.h = 0;
if (e.l) e.l.g = i;
if (e.p) e.p.g = t;
i.p = e.l;
t.l = e.p;
e.l = i;
e.p = t;
if (i === this.B) {
this.B = e;
this.m.g = e;
} else {
const t = i.g;
if (t.l === i) {
t.l = e;
} else t.p = e;
}
e.g = i.g;
t.g = e;
i.g = e;
i.h = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.h = 0;
if (i === this.B) {
this.B = i.rotateLeft();
} else i.rotateLeft();
i.h = 1;
}
}
return;
}
}
_(e, t, i) {
if (this.B === undefined) {
this.i += 1;
this.B = new this.O(e, t);
this.B.h = 0;
this.B.g = this.m;
this.m.g = this.B;
this.m.l = this.B;
this.m.p = this.B;
return;
}
let s;
const r = this.m.l;
const n = this.N(r.u, e);
if (n === 0) {
r.o = t;
return;
} else if (n > 0) {
r.l = new this.O(e, t);
r.l.g = r;
s = r.l;
this.m.l = s;
} else {
const r = this.m.p;
const n = this.N(r.u, e);
if (n === 0) {
r.o = t;
return;
} else if (n < 0) {
r.p = new this.O(e, t);
r.p.g = r;
s = r.p;
this.m.p = s;
} else {
if (i !== undefined) {
const r = i.U;
if (r !== this.m) {
const i = this.N(r.u, e);
if (i === 0) {
r.o = t;
return;
} else if (i > 0) {
const i = r.pre();
const n = this.N(i.u, e);
if (n === 0) {
i.o = t;
return;
} else if (n < 0) {
s = new this.O(e, t);
if (i.p === undefined) {
i.p = s;
s.g = i;
} else {
r.l = s;
s.g = r;
}
}
}
}
}
if (s === undefined) {
s = this.B;
while (true) {
const i = this.N(s.u, e);
if (i > 0) {
if (s.l === undefined) {
s.l = new this.O(e, t);
s.l.g = s;
s = s.l;
break;
}
s = s.l;
} else if (i < 0) {
if (s.p === undefined) {
s.p = new this.O(e, t);
s.p.g = s;
s = s.p;
break;
}
s = s.p;
} else {
s.o = t;
return;
}
}
}
}
}
this.i += 1;
return s;
}
clear() {
this.i = 0;
this.B = undefined;
this.m.g = undefined;
this.m.l = this.m.p = undefined;
}
updateKeyByIterator(e, t) {
const i = e.U;
if (i === this.m) {
throw new TypeError("Invalid iterator!");
}
if (this.i === 1) {
i.u = t;
return true;
}
if (i === this.m.l) {
if (this.N(i.next().u, t) > 0) {
i.u = t;
return true;
}
return false;
}
if (i === this.m.p) {
if (this.N(i.pre().u, t) < 0) {
i.u = t;
return true;
}
return false;
}
const s = i.pre().u;
if (this.N(s, t) >= 0) return false;
const r = i.next().u;
if (this.N(r, t) <= 0) return false;
i.u = t;
return true;
}
eraseElementByPos(e) {
if (e < 0 || e > this.i - 1) {
throw new RangeError;
}
let t = 0;
this.M(this.B, (i => {
if (e === t) {
this.v(i);
return true;
}
t += 1;
return false;
}));
}
j(e, t) {
while (e) {
const i = this.N(e.u, t);
if (i < 0) {
e = e.p;
} else if (i > 0) {
e = e.l;
} else return e;
}
return e;
}
eraseElementByKey(e) {
if (!this.i) return;
const t = this.j(this.B, e);
if (t === undefined) return;
this.v(t);
}
eraseElementByIterator(e) {
const t = e.U;
if (t === this.m) {
throw new RangeError("Invalid iterator");
}
if (t.p === undefined) {
e = e.next();
}
this.v(t);
return e;
}
getHeight() {
if (!this.i) return 0;
const traversal = e => {
if (!e) return 0;
return Math.max(traversal(e.l), traversal(e.p)) + 1;
};
return traversal(this.B);
}
}
class TreeIterator extends ContainerIterator {
constructor(e, t, i) {
super(i);
this.U = e;
this.m = t;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.U === this.m.l) {
throw new RangeError("Tree iterator access denied!");
}
this.U = this.U.pre();
return this;
};
this.next = function() {
if (this.U === this.m) {
throw new RangeError("Tree iterator access denied!");
}
this.U = this.U.next();
return this;
};
} else {
this.pre = function() {
if (this.U === this.m.p) {
throw new RangeError("Tree iterator access denied!");
}
this.U = this.U.next();
return this;
};
this.next = function() {
if (this.U === this.m) {
throw new RangeError("Tree iterator access denied!");
}
this.U = this.U.pre();
return this;
};
}
}
get index() {
let e = this.U;
const t = this.m.g;
if (e === this.m) {
if (t) {
return t.I - 1;
}
return 0;
}
let i = 0;
if (e.l) {
i += e.l.I;
}
while (e !== t) {
const t = e.g;
if (e === t.p) {
i += 1;
if (t.l) {
i += t.l.I;
}
}
e = t;
}
return i;
}
equals(e) {
return this.U === e.U;
}
}
class OrderedMapIterator extends TreeIterator {
get pointer() {
if (this.U === this.m) {
throw new RangeError("OrderedMap iterator access denied");
}
return new Proxy([], {
get: (e, t) => {
if (t === "0") return this.U.u; else if (t === "1") return this.U.o;
},
set: (e, t, i) => {
if (t !== "1") {
throw new TypeError("props must be 1");
}
this.U.o = i;
return true;
}
});
}
copy() {
return new OrderedMapIterator(this.U, this.m, this.iteratorType);
}
}
class OrderedMap extends TreeContainer {
constructor(e = [], t, i) {
super(t, i);
this.q = function*(e) {
if (e === undefined) return;
yield* this.q(e.l);
yield [ e.u, e.o ];
yield* this.q(e.p);
};
e.forEach((([e, t]) => this.setElement(e, t)));
}
begin() {
return new OrderedMapIterator(this.m.l || this.m, this.m);
}
end() {
return new OrderedMapIterator(this.m, this.m);
}
rBegin() {
return new OrderedMapIterator(this.m.p || this.m, this.m, 1);
}
rEnd() {
return new OrderedMapIterator(this.m, this.m, 1);
}
front() {
if (!this.i) return undefined;
const e = this.m.l;
return [ e.u, e.o ];
}
back() {
if (!this.i) return undefined;
const e = this.m.p;
return [ e.u, e.o ];
}
forEach(e) {
let t = 0;
for (const i of this) e(i, t++, this);
}
lowerBound(e) {
const t = this.P(this.B, e);
return new OrderedMapIterator(t, this.m);
}
upperBound(e) {
const t = this.k(this.B, e);
return new OrderedMapIterator(t, this.m);
}
reverseLowerBound(e) {
const t = this.L(this.B, e);
return new OrderedMapIterator(t, this.m);
}
reverseUpperBound(e) {
const t = this.S(this.B, e);
return new OrderedMapIterator(t, this.m);
}
setElement(e, t, i) {
this.T(e, t, i);
}
find(e) {
const t = this.j(this.B, e);
if (t !== undefined) {
return new OrderedMapIterator(t, this.m);
}
return this.end();
}
getElementByKey(e) {
const t = this.j(this.B, e);
return t ? t.o : undefined;
}
getElementByPos(e) {
if (e < 0 || e > this.i - 1) {
throw new RangeError;
}
let t;
let i = 0;
for (const s of this) {
if (i === e) {
t = s;
break;
}
i += 1;
}
return t;
}
union(e) {
e.forEach((([e, t]) => this.setElement(e, t)));
}
[Symbol.iterator]() {
return this.q(this.B);
}
}
exports.OrderedMap = OrderedMap;
//# sourceMappingURL=index.js.map

@@ -1,4 +0,333 @@

export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
export type { OrderedMapIterator } from "./container/TreeContainer/OrderedMap";
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase";
export type { default as TreeContainer } from "./container/TreeContainer/Base";
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;
protected constructor(iteratorType?: IteratorType);
/**
* @description Pointers to element.
* @return 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.
* @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.
* @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;
/**
* @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.
* @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.
* @example
* const container = new Vector([1, 2]);
* console.log(container.size()); // 2
*/
size(): number;
/**
* @return Boolean about if the container is empty.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
empty(): boolean;
/**
* @description Clear the container.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
abstract clear(): void;
}
declare abstract class Container<T> extends Base {
/**
* @return 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);
* }
*/
abstract begin(): ContainerIterator<T>;
/**
* @return 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);
* }
*/
abstract end(): ContainerIterator<T>;
/**
* @return 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>;
/**
* @return 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>;
/**
* @return The first element of the container.
*/
abstract front(): T | undefined;
/**
* @return The last element of the container.
*/
abstract back(): T | undefined;
/**
* @description Iterate over all elements in the container.
* @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.
* @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.
* container.eraseElementByPos(-1); // throw a RangeError
*/
abstract eraseElementByPos(pos: number): void;
/**
* @description Removes element by iterator and move `iter` to next.
* @param iter The iterator you want to erase.
* @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.
* @example
* for (const element of container) {
* console.log(element);
* }
*/
abstract [Symbol.iterator](): Generator<T, void, undefined>;
}
type initContainer<T> = ({
size: number;
} | {
length: number;
} | {
size(): number;
}) & {
forEach(callback: (element: T) => void): void;
};
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [
K,
V
]> {
pre: () => this;
next: () => this;
/**
* @description Get the sequential index of the iterator in the tree container.<br/>
* <strong>
* Note:
* </strong>
* This function only takes effect when the specified tree container `enableIndex = true`.
* @example
* const st = new OrderedSet([1, 2, 3], true);
* console.log(st.begin().next().index); // 1
*/
get index(): number;
equals(obj: TreeIterator<K, V>): boolean;
}
declare abstract class TreeContainer<K, V> extends Container<K | [
K,
V
]> {
/**
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
*/
protected constructor(cmp?: (x: K, y: K) => number, enableIndex?: boolean);
/**
* @param key The given key you want to compare.
* @return An iterator to the first element not less than the given key.
*/
abstract lowerBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element greater than the given key.
*/
abstract upperBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element not greater than the given key.
*/
abstract reverseLowerBound(key: K): TreeIterator<K, V>;
/**
* @param key The given key you want to compare.
* @return An iterator to the first element less than the given key.
*/
abstract reverseUpperBound(key: K): TreeIterator<K, V>;
/**
* @description Union the other tree to self.
* @param other The other tree container you want to merge.
*/
abstract union(other: TreeContainer<K, V>): void;
clear(): void;
/**
* @description Update node's key by iterator.
* @param iter The iterator you want to change.
* @param key The key you want to update.
* @return Boolean about if the modification is successful.
* @example
* const st = new orderedSet([1, 2, 5]);
* const iter = st.find(2);
* st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
*/
updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
eraseElementByPos(pos: number): void;
/**
* @description Remove the element of the specified _key.
* @param key The _key you want to remove.
*/
eraseElementByKey(key: K): void;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
/**
* @description Get the height of the tree.
* @return Number about the height of the RB-tree.
*/
getHeight(): number;
}
declare class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
get pointer(): [
K,
V
];
copy(): OrderedMapIterator<K, V>;
}
declare class OrderedMap<K, V> extends TreeContainer<K, V> {
/**
* @param container The initialization container.
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
* @example
* new OrderedMap();
* new OrderedMap([[0, 1], [2, 1]]);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y, true);
*/
constructor(container?: initContainer<[
K,
V
]>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedMapIterator<K, V>;
end(): OrderedMapIterator<K, V>;
rBegin(): OrderedMapIterator<K, V>;
rEnd(): OrderedMapIterator<K, V>;
front(): [
K,
V
] | undefined;
back(): [
K,
V
] | undefined;
forEach(callback: (element: [
K,
V
], index: number, map: OrderedMap<K, V>) => void): void;
lowerBound(key: K): OrderedMapIterator<K, V>;
upperBound(key: K): OrderedMapIterator<K, V>;
reverseLowerBound(key: K): OrderedMapIterator<K, V>;
reverseUpperBound(key: K): OrderedMapIterator<K, V>;
/**
* @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 hint You can give an iterator hint to improve insertion efficiency.
* @example
* const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
* const iter = mp.begin();
* mp.setElement(1, 0);
* mp.setElement(3, 0, iter); // give a hint will be faster.
*/
setElement(key: K, value: V, hint?: OrderedMapIterator<K, V>): void;
find(key: K): OrderedMapIterator<K, V>;
/**
* @description Get the value of the element of the specified key.
* @example const val = container.getElementByKey(1);
*/
getElementByKey(key: K): V | undefined;
getElementByPos(pos: number): [
K,
V
];
union(other: OrderedMap<K, V>): void;
[Symbol.iterator](): Generator<[
K,
V
], void, undefined>;
}
export { OrderedMap };
export type { OrderedMapIterator, IteratorType, Container, ContainerIterator, TreeContainer };

@@ -1,1 +0,1018 @@

export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
var extendStatics = function(e, r) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(e, r) {
e.__proto__ = r;
} || function(e, r) {
for (var t in r) if (Object.prototype.hasOwnProperty.call(r, t)) e[t] = r[t];
};
return extendStatics(e, r);
};
function __extends(e, r) {
if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
extendStatics(e, r);
function __() {
this.constructor = e;
}
e.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
}
function __generator(e, r) {
var t = {
label: 0,
sent: function() {
if (s[0] & 1) throw s[1];
return s[1];
},
trys: [],
ops: []
}, i, n, s, a;
return a = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (a[Symbol.iterator] = function() {
return this;
}), a;
function verb(e) {
return function(r) {
return step([ e, r ]);
};
}
function step(a) {
if (i) throw new TypeError("Generator is already executing.");
while (t) try {
if (i = 1, n && (s = a[0] & 2 ? n["return"] : a[0] ? n["throw"] || ((s = n["return"]) && s.call(n),
0) : n.next) && !(s = s.call(n, a[1])).done) return s;
if (n = 0, s) a = [ a[0] & 2, s.value ];
switch (a[0]) {
case 0:
case 1:
s = a;
break;
case 4:
t.label++;
return {
value: a[1],
done: false
};
case 5:
t.label++;
n = a[1];
a = [ 0 ];
continue;
case 7:
a = t.ops.pop();
t.trys.pop();
continue;
default:
if (!(s = t.trys, s = s.length > 0 && s[s.length - 1]) && (a[0] === 6 || a[0] === 2)) {
t = 0;
continue;
}
if (a[0] === 3 && (!s || a[1] > s[0] && a[1] < s[3])) {
t.label = a[1];
break;
}
if (a[0] === 6 && t.label < s[1]) {
t.label = s[1];
s = a;
break;
}
if (s && t.label < s[2]) {
t.label = s[2];
t.ops.push(a);
break;
}
if (s[2]) t.ops.pop();
t.trys.pop();
continue;
}
a = r.call(e, t);
} catch (e) {
a = [ 6, e ];
n = 0;
} finally {
i = s = 0;
}
if (a[0] & 5) throw a[1];
return {
value: a[0] ? a[1] : void 0,
done: true
};
}
}
function __values(e) {
var r = typeof Symbol === "function" && Symbol.iterator, t = r && e[r], i = 0;
if (t) return t.call(e);
if (e && typeof e.length === "number") return {
next: function() {
if (e && i >= e.length) e = void 0;
return {
value: e && e[i++],
done: !e
};
}
};
throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(e, r) {
var t = typeof Symbol === "function" && e[Symbol.iterator];
if (!t) return e;
var i = t.call(e), n, s = [], a;
try {
while ((r === void 0 || r-- > 0) && !(n = i.next()).done) s.push(n.value);
} catch (e) {
a = {
error: e
};
} finally {
try {
if (n && !n.done && (t = i["return"])) t.call(i);
} finally {
if (a) throw a.error;
}
}
return s;
}
var ContainerIterator = function() {
function ContainerIterator(e) {
if (e === void 0) {
e = 0;
}
this.iteratorType = e;
}
return ContainerIterator;
}();
var Base = function() {
function Base() {
this.t = 0;
}
Base.prototype.size = function() {
return this.t;
};
Base.prototype.empty = function() {
return this.t === 0;
};
return Base;
}();
var Container = function(e) {
__extends(Container, e);
function Container() {
return e !== null && e.apply(this, arguments) || this;
}
return Container;
}(Base);
var TreeNode = function() {
function TreeNode(e, r) {
this.i = 1;
this.u = undefined;
this.h = undefined;
this.o = undefined;
this.l = undefined;
this.v = undefined;
this.u = e;
this.h = r;
}
TreeNode.prototype.pre = function() {
var e = this;
if (e.i === 1 && e.v.v === e) {
e = e.l;
} else if (e.o) {
e = e.o;
while (e.l) {
e = e.l;
}
} else {
var r = e.v;
while (r.o === e) {
e = r;
r = e.v;
}
e = r;
}
return e;
};
TreeNode.prototype.next = function() {
var e = this;
if (e.l) {
e = e.l;
while (e.o) {
e = e.o;
}
return e;
} else {
var r = e.v;
while (r.l === e) {
e = r;
r = e.v;
}
if (e.l !== r) {
return r;
} else return e;
}
};
TreeNode.prototype.rotateLeft = function() {
var e = this.v;
var r = this.l;
var t = r.o;
if (e.v === this) e.v = r; else if (e.o === this) e.o = r; else e.l = r;
r.v = e;
r.o = this;
this.v = r;
this.l = t;
if (t) t.v = this;
return r;
};
TreeNode.prototype.rotateRight = function() {
var e = this.v;
var r = this.o;
var t = r.l;
if (e.v === this) e.v = r; else if (e.o === this) e.o = r; else e.l = r;
r.v = e;
r.l = this;
this.v = r;
this.o = t;
if (t) t.v = this;
return r;
};
return TreeNode;
}();
var TreeNodeEnableIndex = function(e) {
__extends(TreeNodeEnableIndex, e);
function TreeNodeEnableIndex() {
var r = e !== null && e.apply(this, arguments) || this;
r.o = undefined;
r.l = undefined;
r.v = undefined;
r.p = 1;
return r;
}
TreeNodeEnableIndex.prototype.rotateLeft = function() {
var r = e.prototype.rotateLeft.call(this);
this.recount();
r.recount();
return r;
};
TreeNodeEnableIndex.prototype.rotateRight = function() {
var r = e.prototype.rotateRight.call(this);
this.recount();
r.recount();
return r;
};
TreeNodeEnableIndex.prototype.recount = function() {
this.p = 1;
if (this.o) this.p += this.o.p;
if (this.l) this.p += this.l.p;
};
return TreeNodeEnableIndex;
}(TreeNode);
var TreeContainer = function(e) {
__extends(TreeContainer, e);
function TreeContainer(r, t) {
if (r === void 0) {
r = function(e, r) {
if (e < r) return -1;
if (e > r) return 1;
return 0;
};
}
if (t === void 0) {
t = false;
}
var i = e.call(this) || this;
i.T = undefined;
i._ = function(e, r) {
if (e === undefined) return false;
var t = i._(e.o, r);
if (t) return true;
if (r(e)) return true;
return i._(e.l, r);
};
i.O = r;
if (t) {
i.M = TreeNodeEnableIndex;
i.I = function(e, r, t) {
var i = this.C(e, r, t);
if (i) {
var n = i.v;
while (n !== this.N) {
n.p += 1;
n = n.v;
}
var s = this.g(i);
if (s) {
var a = s, u = a.parentNode, f = a.grandParent, h = a.curNode;
u.recount();
f.recount();
h.recount();
}
}
};
i.S = function(e) {
var r = this.m(e);
while (r !== this.N) {
r.p -= 1;
r = r.v;
}
};
} else {
i.M = TreeNode;
i.I = function(e, r, t) {
var i = this.C(e, r, t);
if (i) this.g(i);
};
i.S = i.m;
}
i.N = new i.M;
return i;
}
TreeContainer.prototype.R = function(e, r) {
var t;
while (e) {
var i = this.O(e.u, r);
if (i < 0) {
e = e.l;
} else if (i > 0) {
t = e;
e = e.o;
} else return e;
}
return t === undefined ? this.N : t;
};
TreeContainer.prototype.k = function(e, r) {
var t;
while (e) {
var i = this.O(e.u, r);
if (i <= 0) {
e = e.l;
} else {
t = e;
e = e.o;
}
}
return t === undefined ? this.N : t;
};
TreeContainer.prototype.j = function(e, r) {
var t;
while (e) {
var i = this.O(e.u, r);
if (i < 0) {
t = e;
e = e.l;
} else if (i > 0) {
e = e.o;
} else return e;
}
return t === undefined ? this.N : t;
};
TreeContainer.prototype.B = function(e, r) {
var t;
while (e) {
var i = this.O(e.u, r);
if (i < 0) {
t = e;
e = e.l;
} else {
e = e.o;
}
}
return t === undefined ? this.N : t;
};
TreeContainer.prototype.P = function(e) {
while (true) {
var r = e.v;
if (r === this.N) return;
if (e.i === 1) {
e.i = 0;
return;
}
if (e === r.o) {
var t = r.l;
if (t.i === 1) {
t.i = 0;
r.i = 1;
if (r === this.T) {
this.T = r.rotateLeft();
} else r.rotateLeft();
} else {
if (t.l && t.l.i === 1) {
t.i = r.i;
r.i = 0;
t.l.i = 0;
if (r === this.T) {
this.T = r.rotateLeft();
} else r.rotateLeft();
return;
} else if (t.o && t.o.i === 1) {
t.i = 1;
t.o.i = 0;
t.rotateRight();
} else {
t.i = 1;
e = r;
}
}
} else {
var t = r.o;
if (t.i === 1) {
t.i = 0;
r.i = 1;
if (r === this.T) {
this.T = r.rotateRight();
} else r.rotateRight();
} else {
if (t.o && t.o.i === 1) {
t.i = r.i;
r.i = 0;
t.o.i = 0;
if (r === this.T) {
this.T = r.rotateRight();
} else r.rotateRight();
return;
} else if (t.l && t.l.i === 1) {
t.i = 1;
t.l.i = 0;
t.rotateLeft();
} else {
t.i = 1;
e = r;
}
}
}
}
};
TreeContainer.prototype.m = function(e) {
var r, t;
if (this.t === 1) {
this.clear();
return this.N;
}
var i = e;
while (i.o || i.l) {
if (i.l) {
i = i.l;
while (i.o) i = i.o;
} else {
i = i.o;
}
r = __read([ i.u, e.u ], 2), e.u = r[0], i.u = r[1];
t = __read([ i.h, e.h ], 2), e.h = t[0], i.h = t[1];
e = i;
}
if (this.N.o === i) {
this.N.o = i.v;
} else if (this.N.l === i) {
this.N.l = i.v;
}
this.P(i);
var n = i.v;
if (i === n.o) {
n.o = undefined;
} else n.l = undefined;
this.t -= 1;
this.T.i = 0;
return n;
};
TreeContainer.prototype.g = function(e) {
while (true) {
var r = e.v;
if (r.i === 0) return;
var t = r.v;
if (r === t.o) {
var i = t.l;
if (i && i.i === 1) {
i.i = r.i = 0;
if (t === this.T) return;
t.i = 1;
e = t;
continue;
} else if (e === r.l) {
e.i = 0;
if (e.o) e.o.v = r;
if (e.l) e.l.v = t;
r.l = e.o;
t.o = e.l;
e.o = r;
e.l = t;
if (t === this.T) {
this.T = e;
this.N.v = e;
} else {
var n = t.v;
if (n.o === t) {
n.o = e;
} else n.l = e;
}
e.v = t.v;
r.v = e;
t.v = e;
t.i = 1;
return {
parentNode: r,
grandParent: t,
curNode: e
};
} else {
r.i = 0;
if (t === this.T) {
this.T = t.rotateRight();
} else t.rotateRight();
t.i = 1;
}
} else {
var i = t.o;
if (i && i.i === 1) {
i.i = r.i = 0;
if (t === this.T) return;
t.i = 1;
e = t;
continue;
} else if (e === r.o) {
e.i = 0;
if (e.o) e.o.v = t;
if (e.l) e.l.v = r;
t.l = e.o;
r.o = e.l;
e.o = t;
e.l = r;
if (t === this.T) {
this.T = e;
this.N.v = e;
} else {
var n = t.v;
if (n.o === t) {
n.o = e;
} else n.l = e;
}
e.v = t.v;
r.v = e;
t.v = e;
t.i = 1;
return {
parentNode: r,
grandParent: t,
curNode: e
};
} else {
r.i = 0;
if (t === this.T) {
this.T = t.rotateLeft();
} else t.rotateLeft();
t.i = 1;
}
}
return;
}
};
TreeContainer.prototype.C = function(e, r, t) {
if (this.T === undefined) {
this.t += 1;
this.T = new this.M(e, r);
this.T.i = 0;
this.T.v = this.N;
this.N.v = this.T;
this.N.o = this.T;
this.N.l = this.T;
return;
}
var i;
var n = this.N.o;
var s = this.O(n.u, e);
if (s === 0) {
n.h = r;
return;
} else if (s > 0) {
n.o = new this.M(e, r);
n.o.v = n;
i = n.o;
this.N.o = i;
} else {
var a = this.N.l;
var u = this.O(a.u, e);
if (u === 0) {
a.h = r;
return;
} else if (u < 0) {
a.l = new this.M(e, r);
a.l.v = a;
i = a.l;
this.N.l = i;
} else {
if (t !== undefined) {
var f = t.A;
if (f !== this.N) {
var h = this.O(f.u, e);
if (h === 0) {
f.h = r;
return;
} else if (h > 0) {
var o = f.pre();
var d = this.O(o.u, e);
if (d === 0) {
o.h = r;
return;
} else if (d < 0) {
i = new this.M(e, r);
if (o.l === undefined) {
o.l = i;
i.v = o;
} else {
f.o = i;
i.v = f;
}
}
}
}
}
if (i === undefined) {
i = this.T;
while (true) {
var c = this.O(i.u, e);
if (c > 0) {
if (i.o === undefined) {
i.o = new this.M(e, r);
i.o.v = i;
i = i.o;
break;
}
i = i.o;
} else if (c < 0) {
if (i.l === undefined) {
i.l = new this.M(e, r);
i.l.v = i;
i = i.l;
break;
}
i = i.l;
} else {
i.h = r;
return;
}
}
}
}
}
this.t += 1;
return i;
};
TreeContainer.prototype.clear = function() {
this.t = 0;
this.T = undefined;
this.N.v = undefined;
this.N.o = this.N.l = undefined;
};
TreeContainer.prototype.updateKeyByIterator = function(e, r) {
var t = e.A;
if (t === this.N) {
throw new TypeError("Invalid iterator!");
}
if (this.t === 1) {
t.u = r;
return true;
}
if (t === this.N.o) {
if (this.O(t.next().u, r) > 0) {
t.u = r;
return true;
}
return false;
}
if (t === this.N.l) {
if (this.O(t.pre().u, r) < 0) {
t.u = r;
return true;
}
return false;
}
var i = t.pre().u;
if (this.O(i, r) >= 0) return false;
var n = t.next().u;
if (this.O(n, r) <= 0) return false;
t.u = r;
return true;
};
TreeContainer.prototype.eraseElementByPos = function(e) {
var r = this;
if (e < 0 || e > this.t - 1) {
throw new RangeError;
}
var t = 0;
this._(this.T, (function(i) {
if (e === t) {
r.S(i);
return true;
}
t += 1;
return false;
}));
};
TreeContainer.prototype.G = function(e, r) {
while (e) {
var t = this.O(e.u, r);
if (t < 0) {
e = e.l;
} else if (t > 0) {
e = e.o;
} else return e;
}
return e;
};
TreeContainer.prototype.eraseElementByKey = function(e) {
if (!this.t) return;
var r = this.G(this.T, e);
if (r === undefined) return;
this.S(r);
};
TreeContainer.prototype.eraseElementByIterator = function(e) {
var r = e.A;
if (r === this.N) {
throw new RangeError("Invalid iterator");
}
if (r.l === undefined) {
e = e.next();
}
this.S(r);
return e;
};
TreeContainer.prototype.getHeight = function() {
if (!this.t) return 0;
var traversal = function(e) {
if (!e) return 0;
return Math.max(traversal(e.o), traversal(e.l)) + 1;
};
return traversal(this.T);
};
return TreeContainer;
}(Container);
var TreeIterator = function(e) {
__extends(TreeIterator, e);
function TreeIterator(r, t, i) {
var n = e.call(this, i) || this;
n.A = r;
n.N = t;
if (n.iteratorType === 0) {
n.pre = function() {
if (this.A === this.N.o) {
throw new RangeError("Tree iterator access denied!");
}
this.A = this.A.pre();
return this;
};
n.next = function() {
if (this.A === this.N) {
throw new RangeError("Tree iterator access denied!");
}
this.A = this.A.next();
return this;
};
} else {
n.pre = function() {
if (this.A === this.N.l) {
throw new RangeError("Tree iterator access denied!");
}
this.A = this.A.next();
return this;
};
n.next = function() {
if (this.A === this.N) {
throw new RangeError("Tree iterator access denied!");
}
this.A = this.A.pre();
return this;
};
}
return n;
}
Object.defineProperty(TreeIterator.prototype, "index", {
get: function() {
var e = this.A;
var r = this.N.v;
if (e === this.N) {
if (r) {
return r.p - 1;
}
return 0;
}
var t = 0;
if (e.o) {
t += e.o.p;
}
while (e !== r) {
var i = e.v;
if (e === i.l) {
t += 1;
if (i.o) {
t += i.o.p;
}
}
e = i;
}
return t;
},
enumerable: false,
configurable: true
});
TreeIterator.prototype.equals = function(e) {
return this.A === e.A;
};
return TreeIterator;
}(ContainerIterator);
var OrderedMapIterator = function(e) {
__extends(OrderedMapIterator, e);
function OrderedMapIterator() {
return e !== null && e.apply(this, arguments) || this;
}
Object.defineProperty(OrderedMapIterator.prototype, "pointer", {
get: function() {
var e = this;
if (this.A === this.N) {
throw new RangeError("OrderedMap iterator access denied");
}
return new Proxy([], {
get: function(r, t) {
if (t === "0") return e.A.u; else if (t === "1") return e.A.h;
},
set: function(r, t, i) {
if (t !== "1") {
throw new TypeError("props must be 1");
}
e.A.h = i;
return true;
}
});
},
enumerable: false,
configurable: true
});
OrderedMapIterator.prototype.copy = function() {
return new OrderedMapIterator(this.A, this.N, this.iteratorType);
};
return OrderedMapIterator;
}(TreeIterator);
var OrderedMap = function(e) {
__extends(OrderedMap, e);
function OrderedMap(r, t, i) {
if (r === void 0) {
r = [];
}
var n = e.call(this, t, i) || this;
n.q = function(e) {
return __generator(this, (function(r) {
switch (r.label) {
case 0:
if (e === undefined) return [ 2 ];
return [ 5, __values(this.q(e.o)) ];
case 1:
r.sent();
return [ 4, [ e.u, e.h ] ];
case 2:
r.sent();
return [ 5, __values(this.q(e.l)) ];
case 3:
r.sent();
return [ 2 ];
}
}));
};
r.forEach((function(e) {
var r = __read(e, 2), t = r[0], i = r[1];
return n.setElement(t, i);
}));
return n;
}
OrderedMap.prototype.begin = function() {
return new OrderedMapIterator(this.N.o || this.N, this.N);
};
OrderedMap.prototype.end = function() {
return new OrderedMapIterator(this.N, this.N);
};
OrderedMap.prototype.rBegin = function() {
return new OrderedMapIterator(this.N.l || this.N, this.N, 1);
};
OrderedMap.prototype.rEnd = function() {
return new OrderedMapIterator(this.N, this.N, 1);
};
OrderedMap.prototype.front = function() {
if (!this.t) return undefined;
var e = this.N.o;
return [ e.u, e.h ];
};
OrderedMap.prototype.back = function() {
if (!this.t) return undefined;
var e = this.N.l;
return [ e.u, e.h ];
};
OrderedMap.prototype.forEach = function(e) {
var r, t;
var i = 0;
try {
for (var n = __values(this), s = n.next(); !s.done; s = n.next()) {
var a = s.value;
e(a, i++, this);
}
} catch (e) {
r = {
error: e
};
} finally {
try {
if (s && !s.done && (t = n.return)) t.call(n);
} finally {
if (r) throw r.error;
}
}
};
OrderedMap.prototype.lowerBound = function(e) {
var r = this.R(this.T, e);
return new OrderedMapIterator(r, this.N);
};
OrderedMap.prototype.upperBound = function(e) {
var r = this.k(this.T, e);
return new OrderedMapIterator(r, this.N);
};
OrderedMap.prototype.reverseLowerBound = function(e) {
var r = this.j(this.T, e);
return new OrderedMapIterator(r, this.N);
};
OrderedMap.prototype.reverseUpperBound = function(e) {
var r = this.B(this.T, e);
return new OrderedMapIterator(r, this.N);
};
OrderedMap.prototype.setElement = function(e, r, t) {
this.I(e, r, t);
};
OrderedMap.prototype.find = function(e) {
var r = this.G(this.T, e);
if (r !== undefined) {
return new OrderedMapIterator(r, this.N);
}
return this.end();
};
OrderedMap.prototype.getElementByKey = function(e) {
var r = this.G(this.T, e);
return r ? r.h : undefined;
};
OrderedMap.prototype.getElementByPos = function(e) {
var r, t;
if (e < 0 || e > this.t - 1) {
throw new RangeError;
}
var i;
var n = 0;
try {
for (var s = __values(this), a = s.next(); !a.done; a = s.next()) {
var u = a.value;
if (n === e) {
i = u;
break;
}
n += 1;
}
} catch (e) {
r = {
error: e
};
} finally {
try {
if (a && !a.done && (t = s.return)) t.call(s);
} finally {
if (r) throw r.error;
}
}
return i;
};
OrderedMap.prototype.union = function(e) {
var r = this;
e.forEach((function(e) {
var t = __read(e, 2), i = t[0], n = t[1];
return r.setElement(i, n);
}));
};
OrderedMap.prototype[Symbol.iterator] = function() {
return this.q(this.T);
};
return OrderedMap;
}(TreeContainer);
export { OrderedMap };
//# sourceMappingURL=index.js.map

24

package.json
{
"name": "@js-sdsl/ordered-map",
"version": "4.1.5",
"version": "4.2.0-beta.0",
"description": "javascript standard data structure library which benchmark against C++ STL",

@@ -12,8 +12,2 @@ "main": "./dist/cjs/index.js",

},
"browserslist": [
"last 2 version",
"> 1%",
"not dead",
"maintained node versions"
],
"sideEffects": false,

@@ -30,4 +24,5 @@ "homepage": "https://js-sdsl.github.io",

"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-typescript": "^9.0.2",
"@types/babel__core": "^7.1.19",
"@types/chai": "^4.3.3",
"@types/chai": "^3.5.2",
"@types/delete-empty": "^3.0.2",

@@ -51,7 +46,7 @@ "@types/gulp": "^4.0.9",

"browserslist": "^4.21.3",
"caniuse-lite": "^1.0.30001380",
"chai": "^4.3.6",
"chai": "^3.5.0",
"commitlint": "^17.0.3",
"compare-versions": "^5.0.1",
"conventional-changelog-conventionalcommits": "^5.0.0",
"crypto": "^1.0.1",
"delete-empty": "^3.0.0",

@@ -67,3 +62,2 @@ "eslint": "^8.23.1",

"gulp-rename": "^2.0.0",
"gulp-rollup-2": "^1.3.1",
"gulp-sourcemaps": "^3.0.0",

@@ -77,13 +71,17 @@ "gulp-tap": "^2.0.0",

"karma-chrome-launcher": "^3.1.1",
"karma-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-requirejs": "^1.1.0",
"karma-safarinative-launcher": "^1.1.0",
"karma-typescript": "^5.5.3",
"lint-staged": "^13.0.3",
"merge-stream": "^2.0.0",
"mocha": "^10.0.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"requirejs": "^2.3.6",
"rollup": "^2.79.1",
"rollup-plugin-typescript2": "^0.33.0",
"rollup-plugin-license": "^3.0.0",
"rollup-plugin-ts": "^3.0.2",
"ts-macros": "^1.3.3",

@@ -90,0 +88,0 @@ "ts-mocha": "^10.0.0",

@@ -23,28 +23,61 @@ <p align="center">

## Included data structures
## ✨ Included data structures
- Vector
- Stack
- Queue
- LinkList
- Deque
- PriorityQueue
- OrderedSet (using RBTree)
- OrderedMap (using RBTree)
- HashSet
- HashMap
- **Stack** - first in first out stack.
- **Queue** - first in last out queue.
- **PriorityQueue** - heap-implemented priority queue.
- **Vector** - protected array, cannot to operate properties like `length` directly.
- **LinkList** - linked list of non-contiguous memory addresses.
- **Deque** - double-ended-queue, O(1) time complexity to inserting elements front and back or getting elements by index.
- **OrderedSet** - sorted set which implemented by red black tree.
- **OrderedMap** - sorted map which implemented by red black tree.
- **HashSet** - refer to the hash set implemented by java.
- **HashMap** - refer to the hash map implemented by java.
## Benchmark
## ⚔️ Benchmark
We are benchmarking against other popular data structure libraries. In some ways we're better than the best library. See [benchmark](https://js-sdsl.github.io/#/test/benchmark-analyze).
## Supported platforms
## 🖥 Supported platforms
- node.js (using es6)
- react/vue (using es5)
- browser (support most browsers)
<table>
<tr align="center">
<td>
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" />
<div>IE / Edge</div>
</td>
<td>
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" />
<div>Firefox</div>
</td>
<td>
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" />
<div>Chrome</div>
</td>
<td>
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" />
<div>Safari</div>
</td>
<td>
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" />
<div>Opera</div>
</td>
<td>
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" />
<div>NodeJs</div>
</td>
</tr>
<tr align="center">
<td>Edge 12</td>
<td>31</td>
<td>49</td>
<td>10</td>
<td>36</td>
<td>10</td>
</tr>
</table>
## Download
## 📦 Download
Download directly
Download directly by cdn:

@@ -54,3 +87,3 @@ - [js-sdsl.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js) (for development)

Or install js-sdsl using npm
Or install js-sdsl using npm:

@@ -61,4 +94,19 @@ ```bash

## Usage
Or you can download the isolation packages containing only the containers you want:
| package | npm | install |
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| [@js-sdsl/stack](https://js-sdsl.github.io/js-sdsl/classes/Stack.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/stack)](https://www.npmjs.com/package/@js-sdsl/stack) | `npm i @js-sdsl/stack` |
| [@js-sdsl/queue](https://js-sdsl.github.io/js-sdsl/classes/Queue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/queue)](https://www.npmjs.com/package/@js-sdsl/queue) | `npm i @js-sdsl/queue` |
| [@js-sdsl/priority-queue](https://js-sdsl.github.io/js-sdsl/classes/PriorityQueue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/priority-queue)](https://www.npmjs.com/package/@js-sdsl/priority-queue) | `npm i @js-sdsl/priority-queue` |
| [@js-sdsl/vector](https://js-sdsl.github.io/js-sdsl/classes/Vector.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/vector)](https://www.npmjs.com/package/@js-sdsl/vector) | `npm i @js-sdsl/vector` |
| [@js-sdsl/link-list](https://js-sdsl.github.io/js-sdsl/classes/LinkList.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/link-list)](https://www.npmjs.com/package/@js-sdsl/link-list) | `npm i @js-sdsl/link-list` |
| [@js-sdsl/deque](https://js-sdsl.github.io/js-sdsl/classes/Deque.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/deque)](https://www.npmjs.com/package/@js-sdsl/deque) | `npm i @js-sdsl/deque` |
| [@js-sdsl/ordered-set](https://js-sdsl.github.io/js-sdsl/classes/OrderedSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-set)](https://www.npmjs.com/package/@js-sdsl/ordered-set) | `npm i @js-sdsl/ordered-set` |
| [@js-sdsl/ordered-map](https://js-sdsl.github.io/js-sdsl/classes/OrderedMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-map)](https://www.npmjs.com/package/@js-sdsl/ordered-map) | `npm i @js-sdsl/ordered-map` |
| [@js-sdsl/hash-set](https://js-sdsl.github.io/js-sdsl/classes/HashSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-set)](https://www.npmjs.com/package/@js-sdsl/hash-set) | `npm i @js-sdsl/hash-set` |
| [@js-sdsl/hash-map](https://js-sdsl.github.io/js-sdsl/classes/HashMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-map)](https://www.npmjs.com/package/@js-sdsl/hash-map) | `npm i @js-sdsl/hash-map` |
## 🪒 Usage
You can visit our [official website](https://js-sdsl.github.io/) to get more information.

@@ -68,2 +116,10 @@

For previous versions of the documentation, please visit:
`https://js-sdsl.github.io/js-sdsl/previous/v${version}/index.html`
E.g.
[https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html)
### For browser

@@ -104,8 +160,4 @@

## Build by source code
## 🛠 Test
You can pull this repository and run `yarn build` to rebuild this library.
## Test
### Unit test

@@ -121,8 +173,21 @@

## Maintainers
## ⌨️ Development
[@ZLY201](https://github.com/ZLY201)
Use Gitpod, a free online dev environment for GitHub.
## Contributing
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl)
Or clone locally:
```bash
$ git clone https://github.com/js-sdsl/js-sdl.git
$ cd js-sdsl
$ npm install
$ npm run dev # development mode
```
Then you can see the output in `dist/cjs` folder.
## 🤝 Contributing
Feel free to dive in! Open an issue or submit PRs. It may be helpful to read the [Contributor Guide](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md).

@@ -153,4 +218,16 @@

## License
## ❤️ Sponsors and Backers
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201
The special thanks to these sponsors or backers because they provided support at a very early stage:
<a href="https://eslint.org/"><img src="https://js-sdsl.github.io/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a>
Thanks also give to these sponsors or backers:
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
## 🪪 License
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201)

@@ -23,16 +23,16 @@ <p align="center">

## 包含的数据结构
## ✨ 包含的数据结构
- Vector
- Stack
- Queue
- LinkList
- Deque
- PriorityQueue
- OrderedSet (using RBTree)
- OrderedMap (using RBTree)
- HashSet
- HashMap
- **Stack** - 先进先出的堆栈
- **Queue** - 先进后出的队列
- **PriorityQueue** - 堆实现的优先级队列
- **Vector** - 受保护的数组,不能直接操作像 `length` 这样的属性
- **LinkList** - 非连续内存地址的链表
- **Deque** - 双端队列,向前和向后插入元素或按索引获取元素的 O(1) 时间复杂度
- **OrderedSet** - 由红黑树实现的排序集合
- **OrderedMap** - 由红黑树实现的排序字典
- **HashSet** - 参考 java 实现的哈希集合
- **HashMap** - 参考 java 实现的哈希字典
## 基准测试
## ⚔️ 基准测试

@@ -43,9 +43,42 @@ 我们和其他数据结构库进行了基准测试,在某些场景我们甚至超过了当前最流行的库

## 支持的平台
## 🖥 支持的平台
- node.js (using es6)
- react/vue (using es5)
- browser (support most browsers)
<table>
<tr align="center">
<td>
<img alt="IE / Edge" src="https://www.w3schools.com/images/compatible_edge2020.png" />
<div>IE / Edge</div>
</td>
<td>
<img alt="Firefox" src="https://www.w3schools.com/images/compatible_firefox2020.png" />
<div>Firefox</div>
</td>
<td>
<img alt="Chrome" src="https://www.w3schools.com/images/compatible_chrome2020.png" />
<div>Chrome</div>
</td>
<td>
<img alt="Safari" src="https://www.w3schools.com/images/compatible_safari2020.png" />
<div>Safari</div>
</td>
<td>
<img alt="Opera" src="https://www.w3schools.com/images/compatible_opera2020.png" />
<div>Opera</div>
</td>
<td>
<img alt="NodeJs" src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" width="20" />
<div>NodeJs</div>
</td>
</tr>
<tr align="center">
<td>Edge 12</td>
<td>31</td>
<td>49</td>
<td>10</td>
<td>36</td>
<td>10</td>
</tr>
</table>
## 下载
## 📦 下载

@@ -63,4 +96,19 @@ 使用 cdn 直接引入

## 使用说明
或者根据需要安装以下任意单个包
| package | npm | install |
|-----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| [@js-sdsl/stack](https://js-sdsl.github.io/js-sdsl/classes/Stack.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/stack)](https://www.npmjs.com/package/@js-sdsl/stack) | `npm i @js-sdsl/stack` |
| [@js-sdsl/queue](https://js-sdsl.github.io/js-sdsl/classes/Queue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/queue)](https://www.npmjs.com/package/@js-sdsl/queue) | `npm i @js-sdsl/queue` |
| [@js-sdsl/priority-queue](https://js-sdsl.github.io/js-sdsl/classes/PriorityQueue.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/priority-queue)](https://www.npmjs.com/package/@js-sdsl/priority-queue) | `npm i @js-sdsl/priority-queue` |
| [@js-sdsl/vector](https://js-sdsl.github.io/js-sdsl/classes/Vector.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/vector)](https://www.npmjs.com/package/@js-sdsl/vector) | `npm i @js-sdsl/vector` |
| [@js-sdsl/link-list](https://js-sdsl.github.io/js-sdsl/classes/LinkList.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/link-list)](https://www.npmjs.com/package/@js-sdsl/link-list) | `npm i @js-sdsl/link-list` |
| [@js-sdsl/deque](https://js-sdsl.github.io/js-sdsl/classes/Deque.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/deque)](https://www.npmjs.com/package/@js-sdsl/deque) | `npm i @js-sdsl/deque` |
| [@js-sdsl/ordered-set](https://js-sdsl.github.io/js-sdsl/classes/OrderedSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-set)](https://www.npmjs.com/package/@js-sdsl/ordered-set) | `npm i @js-sdsl/ordered-set` |
| [@js-sdsl/ordered-map](https://js-sdsl.github.io/js-sdsl/classes/OrderedMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/ordered-map)](https://www.npmjs.com/package/@js-sdsl/ordered-map) | `npm i @js-sdsl/ordered-map` |
| [@js-sdsl/hash-set](https://js-sdsl.github.io/js-sdsl/classes/HashSet.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-set)](https://www.npmjs.com/package/@js-sdsl/hash-set) | `npm i @js-sdsl/hash-set` |
| [@js-sdsl/hash-map](https://js-sdsl.github.io/js-sdsl/classes/HashMap.html) | [![NPM Package](https://img.shields.io/npm/v/@js-sdsl/hash-map)](https://www.npmjs.com/package/@js-sdsl/hash-map) | `npm i @js-sdsl/hash-map` |
## 🪒 使用说明
您可以[访问我们的主页](https://js-sdsl.github.io/)获取更多信息

@@ -70,2 +118,10 @@

想要查看从前版本的文档,请访问:
`https://js-sdsl.github.io/js-sdsl/previous/v${version}/index.html`
例如:
[https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.github.io/js-sdsl/previous/v4.1.5/index.html)
### 在浏览器中使用

@@ -106,8 +162,4 @@

## 从源码构建
## 🛠 测试
您可以克隆此仓库后运行 `yarn build` 命令重新构建这个库
## 测试
### 单元测试

@@ -123,8 +175,21 @@

## 维护者
## ⌨️ 开发
[@ZLY201](https://github.com/ZLY201)
可以使用 Gitpod 进行在线编辑:
## 贡献
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl)
或者在本地使用以下命令获取源码进行开发:
```bash
$ git clone https://github.com/js-sdsl/js-sdl.git
$ cd js-sdsl
$ npm install
$ npm run dev # development mode
```
之后您在 `dist/cjs` 文件夹中可以看到在 `dev` 模式下打包生成的产物
## 🤝 贡献
我们欢迎所有的开发人员提交 issue 或 pull request,阅读[贡献者指南](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md)可能会有所帮助

@@ -155,4 +220,16 @@

## 许可证
## ❤️ 赞助者
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201
特别鸣谢下列赞助商和支持者们,他们在非常早期的时候为我们提供了支持:
<a href="https://eslint.org/"><img src="https://js-sdsl.github.io/assets/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a>
同样感谢这些赞助商和支持者们:
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
## 🪪 许可证
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201)