mqtt and socket added
This commit is contained in:
13
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/RandomIterator.d.ts
generated
vendored
Normal file
13
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/RandomIterator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ContainerIterator } from "../../ContainerBase/index";
|
||||
export declare abstract class RandomIterator<T> extends ContainerIterator<T> {
|
||||
protected node: number;
|
||||
protected readonly size: () => number;
|
||||
protected readonly getElementByPos: (pos: number) => T;
|
||||
protected readonly setElementByPos: (pos: number, element: T) => void;
|
||||
pre: () => this;
|
||||
next: () => this;
|
||||
constructor(index: number, size: () => number, getElementByPos: (pos: number) => T, setElementByPos: (pos: number, element: T) => void, iteratorType?: boolean);
|
||||
get pointer(): T;
|
||||
set pointer(newValue: T);
|
||||
equals(obj: RandomIterator<T>): boolean;
|
||||
}
|
||||
77
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/RandomIterator.js
generated
vendored
Normal file
77
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/RandomIterator.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { checkWithinAccessParams } from "../../../utils/checkParams";
|
||||
import { ContainerIterator } from "../../ContainerBase/index";
|
||||
var RandomIterator = /** @class */ (function (_super) {
|
||||
__extends(RandomIterator, _super);
|
||||
function RandomIterator(index, size, getElementByPos, setElementByPos, iteratorType) {
|
||||
var _this = _super.call(this, iteratorType) || this;
|
||||
_this.node = index;
|
||||
_this.size = size;
|
||||
_this.getElementByPos = getElementByPos;
|
||||
_this.setElementByPos = setElementByPos;
|
||||
if (_this.iteratorType === ContainerIterator.NORMAL) {
|
||||
_this.pre = function () {
|
||||
if (this.node === 0) {
|
||||
throw new RangeError('Deque iterator access denied!');
|
||||
}
|
||||
this.node -= 1;
|
||||
return this;
|
||||
};
|
||||
_this.next = function () {
|
||||
if (this.node === this.size()) {
|
||||
throw new RangeError('Deque Iterator access denied!');
|
||||
}
|
||||
this.node += 1;
|
||||
return this;
|
||||
};
|
||||
}
|
||||
else {
|
||||
_this.pre = function () {
|
||||
if (this.node === this.size() - 1) {
|
||||
throw new RangeError('Deque iterator access denied!');
|
||||
}
|
||||
this.node += 1;
|
||||
return this;
|
||||
};
|
||||
_this.next = function () {
|
||||
if (this.node === -1) {
|
||||
throw new RangeError('Deque iterator access denied!');
|
||||
}
|
||||
this.node -= 1;
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(RandomIterator.prototype, "pointer", {
|
||||
get: function () {
|
||||
checkWithinAccessParams(this.node, 0, this.size() - 1);
|
||||
return this.getElementByPos(this.node);
|
||||
},
|
||||
set: function (newValue) {
|
||||
checkWithinAccessParams(this.node, 0, this.size() - 1);
|
||||
this.setElementByPos(this.node, newValue);
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
RandomIterator.prototype.equals = function (obj) {
|
||||
return this.node === obj.node;
|
||||
};
|
||||
return RandomIterator;
|
||||
}(ContainerIterator));
|
||||
export { RandomIterator };
|
||||
44
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/index.d.ts
generated
vendored
Normal file
44
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Container } from "../../ContainerBase/index";
|
||||
declare abstract class SequentialContainer<T> extends Container<T> {
|
||||
/**
|
||||
* @description Push the element to the back.
|
||||
* @param element The element you want to push.
|
||||
*/
|
||||
abstract pushBack(element: T): void;
|
||||
/**
|
||||
* @description Removes the last element.
|
||||
*/
|
||||
abstract popBack(): void;
|
||||
/**
|
||||
* @description Sets element by position.
|
||||
* @param pos The position you want to change.
|
||||
* @param element The element's value you want to update.
|
||||
*/
|
||||
abstract setElementByPos(pos: number, element: T): void;
|
||||
/**
|
||||
* @description Removes the elements of the specified value.
|
||||
* @param value The value you want to remove.
|
||||
*/
|
||||
abstract eraseElementByValue(value: T): void;
|
||||
/**
|
||||
* @description Insert several elements after the specified position.
|
||||
* @param pos The position you want to insert.
|
||||
* @param element The element you want to insert.
|
||||
* @param num The number of elements you want to insert (default 1).
|
||||
*/
|
||||
abstract insert(pos: number, element: T, num?: number): void;
|
||||
/**
|
||||
* @description Reverses the container.
|
||||
*/
|
||||
abstract reverse(): void;
|
||||
/**
|
||||
* @description Removes the duplication of elements in the container.
|
||||
*/
|
||||
abstract unique(): void;
|
||||
/**
|
||||
* @description Sort the container.
|
||||
* @param cmp Comparison function.
|
||||
*/
|
||||
abstract sort(cmp?: (x: T, y: T) => number): void;
|
||||
}
|
||||
export default SequentialContainer;
|
||||
24
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/index.js
generated
vendored
Normal file
24
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Base/index.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { Container } from "../../ContainerBase/index";
|
||||
var SequentialContainer = /** @class */ (function (_super) {
|
||||
__extends(SequentialContainer, _super);
|
||||
function SequentialContainer() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return SequentialContainer;
|
||||
}(Container));
|
||||
export default SequentialContainer;
|
||||
68
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Deque.d.ts
generated
vendored
Normal file
68
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Deque.d.ts
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import SequentialContainer from './Base/index';
|
||||
import { initContainer } from "../ContainerBase/index";
|
||||
import { RandomIterator } from "./Base/RandomIterator";
|
||||
export declare class DequeIterator<T> extends RandomIterator<T> {
|
||||
copy(): DequeIterator<T>;
|
||||
}
|
||||
declare class Deque<T> extends SequentialContainer<T> {
|
||||
private first;
|
||||
private curFirst;
|
||||
private last;
|
||||
private curLast;
|
||||
private bucketNum;
|
||||
private readonly bucketSize;
|
||||
private map;
|
||||
constructor(container?: initContainer<T>, bucketSize?: number);
|
||||
/**
|
||||
* @description Growth the Deque.
|
||||
* @private
|
||||
*/
|
||||
private reAllocate;
|
||||
/**
|
||||
* @description Get the bucket position of the element and the pointer position by index.
|
||||
* @param pos The element's index.
|
||||
* @private
|
||||
*/
|
||||
private getElementIndex;
|
||||
clear(): void;
|
||||
front(): T | undefined;
|
||||
back(): T | undefined;
|
||||
begin(): DequeIterator<T>;
|
||||
end(): DequeIterator<T>;
|
||||
rBegin(): DequeIterator<T>;
|
||||
rEnd(): DequeIterator<T>;
|
||||
pushBack(element: T): void;
|
||||
popBack(): void;
|
||||
/**
|
||||
* @description Push the element to the front.
|
||||
* @param element The element you want to push.
|
||||
*/
|
||||
pushFront(element: T): void;
|
||||
/**
|
||||
* @description Remove the first element.
|
||||
*/
|
||||
popFront(): void;
|
||||
forEach(callback: (element: T, index: number) => void): void;
|
||||
getElementByPos(pos: number): T;
|
||||
setElementByPos(pos: number, element: T): void;
|
||||
insert(pos: number, element: T, num?: number): void;
|
||||
/**
|
||||
* @description Remove all elements after the specified position (excluding the specified position).
|
||||
* @param pos The previous position of the first removed element.
|
||||
* @example deque.cut(1); // Then deque's size will be 2. deque -> [0, 1]
|
||||
*/
|
||||
cut(pos: number): void;
|
||||
eraseElementByPos(pos: number): void;
|
||||
eraseElementByValue(value: T): void;
|
||||
eraseElementByIterator(iter: DequeIterator<T>): DequeIterator<T>;
|
||||
find(element: T): DequeIterator<T>;
|
||||
reverse(): void;
|
||||
unique(): void;
|
||||
sort(cmp?: (x: T, y: T) => number): void;
|
||||
/**
|
||||
* @description Remove as much useless space as possible.
|
||||
*/
|
||||
shrinkToFit(): void;
|
||||
[Symbol.iterator](): Generator<T, void, unknown>;
|
||||
}
|
||||
export default Deque;
|
||||
450
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Deque.js
generated
vendored
Normal file
450
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Deque.js
generated
vendored
Normal file
@@ -0,0 +1,450 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
import SequentialContainer from './Base/index';
|
||||
import { checkWithinAccessParams } from "../../utils/checkParams";
|
||||
import { ContainerIterator } from "../ContainerBase/index";
|
||||
import { RandomIterator } from "./Base/RandomIterator";
|
||||
var DequeIterator = /** @class */ (function (_super) {
|
||||
__extends(DequeIterator, _super);
|
||||
function DequeIterator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
DequeIterator.prototype.copy = function () {
|
||||
return new DequeIterator(this.node, this.size, this.getElementByPos, this.setElementByPos, this.iteratorType);
|
||||
};
|
||||
return DequeIterator;
|
||||
}(RandomIterator));
|
||||
export { DequeIterator };
|
||||
var Deque = /** @class */ (function (_super) {
|
||||
__extends(Deque, _super);
|
||||
function Deque(container, bucketSize) {
|
||||
if (container === void 0) { container = []; }
|
||||
if (bucketSize === void 0) { bucketSize = (1 << 12); }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.first = 0;
|
||||
_this.curFirst = 0;
|
||||
_this.last = 0;
|
||||
_this.curLast = 0;
|
||||
_this.bucketNum = 0;
|
||||
_this.map = [];
|
||||
var _length;
|
||||
if ('size' in container) {
|
||||
if (typeof container.size === 'number') {
|
||||
_length = container.size;
|
||||
}
|
||||
else {
|
||||
_length = container.size();
|
||||
}
|
||||
}
|
||||
else if ('length' in container) {
|
||||
_length = container.length;
|
||||
}
|
||||
else {
|
||||
throw new RangeError('Can\'t get container\'s size!');
|
||||
}
|
||||
_this.bucketSize = bucketSize;
|
||||
_this.bucketNum = Math.max(Math.ceil(_length / _this.bucketSize), 1);
|
||||
for (var i = 0; i < _this.bucketNum; ++i) {
|
||||
_this.map.push(new Array(_this.bucketSize));
|
||||
}
|
||||
var needBucketNum = Math.ceil(_length / _this.bucketSize);
|
||||
_this.first = _this.last = (_this.bucketNum >> 1) - (needBucketNum >> 1);
|
||||
_this.curFirst = _this.curLast = (_this.bucketSize - _length % _this.bucketSize) >> 1;
|
||||
container.forEach(function (element) { return _this.pushBack(element); });
|
||||
_this.size = _this.size.bind(_this);
|
||||
_this.getElementByPos = _this.getElementByPos.bind(_this);
|
||||
_this.setElementByPos = _this.setElementByPos.bind(_this);
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @description Growth the Deque.
|
||||
* @private
|
||||
*/
|
||||
Deque.prototype.reAllocate = function () {
|
||||
var newMap = [];
|
||||
var addBucketNum = Math.max(this.bucketNum >> 1, 1);
|
||||
for (var i = 0; i < addBucketNum; ++i) {
|
||||
newMap[i] = new Array(this.bucketSize);
|
||||
}
|
||||
for (var i = this.first; i < this.bucketNum; ++i) {
|
||||
newMap[newMap.length] = this.map[i];
|
||||
}
|
||||
for (var i = 0; i < this.last; ++i) {
|
||||
newMap[newMap.length] = this.map[i];
|
||||
}
|
||||
newMap[newMap.length] = __spreadArray([], __read(this.map[this.last]), false);
|
||||
this.first = addBucketNum;
|
||||
this.last = newMap.length - 1;
|
||||
for (var i = 0; i < addBucketNum; ++i) {
|
||||
newMap[newMap.length] = new Array(this.bucketSize);
|
||||
}
|
||||
this.map = newMap;
|
||||
this.bucketNum = newMap.length;
|
||||
};
|
||||
/**
|
||||
* @description Get the bucket position of the element and the pointer position by index.
|
||||
* @param pos The element's index.
|
||||
* @private
|
||||
*/
|
||||
Deque.prototype.getElementIndex = function (pos) {
|
||||
var offset = this.curFirst + pos + 1;
|
||||
var offsetRemainder = offset % this.bucketSize;
|
||||
var curNodePointerIndex = offsetRemainder - 1;
|
||||
var curNodeBucketIndex = this.first + (offset - offsetRemainder) / this.bucketSize;
|
||||
if (offsetRemainder === 0)
|
||||
curNodeBucketIndex -= 1;
|
||||
curNodeBucketIndex %= this.bucketNum;
|
||||
if (curNodePointerIndex < 0)
|
||||
curNodePointerIndex += this.bucketSize;
|
||||
return { curNodeBucketIndex: curNodeBucketIndex, curNodePointerIndex: curNodePointerIndex };
|
||||
};
|
||||
Deque.prototype.clear = function () {
|
||||
this.map = [[]];
|
||||
this.bucketNum = 1;
|
||||
this.first = this.last = this.length = 0;
|
||||
this.curFirst = this.curLast = this.bucketSize >> 1;
|
||||
};
|
||||
Deque.prototype.front = function () {
|
||||
return this.map[this.first][this.curFirst];
|
||||
};
|
||||
Deque.prototype.back = function () {
|
||||
return this.map[this.last][this.curLast];
|
||||
};
|
||||
Deque.prototype.begin = function () {
|
||||
return new DequeIterator(0, this.size, this.getElementByPos, this.setElementByPos);
|
||||
};
|
||||
Deque.prototype.end = function () {
|
||||
return new DequeIterator(this.length, this.size, this.getElementByPos, this.setElementByPos);
|
||||
};
|
||||
Deque.prototype.rBegin = function () {
|
||||
return new DequeIterator(this.length - 1, this.size, this.getElementByPos, this.setElementByPos, ContainerIterator.REVERSE);
|
||||
};
|
||||
Deque.prototype.rEnd = function () {
|
||||
return new DequeIterator(-1, this.size, this.getElementByPos, this.setElementByPos, ContainerIterator.REVERSE);
|
||||
};
|
||||
Deque.prototype.pushBack = function (element) {
|
||||
if (this.length) {
|
||||
if (this.curLast < this.bucketSize - 1) {
|
||||
this.curLast += 1;
|
||||
}
|
||||
else if (this.last < this.bucketNum - 1) {
|
||||
this.last += 1;
|
||||
this.curLast = 0;
|
||||
}
|
||||
else {
|
||||
this.last = 0;
|
||||
this.curLast = 0;
|
||||
}
|
||||
if (this.last === this.first &&
|
||||
this.curLast === this.curFirst)
|
||||
this.reAllocate();
|
||||
}
|
||||
this.length += 1;
|
||||
this.map[this.last][this.curLast] = element;
|
||||
};
|
||||
Deque.prototype.popBack = function () {
|
||||
if (!this.length)
|
||||
return;
|
||||
this.map[this.last][this.curLast] = undefined;
|
||||
if (this.length !== 1) {
|
||||
if (this.curLast > 0) {
|
||||
this.curLast -= 1;
|
||||
}
|
||||
else if (this.last > 0) {
|
||||
this.last -= 1;
|
||||
this.curLast = this.bucketSize - 1;
|
||||
}
|
||||
else {
|
||||
this.last = this.bucketNum - 1;
|
||||
this.curLast = this.bucketSize - 1;
|
||||
}
|
||||
}
|
||||
this.length -= 1;
|
||||
};
|
||||
/**
|
||||
* @description Push the element to the front.
|
||||
* @param element The element you want to push.
|
||||
*/
|
||||
Deque.prototype.pushFront = function (element) {
|
||||
if (this.length) {
|
||||
if (this.curFirst > 0) {
|
||||
this.curFirst -= 1;
|
||||
}
|
||||
else if (this.first > 0) {
|
||||
this.first -= 1;
|
||||
this.curFirst = this.bucketSize - 1;
|
||||
}
|
||||
else {
|
||||
this.first = this.bucketNum - 1;
|
||||
this.curFirst = this.bucketSize - 1;
|
||||
}
|
||||
if (this.first === this.last &&
|
||||
this.curFirst === this.curLast)
|
||||
this.reAllocate();
|
||||
}
|
||||
this.length += 1;
|
||||
this.map[this.first][this.curFirst] = element;
|
||||
};
|
||||
/**
|
||||
* @description Remove the first element.
|
||||
*/
|
||||
Deque.prototype.popFront = function () {
|
||||
if (!this.length)
|
||||
return;
|
||||
this.map[this.first][this.curFirst] = undefined;
|
||||
if (this.length !== 1) {
|
||||
if (this.curFirst < this.bucketSize - 1) {
|
||||
this.curFirst += 1;
|
||||
}
|
||||
else if (this.first < this.bucketNum - 1) {
|
||||
this.first += 1;
|
||||
this.curFirst = 0;
|
||||
}
|
||||
else {
|
||||
this.first = 0;
|
||||
this.curFirst = 0;
|
||||
}
|
||||
}
|
||||
this.length -= 1;
|
||||
};
|
||||
Deque.prototype.forEach = function (callback) {
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
callback(this.getElementByPos(i), i);
|
||||
}
|
||||
};
|
||||
Deque.prototype.getElementByPos = function (pos) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
var _a = this.getElementIndex(pos), curNodeBucketIndex = _a.curNodeBucketIndex, curNodePointerIndex = _a.curNodePointerIndex;
|
||||
return this.map[curNodeBucketIndex][curNodePointerIndex];
|
||||
};
|
||||
Deque.prototype.setElementByPos = function (pos, element) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
var _a = this.getElementIndex(pos), curNodeBucketIndex = _a.curNodeBucketIndex, curNodePointerIndex = _a.curNodePointerIndex;
|
||||
this.map[curNodeBucketIndex][curNodePointerIndex] = element;
|
||||
};
|
||||
Deque.prototype.insert = function (pos, element, num) {
|
||||
if (num === void 0) { num = 1; }
|
||||
checkWithinAccessParams(pos, 0, this.length);
|
||||
if (pos === 0) {
|
||||
while (num--)
|
||||
this.pushFront(element);
|
||||
}
|
||||
else if (pos === this.length) {
|
||||
while (num--)
|
||||
this.pushBack(element);
|
||||
}
|
||||
else {
|
||||
var arr = [];
|
||||
for (var i = pos; i < this.length; ++i) {
|
||||
arr.push(this.getElementByPos(i));
|
||||
}
|
||||
this.cut(pos - 1);
|
||||
for (var i = 0; i < num; ++i)
|
||||
this.pushBack(element);
|
||||
for (var i = 0; i < arr.length; ++i)
|
||||
this.pushBack(arr[i]);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @description Remove all elements after the specified position (excluding the specified position).
|
||||
* @param pos The previous position of the first removed element.
|
||||
* @example deque.cut(1); // Then deque's size will be 2. deque -> [0, 1]
|
||||
*/
|
||||
Deque.prototype.cut = function (pos) {
|
||||
if (pos < 0) {
|
||||
this.clear();
|
||||
return;
|
||||
}
|
||||
var _a = this.getElementIndex(pos), curNodeBucketIndex = _a.curNodeBucketIndex, curNodePointerIndex = _a.curNodePointerIndex;
|
||||
this.last = curNodeBucketIndex;
|
||||
this.curLast = curNodePointerIndex;
|
||||
this.length = pos + 1;
|
||||
};
|
||||
Deque.prototype.eraseElementByPos = function (pos) {
|
||||
var _this = this;
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
if (pos === 0)
|
||||
this.popFront();
|
||||
else if (pos === this.length - 1)
|
||||
this.popBack();
|
||||
else {
|
||||
var arr = [];
|
||||
for (var i = pos + 1; i < this.length; ++i) {
|
||||
arr.push(this.getElementByPos(i));
|
||||
}
|
||||
this.cut(pos);
|
||||
this.popBack();
|
||||
arr.forEach(function (element) { return _this.pushBack(element); });
|
||||
}
|
||||
};
|
||||
Deque.prototype.eraseElementByValue = function (value) {
|
||||
if (!this.length)
|
||||
return;
|
||||
var arr = [];
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
var element = this.getElementByPos(i);
|
||||
if (element !== value)
|
||||
arr.push(element);
|
||||
}
|
||||
var _length = arr.length;
|
||||
for (var i = 0; i < _length; ++i)
|
||||
this.setElementByPos(i, arr[i]);
|
||||
this.cut(_length - 1);
|
||||
};
|
||||
Deque.prototype.eraseElementByIterator = function (iter) {
|
||||
// @ts-ignore
|
||||
var node = iter.node;
|
||||
this.eraseElementByPos(node);
|
||||
iter = iter.next();
|
||||
return iter;
|
||||
};
|
||||
Deque.prototype.find = function (element) {
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
if (this.getElementByPos(i) === element) {
|
||||
return new DequeIterator(i, this.size, this.getElementByPos, this.setElementByPos);
|
||||
}
|
||||
}
|
||||
return this.end();
|
||||
};
|
||||
Deque.prototype.reverse = function () {
|
||||
var l = 0;
|
||||
var r = this.length - 1;
|
||||
while (l < r) {
|
||||
var tmp = this.getElementByPos(l);
|
||||
this.setElementByPos(l, this.getElementByPos(r));
|
||||
this.setElementByPos(r, tmp);
|
||||
l += 1;
|
||||
r -= 1;
|
||||
}
|
||||
};
|
||||
Deque.prototype.unique = function () {
|
||||
if (this.length <= 1)
|
||||
return;
|
||||
var index = 1;
|
||||
var pre = this.getElementByPos(0);
|
||||
for (var i = 1; i < this.length; ++i) {
|
||||
var cur = this.getElementByPos(i);
|
||||
if (cur !== pre) {
|
||||
pre = cur;
|
||||
this.setElementByPos(index++, cur);
|
||||
}
|
||||
}
|
||||
while (this.length > index)
|
||||
this.popBack();
|
||||
};
|
||||
Deque.prototype.sort = function (cmp) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
arr.push(this.getElementByPos(i));
|
||||
}
|
||||
arr.sort(cmp);
|
||||
for (var i = 0; i < this.length; ++i)
|
||||
this.setElementByPos(i, arr[i]);
|
||||
};
|
||||
/**
|
||||
* @description Remove as much useless space as possible.
|
||||
*/
|
||||
Deque.prototype.shrinkToFit = function () {
|
||||
if (!this.length)
|
||||
return;
|
||||
var arr = [];
|
||||
this.forEach(function (element) { return arr.push(element); });
|
||||
this.bucketNum = Math.max(Math.ceil(this.length / this.bucketSize), 1);
|
||||
this.length = this.first = this.last = this.curFirst = this.curLast = 0;
|
||||
this.map = [];
|
||||
for (var i = 0; i < this.bucketNum; ++i) {
|
||||
this.map.push(new Array(this.bucketSize));
|
||||
}
|
||||
for (var i = 0; i < arr.length; ++i)
|
||||
this.pushBack(arr[i]);
|
||||
};
|
||||
Deque.prototype[Symbol.iterator] = function () {
|
||||
return function () {
|
||||
var i;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
i = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(i < this.length)) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, this.getElementByPos(i)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
++i;
|
||||
return [3 /*break*/, 1];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}.bind(this)();
|
||||
};
|
||||
return Deque;
|
||||
}(SequentialContainer));
|
||||
export default Deque;
|
||||
61
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/LinkList.d.ts
generated
vendored
Normal file
61
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/LinkList.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import SequentialContainer from './Base/index';
|
||||
import { ContainerIterator, initContainer } from "../ContainerBase/index";
|
||||
export declare class LinkNode<T> {
|
||||
value: T | undefined;
|
||||
pre: LinkNode<T> | undefined;
|
||||
next: LinkNode<T> | undefined;
|
||||
constructor(element?: T);
|
||||
}
|
||||
export declare class LinkListIterator<T> extends ContainerIterator<T> {
|
||||
protected node: LinkNode<T>;
|
||||
private readonly header;
|
||||
pre: () => this;
|
||||
next: () => this;
|
||||
constructor(node: LinkNode<T>, header: LinkNode<T>, iteratorType?: boolean);
|
||||
get pointer(): T;
|
||||
set pointer(newValue: T);
|
||||
equals(obj: LinkListIterator<T>): boolean;
|
||||
copy(): LinkListIterator<T>;
|
||||
}
|
||||
declare class LinkList<T> extends SequentialContainer<T> {
|
||||
private header;
|
||||
private head;
|
||||
private tail;
|
||||
constructor(container?: initContainer<T>);
|
||||
clear(): void;
|
||||
begin(): LinkListIterator<T>;
|
||||
end(): LinkListIterator<T>;
|
||||
rBegin(): LinkListIterator<T>;
|
||||
rEnd(): LinkListIterator<T>;
|
||||
front(): T | undefined;
|
||||
back(): T | undefined;
|
||||
forEach(callback: (element: T, index: number) => void): void;
|
||||
getElementByPos(pos: number): T;
|
||||
eraseElementByPos(pos: number): void;
|
||||
eraseElementByValue(value: T): void;
|
||||
eraseElementByIterator(iter: LinkListIterator<T>): LinkListIterator<T>;
|
||||
pushBack(element: T): void;
|
||||
popBack(): void;
|
||||
setElementByPos(pos: number, element: T): void;
|
||||
insert(pos: number, element: T, num?: number): void;
|
||||
find(element: T): LinkListIterator<T>;
|
||||
reverse(): void;
|
||||
unique(): void;
|
||||
sort(cmp?: (x: T, y: T) => number): void;
|
||||
/**
|
||||
* @description Push an element to the front.
|
||||
* @param element The element you want to push.
|
||||
*/
|
||||
pushFront(element: T): void;
|
||||
/**
|
||||
* @description Removes the first element.
|
||||
*/
|
||||
popFront(): void;
|
||||
/**
|
||||
* @description Merges two sorted lists.
|
||||
* @param list The other list you want to merge (must be sorted).
|
||||
*/
|
||||
merge(list: LinkList<T>): void;
|
||||
[Symbol.iterator](): Generator<T, void, unknown>;
|
||||
}
|
||||
export default LinkList;
|
||||
458
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/LinkList.js
generated
vendored
Normal file
458
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/LinkList.js
generated
vendored
Normal file
@@ -0,0 +1,458 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
import SequentialContainer from './Base/index';
|
||||
import { checkWithinAccessParams } from "../../utils/checkParams";
|
||||
import { ContainerIterator } from "../ContainerBase/index";
|
||||
var LinkNode = /** @class */ (function () {
|
||||
function LinkNode(element) {
|
||||
this.value = undefined;
|
||||
this.pre = undefined;
|
||||
this.next = undefined;
|
||||
this.value = element;
|
||||
}
|
||||
return LinkNode;
|
||||
}());
|
||||
export { LinkNode };
|
||||
var LinkListIterator = /** @class */ (function (_super) {
|
||||
__extends(LinkListIterator, _super);
|
||||
function LinkListIterator(node, header, iteratorType) {
|
||||
var _this = _super.call(this, iteratorType) || this;
|
||||
_this.node = node;
|
||||
_this.header = header;
|
||||
if (_this.iteratorType === ContainerIterator.NORMAL) {
|
||||
_this.pre = function () {
|
||||
if (this.node.pre === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
this.node = this.node.pre;
|
||||
return this;
|
||||
};
|
||||
_this.next = function () {
|
||||
if (this.node === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
this.node = this.node.next;
|
||||
return this;
|
||||
};
|
||||
}
|
||||
else {
|
||||
_this.pre = function () {
|
||||
if (this.node.next === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
this.node = this.node.next;
|
||||
return this;
|
||||
};
|
||||
_this.next = function () {
|
||||
if (this.node === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
this.node = this.node.pre;
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(LinkListIterator.prototype, "pointer", {
|
||||
get: function () {
|
||||
if (this.node === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
return this.node.value;
|
||||
},
|
||||
set: function (newValue) {
|
||||
if (this.node === this.header) {
|
||||
throw new RangeError('LinkList iterator access denied!');
|
||||
}
|
||||
this.node.value = newValue;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
LinkListIterator.prototype.equals = function (obj) {
|
||||
return this.node === obj.node;
|
||||
};
|
||||
LinkListIterator.prototype.copy = function () {
|
||||
return new LinkListIterator(this.node, this.header, this.iteratorType);
|
||||
};
|
||||
return LinkListIterator;
|
||||
}(ContainerIterator));
|
||||
export { LinkListIterator };
|
||||
var LinkList = /** @class */ (function (_super) {
|
||||
__extends(LinkList, _super);
|
||||
function LinkList(container) {
|
||||
if (container === void 0) { container = []; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.header = new LinkNode();
|
||||
_this.head = undefined;
|
||||
_this.tail = undefined;
|
||||
container.forEach(function (element) { return _this.pushBack(element); });
|
||||
return _this;
|
||||
}
|
||||
LinkList.prototype.clear = function () {
|
||||
this.length = 0;
|
||||
this.head = this.tail = undefined;
|
||||
this.header.pre = this.header.next = undefined;
|
||||
};
|
||||
LinkList.prototype.begin = function () {
|
||||
return new LinkListIterator(this.head || this.header, this.header);
|
||||
};
|
||||
LinkList.prototype.end = function () {
|
||||
return new LinkListIterator(this.header, this.header);
|
||||
};
|
||||
LinkList.prototype.rBegin = function () {
|
||||
return new LinkListIterator(this.tail || this.header, this.header, ContainerIterator.REVERSE);
|
||||
};
|
||||
LinkList.prototype.rEnd = function () {
|
||||
return new LinkListIterator(this.header, this.header, ContainerIterator.REVERSE);
|
||||
};
|
||||
LinkList.prototype.front = function () {
|
||||
return this.head ? this.head.value : undefined;
|
||||
};
|
||||
LinkList.prototype.back = function () {
|
||||
return this.tail ? this.tail.value : undefined;
|
||||
};
|
||||
LinkList.prototype.forEach = function (callback) {
|
||||
if (!this.length)
|
||||
return;
|
||||
var curNode = this.head;
|
||||
var index = 0;
|
||||
while (curNode !== this.header) {
|
||||
callback(curNode.value, index++);
|
||||
curNode = curNode.next;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.getElementByPos = function (pos) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
var curNode = this.head;
|
||||
while (pos--) {
|
||||
curNode = curNode.next;
|
||||
}
|
||||
return curNode.value;
|
||||
};
|
||||
LinkList.prototype.eraseElementByPos = function (pos) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
if (pos === 0)
|
||||
this.popFront();
|
||||
else if (pos === this.length - 1)
|
||||
this.popBack();
|
||||
else {
|
||||
var curNode = this.head;
|
||||
while (pos--) {
|
||||
curNode = curNode.next;
|
||||
}
|
||||
curNode = curNode;
|
||||
var pre = curNode.pre;
|
||||
var next = curNode.next;
|
||||
next.pre = pre;
|
||||
pre.next = next;
|
||||
this.length -= 1;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.eraseElementByValue = function (value) {
|
||||
while (this.head && this.head.value === value)
|
||||
this.popFront();
|
||||
while (this.tail && this.tail.value === value)
|
||||
this.popBack();
|
||||
if (!this.head)
|
||||
return;
|
||||
var curNode = this.head;
|
||||
while (curNode !== this.header) {
|
||||
if (curNode.value === value) {
|
||||
var pre = curNode.pre;
|
||||
var next = curNode.next;
|
||||
if (next)
|
||||
next.pre = pre;
|
||||
if (pre)
|
||||
pre.next = next;
|
||||
this.length -= 1;
|
||||
}
|
||||
curNode = curNode.next;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.eraseElementByIterator = function (iter) {
|
||||
// @ts-ignore
|
||||
var node = iter.node;
|
||||
if (node === this.header) {
|
||||
throw new RangeError('Invalid iterator');
|
||||
}
|
||||
iter = iter.next();
|
||||
if (this.head === node)
|
||||
this.popFront();
|
||||
else if (this.tail === node)
|
||||
this.popBack();
|
||||
else {
|
||||
var pre = node.pre;
|
||||
var next = node.next;
|
||||
if (next)
|
||||
next.pre = pre;
|
||||
if (pre)
|
||||
pre.next = next;
|
||||
this.length -= 1;
|
||||
}
|
||||
return iter;
|
||||
};
|
||||
LinkList.prototype.pushBack = function (element) {
|
||||
this.length += 1;
|
||||
var newTail = new LinkNode(element);
|
||||
if (!this.tail) {
|
||||
this.head = this.tail = newTail;
|
||||
this.header.next = this.head;
|
||||
this.head.pre = this.header;
|
||||
}
|
||||
else {
|
||||
this.tail.next = newTail;
|
||||
newTail.pre = this.tail;
|
||||
this.tail = newTail;
|
||||
}
|
||||
this.tail.next = this.header;
|
||||
this.header.pre = this.tail;
|
||||
};
|
||||
LinkList.prototype.popBack = function () {
|
||||
if (!this.tail)
|
||||
return;
|
||||
this.length -= 1;
|
||||
if (this.head === this.tail) {
|
||||
this.head = this.tail = undefined;
|
||||
this.header.next = undefined;
|
||||
}
|
||||
else {
|
||||
this.tail = this.tail.pre;
|
||||
if (this.tail)
|
||||
this.tail.next = undefined;
|
||||
}
|
||||
this.header.pre = this.tail;
|
||||
if (this.tail)
|
||||
this.tail.next = this.header;
|
||||
};
|
||||
LinkList.prototype.setElementByPos = function (pos, element) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
var curNode = this.head;
|
||||
while (pos--) {
|
||||
curNode = curNode.next;
|
||||
}
|
||||
curNode.value = element;
|
||||
};
|
||||
LinkList.prototype.insert = function (pos, element, num) {
|
||||
if (num === void 0) { num = 1; }
|
||||
checkWithinAccessParams(pos, 0, this.length);
|
||||
if (num <= 0)
|
||||
return;
|
||||
if (pos === 0) {
|
||||
while (num--)
|
||||
this.pushFront(element);
|
||||
}
|
||||
else if (pos === this.length) {
|
||||
while (num--)
|
||||
this.pushBack(element);
|
||||
}
|
||||
else {
|
||||
var curNode = this.head;
|
||||
for (var i = 1; i < pos; ++i) {
|
||||
curNode = curNode.next;
|
||||
}
|
||||
var next = curNode.next;
|
||||
this.length += num;
|
||||
while (num--) {
|
||||
curNode.next = new LinkNode(element);
|
||||
curNode.next.pre = curNode;
|
||||
curNode = curNode.next;
|
||||
}
|
||||
curNode.next = next;
|
||||
if (next)
|
||||
next.pre = curNode;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.find = function (element) {
|
||||
if (!this.head)
|
||||
return this.end();
|
||||
var curNode = this.head;
|
||||
while (curNode !== this.header) {
|
||||
if (curNode.value === element) {
|
||||
return new LinkListIterator(curNode, this.header);
|
||||
}
|
||||
curNode = curNode.next;
|
||||
}
|
||||
return this.end();
|
||||
};
|
||||
LinkList.prototype.reverse = function () {
|
||||
if (this.length <= 1)
|
||||
return;
|
||||
var pHead = this.head;
|
||||
var pTail = this.tail;
|
||||
var cnt = 0;
|
||||
while ((cnt << 1) < this.length) {
|
||||
var tmp = pHead.value;
|
||||
pHead.value = pTail.value;
|
||||
pTail.value = tmp;
|
||||
pHead = pHead.next;
|
||||
pTail = pTail.pre;
|
||||
cnt += 1;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.unique = function () {
|
||||
if (this.length <= 1)
|
||||
return;
|
||||
var curNode = this.head;
|
||||
while (curNode !== this.header) {
|
||||
var tmpNode = curNode;
|
||||
while (tmpNode.next && tmpNode.value === tmpNode.next.value) {
|
||||
tmpNode = tmpNode.next;
|
||||
this.length -= 1;
|
||||
}
|
||||
curNode.next = tmpNode.next;
|
||||
if (curNode.next)
|
||||
curNode.next.pre = curNode;
|
||||
curNode = curNode.next;
|
||||
}
|
||||
};
|
||||
LinkList.prototype.sort = function (cmp) {
|
||||
if (this.length <= 1)
|
||||
return;
|
||||
var arr = [];
|
||||
this.forEach(function (element) { return arr.push(element); });
|
||||
arr.sort(cmp);
|
||||
var curNode = this.head;
|
||||
arr.forEach(function (element) {
|
||||
curNode.value = element;
|
||||
curNode = curNode.next;
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @description Push an element to the front.
|
||||
* @param element The element you want to push.
|
||||
*/
|
||||
LinkList.prototype.pushFront = function (element) {
|
||||
this.length += 1;
|
||||
var newHead = new LinkNode(element);
|
||||
if (!this.head) {
|
||||
this.head = this.tail = newHead;
|
||||
this.tail.next = this.header;
|
||||
this.header.pre = this.tail;
|
||||
}
|
||||
else {
|
||||
newHead.next = this.head;
|
||||
this.head.pre = newHead;
|
||||
this.head = newHead;
|
||||
}
|
||||
this.header.next = this.head;
|
||||
this.head.pre = this.header;
|
||||
};
|
||||
/**
|
||||
* @description Removes the first element.
|
||||
*/
|
||||
LinkList.prototype.popFront = function () {
|
||||
if (!this.head)
|
||||
return;
|
||||
this.length -= 1;
|
||||
if (this.head === this.tail) {
|
||||
this.head = this.tail = undefined;
|
||||
this.header.pre = this.tail;
|
||||
}
|
||||
else {
|
||||
this.head = this.head.next;
|
||||
if (this.head)
|
||||
this.head.pre = this.header;
|
||||
}
|
||||
this.header.next = this.head;
|
||||
};
|
||||
/**
|
||||
* @description Merges two sorted lists.
|
||||
* @param list The other list you want to merge (must be sorted).
|
||||
*/
|
||||
LinkList.prototype.merge = function (list) {
|
||||
var _this = this;
|
||||
if (!this.head) {
|
||||
list.forEach(function (element) { return _this.pushBack(element); });
|
||||
return;
|
||||
}
|
||||
var curNode = this.head;
|
||||
list.forEach(function (element) {
|
||||
while (curNode &&
|
||||
curNode !== _this.header &&
|
||||
curNode.value <= element) {
|
||||
curNode = curNode.next;
|
||||
}
|
||||
if (curNode === _this.header) {
|
||||
_this.pushBack(element);
|
||||
curNode = _this.tail;
|
||||
}
|
||||
else if (curNode === _this.head) {
|
||||
_this.pushFront(element);
|
||||
curNode = _this.head;
|
||||
}
|
||||
else {
|
||||
_this.length += 1;
|
||||
var pre = curNode.pre;
|
||||
pre.next = new LinkNode(element);
|
||||
pre.next.pre = pre;
|
||||
pre.next.next = curNode;
|
||||
curNode.pre = pre.next;
|
||||
}
|
||||
});
|
||||
};
|
||||
LinkList.prototype[Symbol.iterator] = function () {
|
||||
return function () {
|
||||
var curNode;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!this.head)
|
||||
return [2 /*return*/];
|
||||
curNode = this.head;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(curNode !== this.header)) return [3 /*break*/, 3];
|
||||
return [4 /*yield*/, curNode.value];
|
||||
case 2:
|
||||
_a.sent();
|
||||
curNode = curNode.next;
|
||||
return [3 /*break*/, 1];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}.bind(this)();
|
||||
};
|
||||
return LinkList;
|
||||
}(SequentialContainer));
|
||||
export default LinkList;
|
||||
38
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Vector.d.ts
generated
vendored
Normal file
38
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Vector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import SequentialContainer from './Base/index';
|
||||
import { initContainer } from "../ContainerBase/index";
|
||||
import { RandomIterator } from "./Base/RandomIterator";
|
||||
export declare class VectorIterator<T> extends RandomIterator<T> {
|
||||
copy(): VectorIterator<T>;
|
||||
}
|
||||
declare class Vector<T> extends SequentialContainer<T> {
|
||||
private readonly vector;
|
||||
/**
|
||||
* @description Vector's constructor.
|
||||
* @param container Initialize container, must have a forEach function.
|
||||
* @param copy When the container is an array, you can choose to directly operate on the original object of
|
||||
* the array or perform a shallow copy. The default is shallow copy.
|
||||
*/
|
||||
constructor(container?: initContainer<T>, copy?: boolean);
|
||||
clear(): void;
|
||||
begin(): VectorIterator<T>;
|
||||
end(): VectorIterator<T>;
|
||||
rBegin(): VectorIterator<T>;
|
||||
rEnd(): VectorIterator<T>;
|
||||
front(): T | undefined;
|
||||
back(): T | undefined;
|
||||
forEach(callback: (element: T, index: number) => void): void;
|
||||
getElementByPos(pos: number): T;
|
||||
eraseElementByPos(pos: number): void;
|
||||
eraseElementByValue(value: T): void;
|
||||
eraseElementByIterator(iter: VectorIterator<T>): VectorIterator<T>;
|
||||
pushBack(element: T): void;
|
||||
popBack(): void;
|
||||
setElementByPos(pos: number, element: T): void;
|
||||
insert(pos: number, element: T, num?: number): void;
|
||||
find(element: T): VectorIterator<T>;
|
||||
reverse(): void;
|
||||
unique(): void;
|
||||
sort(cmp?: (x: T, y: T) => number): void;
|
||||
[Symbol.iterator](): Generator<T, any, undefined>;
|
||||
}
|
||||
export default Vector;
|
||||
227
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Vector.js
generated
vendored
Normal file
227
WebUI/node_modules/js-sdsl/dist/esm/container/SequentialContainer/Vector.js
generated
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var __values = (this && this.__values) || function(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 };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
import SequentialContainer from './Base/index';
|
||||
import { checkWithinAccessParams } from "../../utils/checkParams";
|
||||
import { ContainerIterator } from "../ContainerBase/index";
|
||||
import { RandomIterator } from "./Base/RandomIterator";
|
||||
var VectorIterator = /** @class */ (function (_super) {
|
||||
__extends(VectorIterator, _super);
|
||||
function VectorIterator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
VectorIterator.prototype.copy = function () {
|
||||
return new VectorIterator(this.node, this.size, this.getElementByPos, this.setElementByPos, this.iteratorType);
|
||||
};
|
||||
return VectorIterator;
|
||||
}(RandomIterator));
|
||||
export { VectorIterator };
|
||||
var Vector = /** @class */ (function (_super) {
|
||||
__extends(Vector, _super);
|
||||
/**
|
||||
* @description Vector's constructor.
|
||||
* @param container Initialize container, must have a forEach function.
|
||||
* @param copy When the container is an array, you can choose to directly operate on the original object of
|
||||
* the array or perform a shallow copy. The default is shallow copy.
|
||||
*/
|
||||
function Vector(container, copy) {
|
||||
if (container === void 0) { container = []; }
|
||||
if (copy === void 0) { copy = true; }
|
||||
var _this = _super.call(this) || this;
|
||||
if (Array.isArray(container)) {
|
||||
_this.vector = copy ? __spreadArray([], __read(container), false) : container;
|
||||
_this.length = container.length;
|
||||
}
|
||||
else {
|
||||
_this.vector = [];
|
||||
container.forEach(function (element) { return _this.pushBack(element); });
|
||||
}
|
||||
_this.size = _this.size.bind(_this);
|
||||
_this.getElementByPos = _this.getElementByPos.bind(_this);
|
||||
_this.setElementByPos = _this.setElementByPos.bind(_this);
|
||||
return _this;
|
||||
}
|
||||
Vector.prototype.clear = function () {
|
||||
this.length = 0;
|
||||
this.vector.length = 0;
|
||||
};
|
||||
Vector.prototype.begin = function () {
|
||||
return new VectorIterator(0, this.size, this.getElementByPos, this.setElementByPos);
|
||||
};
|
||||
Vector.prototype.end = function () {
|
||||
return new VectorIterator(this.length, this.size, this.getElementByPos, this.setElementByPos);
|
||||
};
|
||||
Vector.prototype.rBegin = function () {
|
||||
return new VectorIterator(this.length - 1, this.size, this.getElementByPos, this.setElementByPos, ContainerIterator.REVERSE);
|
||||
};
|
||||
Vector.prototype.rEnd = function () {
|
||||
return new VectorIterator(-1, this.size, this.getElementByPos, this.setElementByPos, ContainerIterator.REVERSE);
|
||||
};
|
||||
Vector.prototype.front = function () {
|
||||
return this.vector[0];
|
||||
};
|
||||
Vector.prototype.back = function () {
|
||||
return this.vector[this.length - 1];
|
||||
};
|
||||
Vector.prototype.forEach = function (callback) {
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
callback(this.vector[i], i);
|
||||
}
|
||||
};
|
||||
Vector.prototype.getElementByPos = function (pos) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
return this.vector[pos];
|
||||
};
|
||||
Vector.prototype.eraseElementByPos = function (pos) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
this.vector.splice(pos, 1);
|
||||
this.length -= 1;
|
||||
};
|
||||
Vector.prototype.eraseElementByValue = function (value) {
|
||||
var index = 0;
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
if (this.vector[i] !== value) {
|
||||
this.vector[index++] = this.vector[i];
|
||||
}
|
||||
}
|
||||
this.length = this.vector.length = index;
|
||||
};
|
||||
Vector.prototype.eraseElementByIterator = function (iter) {
|
||||
// @ts-ignore
|
||||
var node = iter.node;
|
||||
iter = iter.next();
|
||||
this.eraseElementByPos(node);
|
||||
return iter;
|
||||
};
|
||||
Vector.prototype.pushBack = function (element) {
|
||||
this.vector.push(element);
|
||||
this.length += 1;
|
||||
};
|
||||
Vector.prototype.popBack = function () {
|
||||
if (!this.length)
|
||||
return;
|
||||
this.vector.pop();
|
||||
this.length -= 1;
|
||||
};
|
||||
Vector.prototype.setElementByPos = function (pos, element) {
|
||||
checkWithinAccessParams(pos, 0, this.length - 1);
|
||||
this.vector[pos] = element;
|
||||
};
|
||||
Vector.prototype.insert = function (pos, element, num) {
|
||||
var _a;
|
||||
if (num === void 0) { num = 1; }
|
||||
checkWithinAccessParams(pos, 0, this.length);
|
||||
(_a = this.vector).splice.apply(_a, __spreadArray([pos, 0], __read(new Array(num).fill(element)), false));
|
||||
this.length += num;
|
||||
};
|
||||
Vector.prototype.find = function (element) {
|
||||
for (var i = 0; i < this.length; ++i) {
|
||||
if (this.vector[i] === element) {
|
||||
return new VectorIterator(i, this.size, this.getElementByPos, this.getElementByPos);
|
||||
}
|
||||
}
|
||||
return this.end();
|
||||
};
|
||||
Vector.prototype.reverse = function () {
|
||||
this.vector.reverse();
|
||||
};
|
||||
Vector.prototype.unique = function () {
|
||||
var index = 1;
|
||||
for (var i = 1; i < this.length; ++i) {
|
||||
if (this.vector[i] !== this.vector[i - 1]) {
|
||||
this.vector[index++] = this.vector[i];
|
||||
}
|
||||
}
|
||||
this.length = this.vector.length = index;
|
||||
};
|
||||
Vector.prototype.sort = function (cmp) {
|
||||
this.vector.sort(cmp);
|
||||
};
|
||||
Vector.prototype[Symbol.iterator] = function () {
|
||||
return function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [5 /*yield**/, __values(this.vector)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
}.bind(this)();
|
||||
};
|
||||
return Vector;
|
||||
}(SequentialContainer));
|
||||
export default Vector;
|
||||
Reference in New Issue
Block a user