Insane number of adds to setup env and packages
This commit is contained in:
25
node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.d.ts
generated
vendored
Normal file
25
node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Base } from "../../ContainerBase";
|
||||
declare abstract class HashContainer<K> extends Base {
|
||||
protected constructor(initBucketNum?: number, hashFunc?: (x: K) => number);
|
||||
clear(): void;
|
||||
/**
|
||||
* @description Iterate over all elements in the container.
|
||||
* @param callback Callback function like Array.forEach.
|
||||
*/
|
||||
abstract forEach(callback: (element: unknown, index: number) => void): void;
|
||||
/**
|
||||
* @description Remove the elements of the specified value.
|
||||
* @param key The element you want to remove.
|
||||
*/
|
||||
abstract eraseElementByKey(key: K): void;
|
||||
/**
|
||||
* @param key The element you want to find.
|
||||
* @return Boolean about if the specified element in the hash set.
|
||||
*/
|
||||
abstract find(key: K): void;
|
||||
/**
|
||||
* @description Using for `for...of` syntax like Array.
|
||||
*/
|
||||
abstract [Symbol.iterator](): Generator<K | [K, unknown], void, undefined>;
|
||||
}
|
||||
export default HashContainer;
|
||||
42
node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.js
generated
vendored
Normal file
42
node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "t", {
|
||||
value: true
|
||||
});
|
||||
|
||||
exports.default = void 0;
|
||||
|
||||
var _ContainerBase = require("../../ContainerBase");
|
||||
|
||||
class HashContainer extends _ContainerBase.Base {
|
||||
constructor(e = 16, t = (e => {
|
||||
let t;
|
||||
if (typeof e !== "string") {
|
||||
t = JSON.stringify(e);
|
||||
} else t = e;
|
||||
let r = 0;
|
||||
const s = t.length;
|
||||
for (let e = 0; e < s; e++) {
|
||||
const s = t.charCodeAt(e);
|
||||
r = (r << 5) - r + s;
|
||||
r |= 0;
|
||||
}
|
||||
return r >>> 0;
|
||||
})) {
|
||||
super();
|
||||
if (e < 16 || (e & e - 1) !== 0) {
|
||||
throw new RangeError("InitBucketNum range error");
|
||||
}
|
||||
this.u = this.te = e;
|
||||
this.l = t;
|
||||
}
|
||||
clear() {
|
||||
this.o = 0;
|
||||
this.u = this.te;
|
||||
this.i = [];
|
||||
}
|
||||
}
|
||||
|
||||
var _default = HashContainer;
|
||||
|
||||
exports.default = _default;
|
||||
22
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.d.ts
generated
vendored
Normal file
22
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { initContainer } from "../ContainerBase";
|
||||
import HashContainer from './Base';
|
||||
declare class HashMap<K, V> extends HashContainer<K> {
|
||||
constructor(container?: initContainer<[K, V]>, initBucketNum?: number, hashFunc?: (x: K) => number);
|
||||
forEach(callback: (element: [K, V], index: number) => void): void;
|
||||
/**
|
||||
* @description Insert a new key-value pair to hash map or set value by key.
|
||||
* @param key The key you want to insert.
|
||||
* @param value The value you want to insert.
|
||||
* @example HashMap.setElement(1, 2); // insert a key-value pair [1, 2]
|
||||
*/
|
||||
setElement(key: K, value: V): void;
|
||||
/**
|
||||
* @description Get the value of the element which has the specified key.
|
||||
* @param key The key you want to get.
|
||||
*/
|
||||
getElementByKey(key: K): V | undefined;
|
||||
eraseElementByKey(key: K): void;
|
||||
find(key: K): boolean;
|
||||
[Symbol.iterator](): Generator<[K, V], void, unknown>;
|
||||
}
|
||||
export default HashMap;
|
||||
178
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.js
generated
vendored
Normal file
178
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.js
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "t", {
|
||||
value: true
|
||||
});
|
||||
|
||||
exports.default = void 0;
|
||||
|
||||
var _Base = _interopRequireDefault(require("./Base"));
|
||||
|
||||
var _Vector = _interopRequireDefault(require("../SequentialContainer/Vector"));
|
||||
|
||||
var _OrderedMap = _interopRequireDefault(require("../TreeContainer/OrderedMap"));
|
||||
|
||||
function _interopRequireDefault(e) {
|
||||
return e && e.t ? e : {
|
||||
default: e
|
||||
};
|
||||
}
|
||||
|
||||
class HashMap extends _Base.default {
|
||||
constructor(e = [], t, s) {
|
||||
super(t, s);
|
||||
this.i = [];
|
||||
e.forEach((e => this.setElement(e[0], e[1])));
|
||||
}
|
||||
h() {
|
||||
if (this.u >= 1073741824) return;
|
||||
const e = [];
|
||||
const t = this.u;
|
||||
this.u <<= 1;
|
||||
const s = Object.keys(this.i);
|
||||
const r = s.length;
|
||||
for (let n = 0; n < r; ++n) {
|
||||
const r = parseInt(s[n]);
|
||||
const i = this.i[r];
|
||||
const o = i.size();
|
||||
if (o === 0) continue;
|
||||
if (o === 1) {
|
||||
const t = i.front();
|
||||
e[this.l(t[0]) & this.u - 1] = new _Vector.default([ t ], false);
|
||||
continue;
|
||||
}
|
||||
const c = [];
|
||||
const f = [];
|
||||
i.forEach((e => {
|
||||
const s = this.l(e[0]);
|
||||
if ((s & t) === 0) {
|
||||
c.push(e);
|
||||
} else f.push(e);
|
||||
}));
|
||||
if (i instanceof _OrderedMap.default) {
|
||||
if (c.length > 6) {
|
||||
e[r] = new _OrderedMap.default(c);
|
||||
} else {
|
||||
e[r] = new _Vector.default(c, false);
|
||||
}
|
||||
if (f.length > 6) {
|
||||
e[r + t] = new _OrderedMap.default(f);
|
||||
} else {
|
||||
e[r + t] = new _Vector.default(f, false);
|
||||
}
|
||||
} else {
|
||||
e[r] = new _Vector.default(c, false);
|
||||
e[r + t] = new _Vector.default(f, false);
|
||||
}
|
||||
}
|
||||
this.i = e;
|
||||
}
|
||||
forEach(e) {
|
||||
const t = Object.values(this.i);
|
||||
const s = t.length;
|
||||
let r = 0;
|
||||
for (let n = 0; n < s; ++n) {
|
||||
t[n].forEach((t => e(t, r++)));
|
||||
}
|
||||
}
|
||||
setElement(e, t) {
|
||||
const s = this.l(e) & this.u - 1;
|
||||
const r = this.i[s];
|
||||
if (!r) {
|
||||
this.o += 1;
|
||||
this.i[s] = new _Vector.default([ [ e, t ] ], false);
|
||||
} else {
|
||||
const n = r.size();
|
||||
if (r instanceof _Vector.default) {
|
||||
for (const s of r) {
|
||||
if (s[0] === e) {
|
||||
s[1] = t;
|
||||
return;
|
||||
}
|
||||
}
|
||||
r.pushBack([ e, t ]);
|
||||
if (n + 1 >= 8) {
|
||||
if (this.u <= 64) {
|
||||
this.o += 1;
|
||||
this.h();
|
||||
return;
|
||||
}
|
||||
this.i[s] = new _OrderedMap.default(this.i[s]);
|
||||
}
|
||||
this.o += 1;
|
||||
} else {
|
||||
r.setElement(e, t);
|
||||
const s = r.size();
|
||||
this.o += s - n;
|
||||
}
|
||||
}
|
||||
if (this.o > this.u * .75) {
|
||||
this.h();
|
||||
}
|
||||
}
|
||||
getElementByKey(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) return undefined;
|
||||
if (s instanceof _OrderedMap.default) {
|
||||
return s.getElementByKey(e);
|
||||
} else {
|
||||
for (const t of s) {
|
||||
if (t[0] === e) return t[1];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
eraseElementByKey(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) return;
|
||||
if (s instanceof _Vector.default) {
|
||||
let t = 0;
|
||||
for (const r of s) {
|
||||
if (r[0] === e) {
|
||||
s.eraseElementByPos(t);
|
||||
this.o -= 1;
|
||||
return;
|
||||
}
|
||||
t += 1;
|
||||
}
|
||||
} else {
|
||||
const r = s.size();
|
||||
s.eraseElementByKey(e);
|
||||
const n = s.size();
|
||||
this.o += n - r;
|
||||
if (n <= 6) {
|
||||
this.i[t] = new _Vector.default(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
find(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) return false;
|
||||
if (s instanceof _OrderedMap.default) {
|
||||
return !s.find(e).equals(s.end());
|
||||
}
|
||||
for (const t of s) {
|
||||
if (t[0] === e) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return function*() {
|
||||
const e = Object.values(this.i);
|
||||
const t = e.length;
|
||||
for (let s = 0; s < t; ++s) {
|
||||
const t = e[s];
|
||||
for (const e of t) {
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
}.bind(this)();
|
||||
}
|
||||
}
|
||||
|
||||
var _default = HashMap;
|
||||
|
||||
exports.default = _default;
|
||||
15
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.d.ts
generated
vendored
Normal file
15
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import HashContainer from './Base';
|
||||
import { initContainer } from "../ContainerBase";
|
||||
declare class HashSet<K> extends HashContainer<K> {
|
||||
constructor(container?: initContainer<K>, initBucketNum?: number, _hashFunc?: (x: K) => number);
|
||||
forEach(callback: (element: K, index: number) => void): void;
|
||||
/**
|
||||
* @description Insert element to hash set.
|
||||
* @param element The element you want to insert.
|
||||
*/
|
||||
insert(element: K): void;
|
||||
eraseElementByKey(key: K): void;
|
||||
find(element: K): boolean;
|
||||
[Symbol.iterator](): Generator<K, void, unknown>;
|
||||
}
|
||||
export default HashSet;
|
||||
149
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.js
generated
vendored
Normal file
149
node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "t", {
|
||||
value: true
|
||||
});
|
||||
|
||||
exports.default = void 0;
|
||||
|
||||
var _Base = _interopRequireDefault(require("./Base"));
|
||||
|
||||
var _Vector = _interopRequireDefault(require("../SequentialContainer/Vector"));
|
||||
|
||||
var _OrderedSet = _interopRequireDefault(require("../TreeContainer/OrderedSet"));
|
||||
|
||||
function _interopRequireDefault(e) {
|
||||
return e && e.t ? e : {
|
||||
default: e
|
||||
};
|
||||
}
|
||||
|
||||
class HashSet extends _Base.default {
|
||||
constructor(e = [], t, s) {
|
||||
super(t, s);
|
||||
this.i = [];
|
||||
e.forEach((e => this.insert(e)));
|
||||
}
|
||||
h() {
|
||||
if (this.u >= 1073741824) return;
|
||||
const e = [];
|
||||
const t = this.u;
|
||||
this.u <<= 1;
|
||||
const s = Object.keys(this.i);
|
||||
const i = s.length;
|
||||
for (let r = 0; r < i; ++r) {
|
||||
const i = parseInt(s[r]);
|
||||
const n = this.i[i];
|
||||
const o = n.size();
|
||||
if (o === 0) continue;
|
||||
if (o === 1) {
|
||||
const t = n.front();
|
||||
e[this.l(t) & this.u - 1] = new _Vector.default([ t ], false);
|
||||
continue;
|
||||
}
|
||||
const c = [];
|
||||
const f = [];
|
||||
n.forEach((e => {
|
||||
const s = this.l(e);
|
||||
if ((s & t) === 0) {
|
||||
c.push(e);
|
||||
} else f.push(e);
|
||||
}));
|
||||
if (n instanceof _OrderedSet.default) {
|
||||
if (c.length > 6) {
|
||||
e[i] = new _OrderedSet.default(c);
|
||||
} else {
|
||||
e[i] = new _Vector.default(c, false);
|
||||
}
|
||||
if (f.length > 6) {
|
||||
e[i + t] = new _OrderedSet.default(f);
|
||||
} else {
|
||||
e[i + t] = new _Vector.default(f, false);
|
||||
}
|
||||
} else {
|
||||
e[i] = new _Vector.default(c, false);
|
||||
e[i + t] = new _Vector.default(f, false);
|
||||
}
|
||||
}
|
||||
this.i = e;
|
||||
}
|
||||
forEach(e) {
|
||||
const t = Object.values(this.i);
|
||||
const s = t.length;
|
||||
let i = 0;
|
||||
for (let r = 0; r < s; ++r) {
|
||||
t[r].forEach((t => e(t, i++)));
|
||||
}
|
||||
}
|
||||
insert(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) {
|
||||
this.i[t] = new _Vector.default([ e ], false);
|
||||
this.o += 1;
|
||||
} else {
|
||||
const i = s.size();
|
||||
if (s instanceof _Vector.default) {
|
||||
if (!s.find(e).equals(s.end())) return;
|
||||
s.pushBack(e);
|
||||
if (i + 1 >= 8) {
|
||||
if (this.u <= 64) {
|
||||
this.o += 1;
|
||||
this.h();
|
||||
return;
|
||||
}
|
||||
this.i[t] = new _OrderedSet.default(s);
|
||||
}
|
||||
this.o += 1;
|
||||
} else {
|
||||
s.insert(e);
|
||||
const t = s.size();
|
||||
this.o += t - i;
|
||||
}
|
||||
}
|
||||
if (this.o > this.u * .75) {
|
||||
this.h();
|
||||
}
|
||||
}
|
||||
eraseElementByKey(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) return;
|
||||
const i = s.size();
|
||||
if (i === 0) return;
|
||||
if (s instanceof _Vector.default) {
|
||||
s.eraseElementByValue(e);
|
||||
const t = s.size();
|
||||
this.o += t - i;
|
||||
} else {
|
||||
s.eraseElementByKey(e);
|
||||
const r = s.size();
|
||||
this.o += r - i;
|
||||
if (r <= 6) {
|
||||
this.i[t] = new _Vector.default(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
find(e) {
|
||||
const t = this.l(e) & this.u - 1;
|
||||
const s = this.i[t];
|
||||
if (!s) return false;
|
||||
return !s.find(e).equals(s.end());
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return function*() {
|
||||
const e = Object.values(this.i);
|
||||
const t = e.length;
|
||||
for (let s = 0; s < t; ++s) {
|
||||
const t = e[s];
|
||||
for (const e of t) {
|
||||
yield e;
|
||||
}
|
||||
}
|
||||
}.bind(this)();
|
||||
}
|
||||
}
|
||||
|
||||
var _default = HashSet;
|
||||
|
||||
exports.default = _default;
|
||||
Reference in New Issue
Block a user