Insane number of adds to setup env and packages

This commit is contained in:
2022-11-07 17:45:54 -05:00
parent 62c2bb73a9
commit 55ecf095a9
3127 changed files with 485223 additions and 1 deletions

160
node_modules/js-sdsl/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,160 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
## [4.1.5] - 2022.09.30
### Added
- Add `find`, `remove`, `updateItem` and `toArray` functions to `PriorityQueue`.
- Support single package release (use scope @js-sdsl).
## [4.1.5-beta.1] - 2022.09.23
### Fixed
- Get wrong tree index when size is 0.
## [4.1.5-beta.0] - 2022.09.23
### Added
- Add `index` property to tree iterator which represents the sequential index of the iterator in the tree.
### Changed
- Minimal optimization with private properties mangling, macro inlining and const enum.
- Private properties are now mangled.
- Remove `checkWithinAccessParams` function.
- Constants of `HashContainer` are moved to `HashContainerConst` const enum.
- The iteratorType parameter in the constructor now changed from `boolean` type to `IteratorType` const enum type.
- The type of `TreeNode.color` is now changed from `boolean` to `TreeNodeColor` const enum.
- Turn some member exports into export-only types.
### Fixed
- Fixed wrong iterator error message.
## [4.1.4] - 2022.09.07
### Added
- Add some notes.
### Changed
- Optimize hash container.
- Abstracting out the hash container.
### Fixed
- Fixed tree get height function return one larger than the real height.
- Tree-shaking not work in ES module.
- `Queue` and `Deque` should return `undefined` when container is empty.
## [4.1.4-beta.0] - 2022.08.31
### Added
- Add function update key by iterator.
- Add iterator copy function to get a copy of itself.
- Add insert by iterator hint function in tree container.
### Changed
- Changed OrderedMap's iterator pointer get from `Object.defineProperty'` to `Proxy`.
- Improve iterator performance by remove some judgment.
- Change iterator type description from `normal` and `reverse` to boolean.
## [4.1.2-beta.0] - 2022.08.27
### Added
- Make `SequentialContainer` and `TreeBaseContainer` export in the index.
### Changed
- Change rbTree binary search from recursive to loop implementation (don't effect using).
- Reduce memory waste during deque initialization.
### Fixed
- Fixed priority queue not dereference on pop.
## [4.1.1] - 2022.08.23
### Fixed
- Forgot to reset root node on rotation in red-black tree delete operation.
- Fix iterator invalidation after tree container removes iterator.
## [4.1.0] - 2022.08.21
### Changed
- Change some functions from recursive to loop implementation (don't effect using).
- Change some iterator function parameter type.
- Change commonjs target to `es6`.
- Change `Deque` from sequential queue to circular queue.
- Optimize so many places (don't affect using).
### Fixed
- Fix `Vector` length bugs.
## [4.0.3] - 2022-08-13
### Changed
- Change `if (this.empty())` to `if (!this.length)`.
- Change some unit test.
- Change class type and optimized type design.
### Fixed
- Fix can push undefined to deque.
## [4.0.0] - 2022-07-30
### Changed
- Remove InternalError error as much as possible (don't affect using).
- Change `HashSet` api `eraseElementByValue`'s name to `eraseElementByKey`.
- Change some unit tests to improve coverage (don't affect using).
## [4.0.0-beta.0] - 2022-07-24
### Added
- Complete test examples (don't effect using).
- The error thrown is standardized, you can catch it according to the error type.
### Changed
- Refactor all container from function to class (don't affect using).
- Abstracting tree containers and hash containers, change `Set`'s and `Map`'s name to `OrderedSet` and `OrderedMap` to distinguish it from the official container.
- Change `OrderedSet` api `eraseElementByValue`'s name to `eraseElementByKey`.
### Fixed
- Fixed so many bugs.
## [3.0.0-beta.0] - 2022-04-29
### Added
- Bidirectional iterator is provided for all containers except Stack, Queue, HashSet and HashMap.
- Added begin, end, rBegin and rEnd functions to some containers for using iterator.
- Added `eraseElementByIterator` function.
### Changed
- Changed Pair type `T, K` to `K, V` (don't affect using).
- Changed `find`, `lowerBound`, `upperBound`, `reverseLowerBound` and `reverseUpperBound` function's returned value to `Iterator`.
### Fixed
- Fixed an error when the insert value was 0.
- Fixed the problem that the lower version browser does not recognize symbol Compilation error caused by iterator.

21
node_modules/js-sdsl/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Zilong Yao
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

149
node_modules/js-sdsl/README.md generated vendored Normal file
View File

@@ -0,0 +1,149 @@
<p align="center">
<a href="https://js-sdsl.github.io/" target="_blank" rel="noopener noreferrer">
<img src="https://js-sdsl.github.io/assets/logo-removebg.png" alt="js-sdsl logo" width="120" />
</a>
</p>
<h3><p align="center">A javascript standard data structure library which benchmark against C++ STL</p></h3>
<p align="center">
<a href="https://www.npmjs.com/package/js-sdsl"><img src="https://img.shields.io/npm/v/js-sdsl.svg" alt="NPM Version" /></a>
<a href="https://github.com/js-sdsl/js-sdsl/actions/workflows/build.yml"><img src="https://img.shields.io/github/workflow/status/js-sdsl/js-sdsl/js-sdsl%20CI" alt="Build Status" /></a>
<a href='https://coveralls.io/github/js-sdsl/js-sdsl?branch=main'><img src='https://coveralls.io/repos/github/js-sdsl/js-sdsl/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://github.com/js-sdsl/js-sdsl"><img src="https://img.shields.io/github/stars/js-sdsl/js-sdsl.svg" alt="GITHUB Star" /></a>
<a href="https://npmcharts.com/compare/js-sdsl?minimal=true"><img src="https://img.shields.io/npm/dm/js-sdsl.svg" alt="NPM Downloads" /></a>
<a href="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"><img src="https://img.badgesize.io/https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js?compression=gzip&style=flat-square/" alt="Gzip Size"></a>
<a href="https://openbase.com/js/js-sdsl?utm_source=embedded&amp;utm_medium=badge&amp;utm_campaign=rate-badge"><img src="https://badges.openbase.com/js/rating/js-sdsl.svg?token=fh3LMNOV+JSWykSjtg1rA8kouSYkJoIDzGbvaByq5X0=" alt="Rate this package"/></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/js-sdsl.svg" alt="MIT-license" /></a>
<a href="https://github.com/js-sdsl/js-sdsl/"><img src="https://img.shields.io/github/languages/top/js-sdsl/js-sdsl.svg" alt="GITHUB-language" /></a>
</p>
<p align="center">English | <a href="https://github.com/js-sdsl/js-sdsl/blob/main/README.zh-CN.md">简体中文</a></p>
## Included data structures
- Vector
- Stack
- Queue
- LinkList
- Deque
- PriorityQueue
- OrderedSet (using RBTree)
- OrderedMap (using RBTree)
- HashSet
- HashMap
## 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
- node.js (using es6)
- react/vue (using es5)
- browser (support most browsers)
## Download
Download directly
- [js-sdsl.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js) (for development)
- [js-sdsl.min.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js) (for production)
Or install js-sdsl using npm
```bash
npm install js-sdsl
```
## Usage
You can visit our [official website](https://js-sdsl.github.io/) to get more information.
To help you have a better use, we also provide this [API document](https://js-sdsl.github.io/js-sdsl/index.html).
### For browser
```html
<script src="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"></script>
<script>
const {
Vector,
Stack,
Queue,
LinkList,
Deque,
PriorityQueue,
OrderedSet,
OrderedMap,
HashSet,
HashMap
} = sdsl;
const myOrderedMap = new OrderedMap();
myOrderedMap.setElement(1, 2);
console.log(myOrderedMap.getElementByKey(1)); // 2
</script>
```
### For npm
```javascript
// esModule
import { OrderedMap } from 'js-sdsl';
// commonJs
const { OrderedMap } = require('js-sdsl');
const myOrderedMap = new OrderedMap();
myOrderedMap.setElement(1, 2);
console.log(myOrderedMap.getElementByKey(1)); // 2
```
## Build by source code
You can pull this repository and run `yarn build` to rebuild this library.
## Test
### Unit test
We use jest library to write unit tests, you can see test coverage on [coveralls](https://coveralls.io/github/js-sdsl/js-sdsl). You can run `yarn test:unit` command to reproduce it.
### For performance
We tested most of the functions for efficiency. You can go to [`gh-pages/performance.md`](https://github.com/js-sdsl/js-sdsl/blob/gh-pages/performance.md) to see our running results or reproduce it with `yarn test:performance` command.
You can also visit [here](https://js-sdsl.github.io/#/test/performance-test) to get the result.
## Maintainers
[@ZLY201](https://github.com/ZLY201)
## 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).
### Contributors
Thanks goes to these wonderful people:
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center"><a href="https://www.linkedin.com/in/takatoshi-kondo-02a91410/"><img src="https://avatars.githubusercontent.com/u/275959?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Takatoshi Kondo</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Code">💻</a> <a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Tests">⚠️</a></td>
<td align="center"><a href="https://www.youtube.com/c/noname0310"><img src="https://avatars.githubusercontent.com/u/48761044?v=4?s=100" width="100px;" alt=""/><br /><sub><b>noname</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=noname0310" title="Code">💻</a></td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## License
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201

151
node_modules/js-sdsl/README.zh-CN.md generated vendored Normal file
View File

@@ -0,0 +1,151 @@
<p align="center">
<a href="https://js-sdsl.github.io/" target="_blank" rel="noopener noreferrer">
<img src="https://js-sdsl.github.io/assets/logo-removebg.png" alt="js-sdsl logo" width="120" />
</a>
</p>
<h3><p align="center">一款参考 C++ STL 实现的 JavaScript 标准数据结构库</p></h3>
<p align="center">
<a href="https://www.npmjs.com/package/js-sdsl"><img src="https://img.shields.io/npm/v/js-sdsl.svg" alt="NPM Version" /></a>
<a href="https://github.com/js-sdsl/js-sdsl/actions/workflows/build.yml"><img src="https://img.shields.io/github/workflow/status/js-sdsl/js-sdsl/js-sdsl%20CI" alt="Build Status" /></a>
<a href='https://coveralls.io/github/js-sdsl/js-sdsl?branch=main'><img src='https://coveralls.io/repos/github/js-sdsl/js-sdsl/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://github.com/js-sdsl/js-sdsl"><img src="https://img.shields.io/github/stars/js-sdsl/js-sdsl.svg" alt="GITHUB Star" /></a>
<a href="https://npmcharts.com/compare/js-sdsl?minimal=true"><img src="https://img.shields.io/npm/dm/js-sdsl.svg" alt="NPM Downloads" /></a>
<a href="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"><img src="https://img.badgesize.io/https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js?compression=gzip&style=flat-square/" alt="Gzip Size"></a>
<a href="https://openbase.com/js/js-sdsl?utm_source=embedded&amp;utm_medium=badge&amp;utm_campaign=rate-badge"><img src="https://badges.openbase.com/js/rating/js-sdsl.svg?token=fh3LMNOV+JSWykSjtg1rA8kouSYkJoIDzGbvaByq5X0=" alt="Rate this package"/></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/js-sdsl.svg" alt="MIT-license" /></a>
<a href="https://github.com/js-sdsl/js-sdsl/"><img src="https://img.shields.io/github/languages/top/js-sdsl/js-sdsl.svg" alt="GITHUB-language" /></a>
</p>
<p align="center"><a href="https://github.com/js-sdsl/js-sdsl/blob/main/README.md">English</a> | 简体中文</p>
## 包含的数据结构
- Vector
- Stack
- Queue
- LinkList
- Deque
- PriorityQueue
- OrderedSet (using RBTree)
- OrderedMap (using RBTree)
- HashSet
- HashMap
## 基准测试
我们和其他数据结构库进行了基准测试,在某些场景我们甚至超过了当前最流行的库
查看 [benchmark](https://js-sdsl.github.io/#/zh-cn/test/benchmark-analyze) 以获取更多信息
## 支持的平台
- node.js (using es6)
- react/vue (using es5)
- browser (support most browsers)
## 下载
使用 cdn 直接引入
- [js-sdsl.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.js) (for development)
- [js-sdsl.min.js](https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js) (for production)
使用 npm 下载
```bash
npm install js-sdsl
```
## 使用说明
您可以[访问我们的主页](https://js-sdsl.github.io/)获取更多信息
并且我们提供了完整的 [API 文档](https://js-sdsl.github.io/js-sdsl/index.html)供您参考
### 在浏览器中使用
```html
<script src="https://unpkg.com/js-sdsl/dist/umd/js-sdsl.min.js"></script>
<script>
const {
Vector,
Stack,
Queue,
LinkList,
Deque,
PriorityQueue,
OrderedSet,
OrderedMap,
HashSet,
HashMap
} = sdsl;
const myOrderedMap = new OrderedMap();
myOrderedMap.setElement(1, 2);
console.log(myOrderedMap.getElementByKey(1)); // 2
</script>
```
### npm 引入
```javascript
// esModule
import { OrderedMap } from 'js-sdsl';
// commonJs
const { OrderedMap } = require('js-sdsl');
const myOrderedMap = new OrderedMap();
myOrderedMap.setElement(1, 2);
console.log(myOrderedMap.getElementByKey(1)); // 2
```
## 从源码构建
您可以克隆此仓库后运行 `yarn build` 命令重新构建这个库
## 测试
### 单元测试
我们使用 `jest` 库来编写我们的单元测试,并将结果同步到了 [coveralls](https://coveralls.io/github/js-sdsl/js-sdsl) 上,你可以使用 `yarn test:unit` 命令来重建它
### 对于性能的校验
我们对于编写的所有 API 进行了性能测试,并将结果同步到了 [`gh-pages/performance.md`](https://github.com/js-sdsl/js-sdsl/blob/gh-pages/performance.md) 中,你可以通过 `yarn test:performance` 命令来重现它
您也可以访问[我们的网站](https://js-sdsl.github.io/#/zh-cn/test/performance-test)来获取结果
## 维护者
[@ZLY201](https://github.com/ZLY201)
## 贡献
我们欢迎所有的开发人员提交 issue 或 pull request阅读[贡献者指南](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md)可能会有所帮助
### 贡献者
感谢对本项目做出贡献的开发者们:
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center"><a href="https://www.linkedin.com/in/takatoshi-kondo-02a91410/"><img src="https://avatars.githubusercontent.com/u/275959?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Takatoshi Kondo</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Code">💻</a> <a href="https://github.com/js-sdsl/js-sdsl/commits?author=redboltz" title="Tests">⚠️</a></td>
<td align="center"><a href="https://www.youtube.com/c/noname0310"><img src="https://avatars.githubusercontent.com/u/48761044?v=4?s=100" width="100px;" alt=""/><br /><sub><b>noname</b></sub></a><br /><a href="https://github.com/js-sdsl/js-sdsl/commits?author=noname0310" title="Code">💻</a></td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
本项目遵循 [all-contributors](https://github.com/all-contributors/all-contributors) 规范。 欢迎任何形式的贡献!
## 许可证
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © ZLY201

View File

@@ -0,0 +1,120 @@
export declare const enum IteratorType {
NORMAL = 0,
REVERSE = 1
}
export declare abstract class ContainerIterator<T> {
/**
* @description Iterator's type.
*/
readonly iteratorType: IteratorType;
protected constructor(iteratorType?: IteratorType);
/**
* @description Pointers to element.
* @return The value of the pointer's element.
*/
abstract get pointer(): T;
/**
* @description Set pointer's value (some containers are unavailable).
* @param newValue The new value you want to set.
*/
abstract set pointer(newValue: T);
/**
* @description Move `this` iterator to pre.
*/
abstract pre(): this;
/**
* @description Move `this` iterator to next.
*/
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.<br/>
* We do not guarantee the safety of this function.<br/>
* Please ensure that the iterator will not fail.
* @return The copy of self.
*/
abstract copy(): ContainerIterator<T>;
}
export declare abstract class Base {
/**
* @return The size of the container.
*/
size(): number;
/**
* @return Boolean about if the container is empty.
*/
empty(): boolean;
/**
* @description Clear the container.
*/
abstract clear(): void;
}
export declare abstract class Container<T> extends Base {
/**
* @return Iterator pointing to the beginning element.
*/
abstract begin(): ContainerIterator<T>;
/**
* @return Iterator pointing to the super end like c++.
*/
abstract end(): ContainerIterator<T>;
/**
* @return Iterator pointing to the end element.
*/
abstract rBegin(): ContainerIterator<T>;
/**
* @return Iterator pointing to the super begin like c++.
*/
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.
*/
abstract forEach(callback: (element: T, index: number) => 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.
*/
abstract find(element: T): ContainerIterator<T>;
/**
* @description Gets the value of the element at the specified position.
*/
abstract getElementByPos(pos: number): T;
/**
* @description Removes the element at the specified position.
* @param pos The element's position you want to remove.
*/
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());
*/
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>;
/**
* @description Using for `for...of` syntax like Array.
*/
abstract [Symbol.iterator](): Generator<T, void, undefined>;
}
export declare type initContainer<T> = ({
size: number;
} | {
length: number;
} | {
size(): number;
}) & {
forEach(callback: (element: T) => void): void;
};

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.ContainerIterator = exports.Container = exports.Base = void 0;
class ContainerIterator {
constructor(t = 0) {
this.iteratorType = t;
}
}
exports.ContainerIterator = ContainerIterator;
class Base {
constructor() {
this.o = 0;
}
size() {
return this.o;
}
empty() {
return this.o === 0;
}
}
exports.Base = Base;
class Container extends Base {}
exports.Container = Container;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View File

@@ -0,0 +1,48 @@
import { Base, initContainer } from "../ContainerBase";
declare class PriorityQueue<T> extends Base {
/**
* @description PriorityQueue's constructor.
* @param container Initialize container, must have a forEach function.
* @param cmp Compare 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>, cmp?: (x: T, y: T) => number, copy?: boolean);
clear(): void;
/**
* @description Push element into a container in order.
* @param item The element you want to push.
*/
push(item: T): void;
/**
* @description Removes the top element.
*/
pop(): void;
/**
* @description Accesses the top element.
*/
top(): T | undefined;
/**
* @description Check if element is in heap.
* @param item The item want to find.
* @return Boolean about if element is in heap.
*/
find(item: T): boolean;
/**
* @description Remove specified item from heap.
* @param item The item want to remove.
* @return Boolean about if remove success.
*/
remove(item: T): boolean;
/**
* @description Update item and it's pos in the heap.
* @param item The item want to update.
* @return Boolean about if update success.
*/
updateItem(item: T): boolean;
/**
* @return Return a copy array of heap.
*/
toArray(): T[];
}
export default PriorityQueue;

View File

@@ -0,0 +1,112 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../ContainerBase");
class PriorityQueue extends _ContainerBase.Base {
constructor(t = [], s = ((t, s) => {
if (t > s) return -1;
if (t < s) return 1;
return 0;
}), i = true) {
super();
this.p = s;
if (Array.isArray(t)) {
this._ = i ? [ ...t ] : t;
} else {
this._ = [];
t.forEach((t => this._.push(t)));
}
this.o = this._.length;
const e = this.o >> 1;
for (let t = this.o - 1 >> 1; t >= 0; --t) {
this.v(t, e);
}
}
B(t) {
const s = this._[t];
while (t > 0) {
const i = t - 1 >> 1;
const e = this._[i];
if (this.p(e, s) <= 0) break;
this._[t] = e;
t = i;
}
this._[t] = s;
}
v(t, s) {
const i = this._[t];
while (t < s) {
let s = t << 1 | 1;
const e = s + 1;
let h = this._[s];
if (e < this.o && this.p(h, this._[e]) > 0) {
s = e;
h = this._[e];
}
if (this.p(h, i) >= 0) break;
this._[t] = h;
t = s;
}
this._[t] = i;
}
clear() {
this.o = 0;
this._.length = 0;
}
push(t) {
this._.push(t);
this.B(this.o);
this.o += 1;
}
pop() {
if (!this.o) return;
const t = this._.pop();
this.o -= 1;
if (this.o) {
this._[0] = t;
this.v(0, this.o >> 1);
}
}
top() {
return this._[0];
}
find(t) {
return this._.indexOf(t) >= 0;
}
remove(t) {
const s = this._.indexOf(t);
if (s < 0) return false;
if (s === 0) {
this.pop();
} else if (s === this.o - 1) {
this._.pop();
this.o -= 1;
} else {
this._.splice(s, 1, this._.pop());
this.o -= 1;
this.B(s);
this.v(s, this.o >> 1);
}
return true;
}
updateItem(t) {
const s = this._.indexOf(t);
if (s < 0) return false;
this.B(s);
this.v(s, this.o >> 1);
return true;
}
toArray() {
return [ ...this._ ];
}
}
var _default = PriorityQueue;
exports.default = _default;

View File

@@ -0,0 +1,18 @@
import { Base, initContainer } from "../ContainerBase";
declare class Queue<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Inserts element to queue's end.
*/
push(element: T): void;
/**
* @description Removes the first element.
*/
pop(): void;
/**
* @description Access the first element.
*/
front(): T | undefined;
}
export default Queue;

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _Deque = _interopRequireDefault(require("../SequentialContainer/Deque"));
var _ContainerBase = require("../ContainerBase");
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
class Queue extends _ContainerBase.Base {
constructor(e = []) {
super();
this.q = new _Deque.default(e);
this.o = this.q.size();
}
clear() {
this.q.clear();
this.o = 0;
}
push(e) {
this.q.pushBack(e);
this.o += 1;
}
pop() {
this.q.popFront();
if (this.o) this.o -= 1;
}
front() {
return this.q.front();
}
}
var _default = Queue;
exports.default = _default;

View File

@@ -0,0 +1,18 @@
import { Base, initContainer } from "../ContainerBase";
declare class Stack<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Insert element to stack's end.
*/
push(element: T): void;
/**
* @description Removes the end element.
*/
pop(): void;
/**
* @description Accesses the end element.
*/
top(): T | undefined;
}
export default Stack;

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../ContainerBase");
class Stack extends _ContainerBase.Base {
constructor(t = []) {
super();
this.C = [];
t.forEach((t => this.push(t)));
}
clear() {
this.o = 0;
this.C.length = 0;
}
push(t) {
this.C.push(t);
this.o += 1;
}
pop() {
this.C.pop();
if (this.o > 0) this.o -= 1;
}
top() {
return this.C[this.o - 1];
}
}
var _default = Stack;
exports.default = _default;

View File

@@ -0,0 +1,8 @@
import { ContainerIterator } from "../../ContainerBase";
export declare abstract class RandomIterator<T> extends ContainerIterator<T> {
pre: () => this;
next: () => this;
get pointer(): T;
set pointer(newValue: T);
equals(obj: RandomIterator<T>): boolean;
}

View File

@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.RandomIterator = void 0;
var _ContainerBase = require("../../ContainerBase");
class RandomIterator extends _ContainerBase.ContainerIterator {
constructor(t, r, e, i, s) {
super(s);
this.I = t;
this.D = r;
this.g = e;
this.m = i;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.I === 0) {
throw new RangeError("Random iterator access denied!");
}
this.I -= 1;
return this;
};
this.next = function() {
if (this.I === this.D()) {
throw new RangeError("Random Iterator access denied!");
}
this.I += 1;
return this;
};
} else {
this.pre = function() {
if (this.I === this.D() - 1) {
throw new RangeError("Random iterator access denied!");
}
this.I += 1;
return this;
};
this.next = function() {
if (this.I === -1) {
throw new RangeError("Random iterator access denied!");
}
this.I -= 1;
return this;
};
}
}
get pointer() {
if (this.I < 0 || this.I > this.D() - 1) {
throw new RangeError;
}
return this.g(this.I);
}
set pointer(t) {
if (this.I < 0 || this.I > this.D() - 1) {
throw new RangeError;
}
this.m(this.I, t);
}
equals(t) {
return this.I === t.I;
}
}
exports.RandomIterator = RandomIterator;

View File

@@ -0,0 +1,44 @@
import { Container } from "../../ContainerBase";
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;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../../ContainerBase");
class SequentialContainer extends _ContainerBase.Container {}
var _default = SequentialContainer;
exports.default = _default;

View File

@@ -0,0 +1,50 @@
import SequentialContainer from './Base';
import { initContainer } from "../ContainerBase";
import { RandomIterator } from "./Base/RandomIterator";
export declare class DequeIterator<T> extends RandomIterator<T> {
copy(): DequeIterator<T>;
}
declare class Deque<T> extends SequentialContainer<T> {
constructor(container?: initContainer<T>, _bucketSize?: number);
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;

View File

@@ -0,0 +1,324 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = exports.DequeIterator = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _RandomIterator = require("./Base/RandomIterator");
function _interopRequireDefault(t) {
return t && t.t ? t : {
default: t
};
}
class DequeIterator extends _RandomIterator.RandomIterator {
copy() {
return new DequeIterator(this.I, this.D, this.g, this.m, this.iteratorType);
}
}
exports.DequeIterator = DequeIterator;
class Deque extends _Base.default {
constructor(t = [], i = 1 << 12) {
super();
this.R = 0;
this.k = 0;
this.N = 0;
this.M = 0;
this.u = 0;
this.P = [];
let s;
if ("size" in t) {
if (typeof t.size === "number") {
s = t.size;
} else {
s = t.size();
}
} else if ("length" in t) {
s = t.length;
} else {
throw new RangeError("Can't get container's size!");
}
this.A = i;
this.u = Math.max(Math.ceil(s / this.A), 1);
for (let t = 0; t < this.u; ++t) {
this.P.push(new Array(this.A));
}
const h = Math.ceil(s / this.A);
this.R = this.N = (this.u >> 1) - (h >> 1);
this.k = this.M = this.A - s % this.A >> 1;
t.forEach((t => this.pushBack(t)));
this.size = this.size.bind(this);
this.getElementByPos = this.getElementByPos.bind(this);
this.setElementByPos = this.setElementByPos.bind(this);
}
h() {
const t = [];
const i = Math.max(this.u >> 1, 1);
for (let s = 0; s < i; ++s) {
t[s] = new Array(this.A);
}
for (let i = this.R; i < this.u; ++i) {
t[t.length] = this.P[i];
}
for (let i = 0; i < this.N; ++i) {
t[t.length] = this.P[i];
}
t[t.length] = [ ...this.P[this.N] ];
this.R = i;
this.N = t.length - 1;
for (let s = 0; s < i; ++s) {
t[t.length] = new Array(this.A);
}
this.P = t;
this.u = t.length;
}
F(t) {
const i = this.k + t + 1;
const s = i % this.A;
let h = s - 1;
let e = this.R + (i - s) / this.A;
if (s === 0) e -= 1;
e %= this.u;
if (h < 0) h += this.A;
return {
curNodeBucketIndex: e,
curNodePointerIndex: h
};
}
clear() {
this.P = [ [] ];
this.u = 1;
this.R = this.N = this.o = 0;
this.k = this.M = this.A >> 1;
}
front() {
return this.P[this.R][this.k];
}
back() {
return this.P[this.N][this.M];
}
begin() {
return new DequeIterator(0, this.size, this.getElementByPos, this.setElementByPos);
}
end() {
return new DequeIterator(this.o, this.size, this.getElementByPos, this.setElementByPos);
}
rBegin() {
return new DequeIterator(this.o - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
}
rEnd() {
return new DequeIterator(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
}
pushBack(t) {
if (this.o) {
if (this.M < this.A - 1) {
this.M += 1;
} else if (this.N < this.u - 1) {
this.N += 1;
this.M = 0;
} else {
this.N = 0;
this.M = 0;
}
if (this.N === this.R && this.M === this.k) this.h();
}
this.o += 1;
this.P[this.N][this.M] = t;
}
popBack() {
if (!this.o) return;
this.P[this.N][this.M] = undefined;
if (this.o !== 1) {
if (this.M > 0) {
this.M -= 1;
} else if (this.N > 0) {
this.N -= 1;
this.M = this.A - 1;
} else {
this.N = this.u - 1;
this.M = this.A - 1;
}
}
this.o -= 1;
}
pushFront(t) {
if (this.o) {
if (this.k > 0) {
this.k -= 1;
} else if (this.R > 0) {
this.R -= 1;
this.k = this.A - 1;
} else {
this.R = this.u - 1;
this.k = this.A - 1;
}
if (this.R === this.N && this.k === this.M) this.h();
}
this.o += 1;
this.P[this.R][this.k] = t;
}
popFront() {
if (!this.o) return;
this.P[this.R][this.k] = undefined;
if (this.o !== 1) {
if (this.k < this.A - 1) {
this.k += 1;
} else if (this.R < this.u - 1) {
this.R += 1;
this.k = 0;
} else {
this.R = 0;
this.k = 0;
}
}
this.o -= 1;
}
forEach(t) {
for (let i = 0; i < this.o; ++i) {
t(this.getElementByPos(i), i);
}
}
getElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
const {curNodeBucketIndex: i, curNodePointerIndex: s} = this.F(t);
return this.P[i][s];
}
setElementByPos(t, i) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
const {curNodeBucketIndex: s, curNodePointerIndex: h} = this.F(t);
this.P[s][h] = i;
}
insert(t, i, s = 1) {
if (t < 0 || t > this.o) {
throw new RangeError;
}
if (t === 0) {
while (s--) this.pushFront(i);
} else if (t === this.o) {
while (s--) this.pushBack(i);
} else {
const h = [];
for (let i = t; i < this.o; ++i) {
h.push(this.getElementByPos(i));
}
this.cut(t - 1);
for (let t = 0; t < s; ++t) this.pushBack(i);
for (let t = 0; t < h.length; ++t) this.pushBack(h[t]);
}
}
cut(t) {
if (t < 0) {
this.clear();
return;
}
const {curNodeBucketIndex: i, curNodePointerIndex: s} = this.F(t);
this.N = i;
this.M = s;
this.o = t + 1;
}
eraseElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
if (t === 0) this.popFront(); else if (t === this.o - 1) this.popBack(); else {
const i = [];
for (let s = t + 1; s < this.o; ++s) {
i.push(this.getElementByPos(s));
}
this.cut(t);
this.popBack();
i.forEach((t => this.pushBack(t)));
}
}
eraseElementByValue(t) {
if (!this.o) return;
const i = [];
for (let s = 0; s < this.o; ++s) {
const h = this.getElementByPos(s);
if (h !== t) i.push(h);
}
const s = i.length;
for (let t = 0; t < s; ++t) this.setElementByPos(t, i[t]);
this.cut(s - 1);
}
eraseElementByIterator(t) {
const i = t.I;
this.eraseElementByPos(i);
t = t.next();
return t;
}
find(t) {
for (let i = 0; i < this.o; ++i) {
if (this.getElementByPos(i) === t) {
return new DequeIterator(i, this.size, this.getElementByPos, this.setElementByPos);
}
}
return this.end();
}
reverse() {
let t = 0;
let i = this.o - 1;
while (t < i) {
const s = this.getElementByPos(t);
this.setElementByPos(t, this.getElementByPos(i));
this.setElementByPos(i, s);
t += 1;
i -= 1;
}
}
unique() {
if (this.o <= 1) return;
let t = 1;
let i = this.getElementByPos(0);
for (let s = 1; s < this.o; ++s) {
const h = this.getElementByPos(s);
if (h !== i) {
i = h;
this.setElementByPos(t++, h);
}
}
while (this.o > t) this.popBack();
}
sort(t) {
const i = [];
for (let t = 0; t < this.o; ++t) {
i.push(this.getElementByPos(t));
}
i.sort(t);
for (let t = 0; t < this.o; ++t) this.setElementByPos(t, i[t]);
}
shrinkToFit() {
if (!this.o) return;
const t = [];
this.forEach((i => t.push(i)));
this.u = Math.max(Math.ceil(this.o / this.A), 1);
this.o = this.R = this.N = this.k = this.M = 0;
this.P = [];
for (let t = 0; t < this.u; ++t) {
this.P.push(new Array(this.A));
}
for (let i = 0; i < t.length; ++i) this.pushBack(t[i]);
}
[Symbol.iterator]() {
return function*() {
for (let t = 0; t < this.o; ++t) {
yield this.getElementByPos(t);
}
}.bind(this)();
}
}
var _default = Deque;
exports.default = _default;

View File

@@ -0,0 +1,49 @@
import SequentialContainer from './Base';
import { ContainerIterator, initContainer } from "../ContainerBase";
export declare class LinkListIterator<T> extends ContainerIterator<T> {
pre: () => this;
next: () => this;
get pointer(): T;
set pointer(newValue: T);
equals(obj: LinkListIterator<T>): boolean;
copy(): LinkListIterator<T>;
}
declare class LinkList<T> extends SequentialContainer<T> {
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;

View File

@@ -0,0 +1,366 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = exports.LinkNode = exports.LinkListIterator = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _ContainerBase = require("../ContainerBase");
function _interopRequireDefault(t) {
return t && t.t ? t : {
default: t
};
}
class LinkNode {
constructor(t) {
this.L = undefined;
this.j = undefined;
this.O = undefined;
this.L = t;
}
}
exports.LinkNode = LinkNode;
class LinkListIterator extends _ContainerBase.ContainerIterator {
constructor(t, i, s) {
super(s);
this.I = t;
this.S = i;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.I.j === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
this.I = this.I.j;
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
this.I = this.I.O;
return this;
};
} else {
this.pre = function() {
if (this.I.O === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
this.I = this.I.O;
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
this.I = this.I.j;
return this;
};
}
}
get pointer() {
if (this.I === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
return this.I.L;
}
set pointer(t) {
if (this.I === this.S) {
throw new RangeError("LinkList iterator access denied!");
}
this.I.L = t;
}
equals(t) {
return this.I === t.I;
}
copy() {
return new LinkListIterator(this.I, this.S, this.iteratorType);
}
}
exports.LinkListIterator = LinkListIterator;
class LinkList extends _Base.default {
constructor(t = []) {
super();
this.S = new LinkNode;
this.V = undefined;
this.G = undefined;
t.forEach((t => this.pushBack(t)));
}
clear() {
this.o = 0;
this.V = this.G = undefined;
this.S.j = this.S.O = undefined;
}
begin() {
return new LinkListIterator(this.V || this.S, this.S);
}
end() {
return new LinkListIterator(this.S, this.S);
}
rBegin() {
return new LinkListIterator(this.G || this.S, this.S, 1);
}
rEnd() {
return new LinkListIterator(this.S, this.S, 1);
}
front() {
return this.V ? this.V.L : undefined;
}
back() {
return this.G ? this.G.L : undefined;
}
forEach(t) {
if (!this.o) return;
let i = this.V;
let s = 0;
while (i !== this.S) {
t(i.L, s++);
i = i.O;
}
}
getElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
let i = this.V;
while (t--) {
i = i.O;
}
return i.L;
}
eraseElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
if (t === 0) this.popFront(); else if (t === this.o - 1) this.popBack(); else {
let i = this.V;
while (t--) {
i = i.O;
}
i = i;
const s = i.j;
const e = i.O;
e.j = s;
s.O = e;
this.o -= 1;
}
}
eraseElementByValue(t) {
while (this.V && this.V.L === t) this.popFront();
while (this.G && this.G.L === t) this.popBack();
if (!this.V) return;
let i = this.V;
while (i !== this.S) {
if (i.L === t) {
const t = i.j;
const s = i.O;
s.j = t;
t.O = s;
this.o -= 1;
}
i = i.O;
}
}
eraseElementByIterator(t) {
const i = t.I;
if (i === this.S) {
throw new RangeError("Invalid iterator");
}
t = t.next();
if (this.V === i) this.popFront(); else if (this.G === i) this.popBack(); else {
const t = i.j;
const s = i.O;
s.j = t;
t.O = s;
this.o -= 1;
}
return t;
}
pushBack(t) {
this.o += 1;
const i = new LinkNode(t);
if (!this.G) {
this.V = this.G = i;
this.S.O = this.V;
this.V.j = this.S;
} else {
this.G.O = i;
i.j = this.G;
this.G = i;
}
this.G.O = this.S;
this.S.j = this.G;
}
popBack() {
if (!this.G) return;
this.o -= 1;
if (this.V === this.G) {
this.V = this.G = undefined;
this.S.O = undefined;
} else {
this.G = this.G.j;
this.G.O = this.S;
}
this.S.j = this.G;
}
setElementByPos(t, i) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
let s = this.V;
while (t--) {
s = s.O;
}
s.L = i;
}
insert(t, i, s = 1) {
if (t < 0 || t > this.o) {
throw new RangeError;
}
if (s <= 0) return;
if (t === 0) {
while (s--) this.pushFront(i);
} else if (t === this.o) {
while (s--) this.pushBack(i);
} else {
let e = this.V;
for (let i = 1; i < t; ++i) {
e = e.O;
}
const h = e.O;
this.o += s;
while (s--) {
e.O = new LinkNode(i);
e.O.j = e;
e = e.O;
}
e.O = h;
h.j = e;
}
}
find(t) {
if (!this.V) return this.end();
let i = this.V;
while (i !== this.S) {
if (i.L === t) {
return new LinkListIterator(i, this.S);
}
i = i.O;
}
return this.end();
}
reverse() {
if (this.o <= 1) return;
let t = this.V;
let i = this.G;
let s = 0;
while (s << 1 < this.o) {
const e = t.L;
t.L = i.L;
i.L = e;
t = t.O;
i = i.j;
s += 1;
}
}
unique() {
if (this.o <= 1) return;
let t = this.V;
while (t !== this.S) {
let i = t;
while (i.O && i.L === i.O.L) {
i = i.O;
this.o -= 1;
}
t.O = i.O;
t.O.j = t;
t = t.O;
}
}
sort(t) {
if (this.o <= 1) return;
const i = [];
this.forEach((t => i.push(t)));
i.sort(t);
let s = this.V;
i.forEach((t => {
s.L = t;
s = s.O;
}));
}
pushFront(t) {
this.o += 1;
const i = new LinkNode(t);
if (!this.V) {
this.V = this.G = i;
this.G.O = this.S;
this.S.j = this.G;
} else {
i.O = this.V;
this.V.j = i;
this.V = i;
}
this.S.O = this.V;
this.V.j = this.S;
}
popFront() {
if (!this.V) return;
this.o -= 1;
if (this.V === this.G) {
this.V = this.G = undefined;
this.S.j = this.G;
} else {
this.V = this.V.O;
this.V.j = this.S;
}
this.S.O = this.V;
}
merge(t) {
if (!this.V) {
t.forEach((t => this.pushBack(t)));
return;
}
let i = this.V;
t.forEach((t => {
while (i && i !== this.S && i.L <= t) {
i = i.O;
}
if (i === this.S) {
this.pushBack(t);
i = this.G;
} else if (i === this.V) {
this.pushFront(t);
i = this.V;
} else {
this.o += 1;
const s = i.j;
s.O = new LinkNode(t);
s.O.j = s;
s.O.O = i;
i.j = s.O;
}
}));
}
[Symbol.iterator]() {
return function*() {
if (!this.V) return;
let t = this.V;
while (t !== this.S) {
yield t.L;
t = t.O;
}
}.bind(this)();
}
}
var _default = LinkList;
exports.default = _default;

View File

@@ -0,0 +1,37 @@
import SequentialContainer from './Base';
import { initContainer } from "../ContainerBase";
import { RandomIterator } from "./Base/RandomIterator";
export declare class VectorIterator<T> extends RandomIterator<T> {
copy(): VectorIterator<T>;
}
declare class Vector<T> extends SequentialContainer<T> {
/**
* @description Vector's constructor.
* @param container Initialize container, must have a forEach function.
* @param copy When the container is an array, you can choose to directly operate on the original object of
* the array or perform a shallow copy. The default is shallow copy.
*/
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;

View File

@@ -0,0 +1,150 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = exports.VectorIterator = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _RandomIterator = require("./Base/RandomIterator");
function _interopRequireDefault(t) {
return t && t.t ? t : {
default: t
};
}
class VectorIterator extends _RandomIterator.RandomIterator {
copy() {
return new VectorIterator(this.I, this.D, this.g, this.m, this.iteratorType);
}
}
exports.VectorIterator = VectorIterator;
class Vector extends _Base.default {
constructor(t = [], e = true) {
super();
if (Array.isArray(t)) {
this.H = e ? [ ...t ] : t;
this.o = t.length;
} else {
this.H = [];
t.forEach((t => this.pushBack(t)));
}
this.size = this.size.bind(this);
this.getElementByPos = this.getElementByPos.bind(this);
this.setElementByPos = this.setElementByPos.bind(this);
}
clear() {
this.o = 0;
this.H.length = 0;
}
begin() {
return new VectorIterator(0, this.size, this.getElementByPos, this.setElementByPos);
}
end() {
return new VectorIterator(this.o, this.size, this.getElementByPos, this.setElementByPos);
}
rBegin() {
return new VectorIterator(this.o - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
}
rEnd() {
return new VectorIterator(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
}
front() {
return this.H[0];
}
back() {
return this.H[this.o - 1];
}
forEach(t) {
for (let e = 0; e < this.o; ++e) {
t(this.H[e], e);
}
}
getElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
return this.H[t];
}
eraseElementByPos(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
this.H.splice(t, 1);
this.o -= 1;
}
eraseElementByValue(t) {
let e = 0;
for (let r = 0; r < this.o; ++r) {
if (this.H[r] !== t) {
this.H[e++] = this.H[r];
}
}
this.o = this.H.length = e;
}
eraseElementByIterator(t) {
const e = t.I;
t = t.next();
this.eraseElementByPos(e);
return t;
}
pushBack(t) {
this.H.push(t);
this.o += 1;
}
popBack() {
if (!this.o) return;
this.H.pop();
this.o -= 1;
}
setElementByPos(t, e) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
this.H[t] = e;
}
insert(t, e, r = 1) {
if (t < 0 || t > this.o) {
throw new RangeError;
}
this.H.splice(t, 0, ...new Array(r).fill(e));
this.o += r;
}
find(t) {
for (let e = 0; e < this.o; ++e) {
if (this.H[e] === t) {
return new VectorIterator(e, this.size, this.getElementByPos, this.getElementByPos);
}
}
return this.end();
}
reverse() {
this.H.reverse();
}
unique() {
let t = 1;
for (let e = 1; e < this.o; ++e) {
if (this.H[e] !== this.H[e - 1]) {
this.H[t++] = this.H[e];
}
}
this.o = this.H.length = t;
}
sort(t) {
this.H.sort(t);
}
[Symbol.iterator]() {
return function*() {
return yield* this.H;
}.bind(this)();
}
}
var _default = Vector;
exports.default = _default;

View File

@@ -0,0 +1,15 @@
import { ContainerIterator } from "../../ContainerBase";
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`.
*/
get index(): number;
equals(obj: TreeIterator<K, V>): boolean;
}
export default TreeIterator;

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../../ContainerBase");
class TreeIterator extends _ContainerBase.ContainerIterator {
constructor(t, e, r) {
super(r);
this.I = t;
this.S = e;
if (this.iteratorType === 0) {
this.pre = function() {
if (this.I === this.S.U) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.pre();
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.next();
return this;
};
} else {
this.pre = function() {
if (this.I === this.S.J) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.next();
return this;
};
this.next = function() {
if (this.I === this.S) {
throw new RangeError("Tree iterator access denied!");
}
this.I = this.I.pre();
return this;
};
}
}
get index() {
let t = this.I;
const e = this.S.tt;
if (t === this.S) {
if (e) {
return e.et - 1;
}
return 0;
}
let r = 0;
if (t.U) {
r += t.U.et;
}
while (t !== e) {
const e = t.tt;
if (t === e.J) {
r += 1;
if (e.U) {
r += e.U.et;
}
}
t = e;
}
return r;
}
equals(t) {
return this.I === t.I;
}
}
var _default = TreeIterator;
exports.default = _default;

View File

@@ -0,0 +1,36 @@
export declare class TreeNode<K, V> {
constructor(_key?: K, _value?: V);
/**
* @description Get the pre node.
* @return TreeNode about the pre node.
*/
pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @return TreeNode about the next node.
*/
next(): TreeNode<K, V>;
/**
* @description Rotate _left.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate _right.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
}
export declare class TreeNodeEnableIndex<K, V> extends TreeNode<K, V> {
/**
* @description Rotate _left and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNodeEnableIndex<K, V>;
/**
* @description Rotate _right and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
recount(): void;
}

View File

@@ -0,0 +1,113 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.TreeNodeEnableIndex = exports.TreeNode = void 0;
class TreeNode {
constructor(e, t) {
this.se = 1;
this.T = undefined;
this.L = undefined;
this.U = undefined;
this.J = undefined;
this.tt = undefined;
this.T = e;
this.L = t;
}
pre() {
let e = this;
if (e.se === 1 && e.tt.tt === e) {
e = e.J;
} else if (e.U) {
e = e.U;
while (e.J) {
e = e.J;
}
} else {
let t = e.tt;
while (t.U === e) {
e = t;
t = e.tt;
}
e = t;
}
return e;
}
next() {
let e = this;
if (e.J) {
e = e.J;
while (e.U) {
e = e.U;
}
return e;
} else {
let t = e.tt;
while (t.J === e) {
e = t;
t = e.tt;
}
if (e.J !== t) {
return t;
} else return e;
}
}
rotateLeft() {
const e = this.tt;
const t = this.J;
const s = t.U;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.J = t;
t.tt = e;
t.U = this;
this.tt = t;
this.J = s;
if (s) s.tt = this;
return t;
}
rotateRight() {
const e = this.tt;
const t = this.U;
const s = t.J;
if (e.tt === this) e.tt = t; else if (e.U === this) e.U = t; else e.J = t;
t.tt = e;
t.J = this;
this.tt = t;
this.U = s;
if (s) s.tt = this;
return t;
}
}
exports.TreeNode = TreeNode;
class TreeNodeEnableIndex extends TreeNode {
constructor() {
super(...arguments);
this.U = undefined;
this.J = undefined;
this.tt = undefined;
this.et = 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.et = 1;
if (this.U) this.et += this.U.et;
if (this.J) this.et += this.J.et;
}
}
exports.TreeNodeEnableIndex = TreeNodeEnableIndex;

View File

@@ -0,0 +1,55 @@
import type TreeIterator from './TreeIterator';
import { Container } from "../../ContainerBase";
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.
*/
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;
}
export default TreeContainer;

View File

@@ -0,0 +1,483 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = void 0;
var _ContainerBase = require("../../ContainerBase");
var _TreeNode = require("./TreeNode");
class TreeContainer extends _ContainerBase.Container {
constructor(e = ((e, t) => {
if (e < t) return -1;
if (e > t) return 1;
return 0;
}), t = false) {
super();
this.X = undefined;
this.ie = (e, t) => {
if (e === undefined) return false;
const i = this.ie(e.U, t);
if (i) return true;
if (t(e)) return true;
return this.ie(e.J, t);
};
this.p = e;
if (t) {
this.ne = _TreeNode.TreeNodeEnableIndex;
this.ee = function(e, t, i) {
const s = this.he(e, t, i);
if (s) {
let e = s.tt;
while (e !== this.S) {
e.et += 1;
e = e.tt;
}
const t = this.fe(s);
if (t) {
const {parentNode: e, grandParent: i, curNode: s} = t;
e.recount();
i.recount();
s.recount();
}
}
};
this.ue = function(e) {
let t = this.le(e);
while (t !== this.S) {
t.et -= 1;
t = t.tt;
}
};
} else {
this.ne = _TreeNode.TreeNode;
this.ee = function(e, t, i) {
const s = this.he(e, t, i);
if (s) this.fe(s);
};
this.ue = this.le;
}
this.S = new this.ne;
}
W(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
e = e.J;
} else if (s > 0) {
i = e;
e = e.U;
} else return e;
}
return i === undefined ? this.S : i;
}
Y(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s <= 0) {
e = e.J;
} else {
i = e;
e = e.U;
}
}
return i === undefined ? this.S : i;
}
Z(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
i = e;
e = e.J;
} else if (s > 0) {
e = e.U;
} else return e;
}
return i === undefined ? this.S : i;
}
$(e, t) {
let i;
while (e) {
const s = this.p(e.T, t);
if (s < 0) {
i = e;
e = e.J;
} else {
e = e.U;
}
}
return i === undefined ? this.S : i;
}
oe(e) {
while (true) {
const t = e.tt;
if (t === this.S) return;
if (e.se === 1) {
e.se = 0;
return;
}
if (e === t.U) {
const i = t.J;
if (i.se === 1) {
i.se = 0;
t.se = 1;
if (t === this.X) {
this.X = t.rotateLeft();
} else t.rotateLeft();
} else {
if (i.J && i.J.se === 1) {
i.se = t.se;
t.se = 0;
i.J.se = 0;
if (t === this.X) {
this.X = t.rotateLeft();
} else t.rotateLeft();
return;
} else if (i.U && i.U.se === 1) {
i.se = 1;
i.U.se = 0;
i.rotateRight();
} else {
i.se = 1;
e = t;
}
}
} else {
const i = t.U;
if (i.se === 1) {
i.se = 0;
t.se = 1;
if (t === this.X) {
this.X = t.rotateRight();
} else t.rotateRight();
} else {
if (i.U && i.U.se === 1) {
i.se = t.se;
t.se = 0;
i.U.se = 0;
if (t === this.X) {
this.X = t.rotateRight();
} else t.rotateRight();
return;
} else if (i.J && i.J.se === 1) {
i.se = 1;
i.J.se = 0;
i.rotateLeft();
} else {
i.se = 1;
e = t;
}
}
}
}
}
le(e) {
if (this.o === 1) {
this.clear();
return this.S;
}
let t = e;
while (t.U || t.J) {
if (t.J) {
t = t.J;
while (t.U) t = t.U;
} else {
t = t.U;
}
[e.T, t.T] = [ t.T, e.T ];
[e.L, t.L] = [ t.L, e.L ];
e = t;
}
if (this.S.U === t) {
this.S.U = t.tt;
} else if (this.S.J === t) {
this.S.J = t.tt;
}
this.oe(t);
const i = t.tt;
if (t === i.U) {
i.U = undefined;
} else i.J = undefined;
this.o -= 1;
this.X.se = 0;
return i;
}
fe(e) {
while (true) {
const t = e.tt;
if (t.se === 0) return;
const i = t.tt;
if (t === i.U) {
const s = i.J;
if (s && s.se === 1) {
s.se = t.se = 0;
if (i === this.X) return;
i.se = 1;
e = i;
continue;
} else if (e === t.J) {
e.se = 0;
if (e.U) e.U.tt = t;
if (e.J) e.J.tt = i;
t.J = e.U;
i.U = e.J;
e.U = t;
e.J = i;
if (i === this.X) {
this.X = e;
this.S.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.J = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.se = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.se = 0;
if (i === this.X) {
this.X = i.rotateRight();
} else i.rotateRight();
i.se = 1;
}
} else {
const s = i.U;
if (s && s.se === 1) {
s.se = t.se = 0;
if (i === this.X) return;
i.se = 1;
e = i;
continue;
} else if (e === t.U) {
e.se = 0;
if (e.U) e.U.tt = i;
if (e.J) e.J.tt = t;
i.J = e.U;
t.U = e.J;
e.U = i;
e.J = t;
if (i === this.X) {
this.X = e;
this.S.tt = e;
} else {
const t = i.tt;
if (t.U === i) {
t.U = e;
} else t.J = e;
}
e.tt = i.tt;
t.tt = e;
i.tt = e;
i.se = 1;
return {
parentNode: t,
grandParent: i,
curNode: e
};
} else {
t.se = 0;
if (i === this.X) {
this.X = i.rotateLeft();
} else i.rotateLeft();
i.se = 1;
}
}
return;
}
}
he(e, t, i) {
if (this.X === undefined) {
this.o += 1;
this.X = new this.ne(e, t);
this.X.se = 0;
this.X.tt = this.S;
this.S.tt = this.X;
this.S.U = this.X;
this.S.J = this.X;
return;
}
let s;
const r = this.S.U;
const n = this.p(r.T, e);
if (n === 0) {
r.L = t;
return;
} else if (n > 0) {
r.U = new this.ne(e, t);
r.U.tt = r;
s = r.U;
this.S.U = s;
} else {
const r = this.S.J;
const n = this.p(r.T, e);
if (n === 0) {
r.L = t;
return;
} else if (n < 0) {
r.J = new this.ne(e, t);
r.J.tt = r;
s = r.J;
this.S.J = s;
} else {
if (i !== undefined) {
const r = i.I;
if (r !== this.S) {
const i = this.p(r.T, e);
if (i === 0) {
r.L = t;
return;
} else if (i > 0) {
const i = r.pre();
const n = this.p(i.T, e);
if (n === 0) {
i.L = t;
return;
} else if (n < 0) {
s = new this.ne(e, t);
if (i.J === undefined) {
i.J = s;
s.tt = i;
} else {
r.U = s;
s.tt = r;
}
}
}
}
}
if (s === undefined) {
s = this.X;
while (true) {
const i = this.p(s.T, e);
if (i > 0) {
if (s.U === undefined) {
s.U = new this.ne(e, t);
s.U.tt = s;
s = s.U;
break;
}
s = s.U;
} else if (i < 0) {
if (s.J === undefined) {
s.J = new this.ne(e, t);
s.J.tt = s;
s = s.J;
break;
}
s = s.J;
} else {
s.L = t;
return;
}
}
}
}
}
this.o += 1;
return s;
}
clear() {
this.o = 0;
this.X = undefined;
this.S.tt = undefined;
this.S.U = this.S.J = undefined;
}
updateKeyByIterator(e, t) {
const i = e.I;
if (i === this.S) {
throw new TypeError("Invalid iterator!");
}
if (this.o === 1) {
i.T = t;
return true;
}
if (i === this.S.U) {
if (this.p(i.next().T, t) > 0) {
i.T = t;
return true;
}
return false;
}
if (i === this.S.J) {
if (this.p(i.pre().T, t) < 0) {
i.T = t;
return true;
}
return false;
}
const s = i.pre().T;
if (this.p(s, t) >= 0) return false;
const r = i.next().T;
if (this.p(r, t) <= 0) return false;
i.T = t;
return true;
}
eraseElementByPos(e) {
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
let t = 0;
this.ie(this.X, (i => {
if (e === t) {
this.ue(i);
return true;
}
t += 1;
return false;
}));
}
re(e, t) {
while (e) {
const i = this.p(e.T, t);
if (i < 0) {
e = e.J;
} else if (i > 0) {
e = e.U;
} else return e;
}
return e;
}
eraseElementByKey(e) {
if (!this.o) return;
const t = this.re(this.X, e);
if (t === undefined) return;
this.ue(t);
}
eraseElementByIterator(e) {
const t = e.I;
if (t === this.S) {
throw new RangeError("Invalid iterator");
}
if (t.J === undefined) {
e = e.next();
}
this.ue(t);
return e;
}
getHeight() {
if (!this.o) return 0;
const traversal = e => {
if (!e) return 0;
return Math.max(traversal(e.U), traversal(e.J)) + 1;
};
return traversal(this.X);
}
}
var _default = TreeContainer;
exports.default = _default;

View File

@@ -0,0 +1,42 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { initContainer } from "../ContainerBase";
export 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.
*/
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) => 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.
*/
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.
*/
getElementByKey(_key: K): V | undefined;
getElementByPos(pos: number): [K, V];
union(other: OrderedMap<K, V>): void;
[Symbol.iterator](): Generator<[K, V], void, undefined>;
}
export default OrderedMap;

View File

@@ -0,0 +1,136 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = exports.OrderedMapIterator = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _TreeIterator = _interopRequireDefault(require("./Base/TreeIterator"));
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
class OrderedMapIterator extends _TreeIterator.default {
get pointer() {
if (this.I === this.S) {
throw new RangeError("OrderedMap iterator access denied");
}
return new Proxy([], {
get: (e, r) => {
if (r === "0") return this.I.T; else if (r === "1") return this.I.L;
},
set: (e, r, t) => {
if (r !== "1") {
throw new TypeError("props must be 1");
}
this.I.L = t;
return true;
}
});
}
copy() {
return new OrderedMapIterator(this.I, this.S, this.iteratorType);
}
}
exports.OrderedMapIterator = OrderedMapIterator;
class OrderedMap extends _Base.default {
constructor(e = [], r, t) {
super(r, t);
this.K = function*(e) {
if (e === undefined) return;
yield* this.K(e.U);
yield [ e.T, e.L ];
yield* this.K(e.J);
};
e.forEach((([e, r]) => this.setElement(e, r)));
}
begin() {
return new OrderedMapIterator(this.S.U || this.S, this.S);
}
end() {
return new OrderedMapIterator(this.S, this.S);
}
rBegin() {
return new OrderedMapIterator(this.S.J || this.S, this.S, 1);
}
rEnd() {
return new OrderedMapIterator(this.S, this.S, 1);
}
front() {
if (!this.o) return undefined;
const e = this.S.U;
return [ e.T, e.L ];
}
back() {
if (!this.o) return undefined;
const e = this.S.J;
return [ e.T, e.L ];
}
forEach(e) {
let r = 0;
for (const t of this) e(t, r++);
}
lowerBound(e) {
const r = this.W(this.X, e);
return new OrderedMapIterator(r, this.S);
}
upperBound(e) {
const r = this.Y(this.X, e);
return new OrderedMapIterator(r, this.S);
}
reverseLowerBound(e) {
const r = this.Z(this.X, e);
return new OrderedMapIterator(r, this.S);
}
reverseUpperBound(e) {
const r = this.$(this.X, e);
return new OrderedMapIterator(r, this.S);
}
setElement(e, r, t) {
this.ee(e, r, t);
}
find(e) {
const r = this.re(this.X, e);
if (r !== undefined) {
return new OrderedMapIterator(r, this.S);
}
return this.end();
}
getElementByKey(e) {
const r = this.re(this.X, e);
return r ? r.L : undefined;
}
getElementByPos(e) {
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
let r;
let t = 0;
for (const s of this) {
if (t === e) {
r = s;
break;
}
t += 1;
}
return r;
}
union(e) {
e.forEach((([e, r]) => this.setElement(e, r)));
}
[Symbol.iterator]() {
return this.K(this.X);
}
}
var _default = OrderedMap;
exports.default = _default;

View File

@@ -0,0 +1,37 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { initContainer } from "../ContainerBase";
export declare class OrderedSetIterator<K> extends TreeIterator<K, undefined> {
get pointer(): K;
copy(): OrderedSetIterator<K>;
}
declare class OrderedSet<K> extends TreeContainer<K, undefined> {
/**
* @param container The initialization container.
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
*/
constructor(container?: initContainer<K>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedSetIterator<K>;
end(): OrderedSetIterator<K>;
rBegin(): OrderedSetIterator<K>;
rEnd(): OrderedSetIterator<K>;
front(): K | undefined;
back(): K | undefined;
forEach(callback: (element: K, index: number) => void): void;
getElementByPos(pos: number): K;
/**
* @description Insert element to set.
* @param _key The _key want to insert.
* @param hint You can give an iterator hint to improve insertion efficiency.
*/
insert(_key: K, hint?: OrderedSetIterator<K>): void;
find(element: K): OrderedSetIterator<K>;
lowerBound(_key: K): OrderedSetIterator<K>;
upperBound(_key: K): OrderedSetIterator<K>;
reverseLowerBound(_key: K): OrderedSetIterator<K>;
reverseUpperBound(_key: K): OrderedSetIterator<K>;
union(other: OrderedSet<K>): void;
[Symbol.iterator](): Generator<K, void, undefined>;
}
export default OrderedSet;

View File

@@ -0,0 +1,117 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
exports.default = exports.OrderedSetIterator = void 0;
var _Base = _interopRequireDefault(require("./Base"));
var _TreeIterator = _interopRequireDefault(require("./Base/TreeIterator"));
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}
class OrderedSetIterator extends _TreeIterator.default {
get pointer() {
if (this.I === this.S) {
throw new RangeError("OrderedSet iterator access denied!");
}
return this.I.T;
}
copy() {
return new OrderedSetIterator(this.I, this.S, this.iteratorType);
}
}
exports.OrderedSetIterator = OrderedSetIterator;
class OrderedSet extends _Base.default {
constructor(e = [], t, r) {
super(t, r);
this.K = function*(e) {
if (e === undefined) return;
yield* this.K(e.U);
yield e.T;
yield* this.K(e.J);
};
e.forEach((e => this.insert(e)));
}
begin() {
return new OrderedSetIterator(this.S.U || this.S, this.S);
}
end() {
return new OrderedSetIterator(this.S, this.S);
}
rBegin() {
return new OrderedSetIterator(this.S.J || this.S, this.S, 1);
}
rEnd() {
return new OrderedSetIterator(this.S, this.S, 1);
}
front() {
return this.S.U ? this.S.U.T : undefined;
}
back() {
return this.S.J ? this.S.J.T : undefined;
}
forEach(e) {
let t = 0;
for (const r of this) e(r, t++);
}
getElementByPos(e) {
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
let t;
let r = 0;
for (const i of this) {
if (r === e) {
t = i;
break;
}
r += 1;
}
return t;
}
insert(e, t) {
this.ee(e, undefined, t);
}
find(e) {
const t = this.re(this.X, e);
if (t !== undefined) {
return new OrderedSetIterator(t, this.S);
}
return this.end();
}
lowerBound(e) {
const t = this.W(this.X, e);
return new OrderedSetIterator(t, this.S);
}
upperBound(e) {
const t = this.Y(this.X, e);
return new OrderedSetIterator(t, this.S);
}
reverseLowerBound(e) {
const t = this.Z(this.X, e);
return new OrderedSetIterator(t, this.S);
}
reverseUpperBound(e) {
const t = this.$(this.X, e);
return new OrderedSetIterator(t, this.S);
}
union(e) {
e.forEach((e => this.insert(e)));
}
[Symbol.iterator]() {
return this.K(this.X);
}
}
var _default = OrderedSet;
exports.default = _default;

19
node_modules/js-sdsl/dist/cjs/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
export { default as Stack } from "./container/OtherContainer/Stack";
export { default as Queue } from "./container/OtherContainer/Queue";
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue";
export { default as Vector } from "./container/SequentialContainer/Vector";
export { default as LinkList } from "./container/SequentialContainer/LinkList";
export { default as Deque } from "./container/SequentialContainer/Deque";
export { default as OrderedSet } from "./container/TreeContainer/OrderedSet";
export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
export { default as HashSet } from "./container/HashContainer/HashSet";
export { default as HashMap } from "./container/HashContainer/HashMap";
export type { VectorIterator } from "./container/SequentialContainer/Vector";
export type { LinkListIterator } from "./container/SequentialContainer/LinkList";
export type { DequeIterator } from "./container/SequentialContainer/Deque";
export type { OrderedSetIterator } from "./container/TreeContainer/OrderedSet";
export type { OrderedMapIterator } from "./container/TreeContainer/OrderedMap";
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase";
export type { default as SequentialContainer } from "./container/SequentialContainer/Base";
export type { default as TreeContainer } from "./container/TreeContainer/Base";
export type { default as HashContainer } from "./container/HashContainer/Base";

101
node_modules/js-sdsl/dist/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "t", {
value: true
});
Object.defineProperty(exports, "Deque", {
enumerable: true,
get: function() {
return _Deque.default;
}
});
Object.defineProperty(exports, "HashMap", {
enumerable: true,
get: function() {
return _HashMap.default;
}
});
Object.defineProperty(exports, "HashSet", {
enumerable: true,
get: function() {
return _HashSet.default;
}
});
Object.defineProperty(exports, "LinkList", {
enumerable: true,
get: function() {
return _LinkList.default;
}
});
Object.defineProperty(exports, "OrderedMap", {
enumerable: true,
get: function() {
return _OrderedMap.default;
}
});
Object.defineProperty(exports, "OrderedSet", {
enumerable: true,
get: function() {
return _OrderedSet.default;
}
});
Object.defineProperty(exports, "PriorityQueue", {
enumerable: true,
get: function() {
return _PriorityQueue.default;
}
});
Object.defineProperty(exports, "Queue", {
enumerable: true,
get: function() {
return _Queue.default;
}
});
Object.defineProperty(exports, "Stack", {
enumerable: true,
get: function() {
return _Stack.default;
}
});
Object.defineProperty(exports, "Vector", {
enumerable: true,
get: function() {
return _Vector.default;
}
});
var _Stack = _interopRequireDefault(require("./container/OtherContainer/Stack"));
var _Queue = _interopRequireDefault(require("./container/OtherContainer/Queue"));
var _PriorityQueue = _interopRequireDefault(require("./container/OtherContainer/PriorityQueue"));
var _Vector = _interopRequireDefault(require("./container/SequentialContainer/Vector"));
var _LinkList = _interopRequireDefault(require("./container/SequentialContainer/LinkList"));
var _Deque = _interopRequireDefault(require("./container/SequentialContainer/Deque"));
var _OrderedSet = _interopRequireDefault(require("./container/TreeContainer/OrderedSet"));
var _OrderedMap = _interopRequireDefault(require("./container/TreeContainer/OrderedMap"));
var _HashSet = _interopRequireDefault(require("./container/HashContainer/HashSet"));
var _HashMap = _interopRequireDefault(require("./container/HashContainer/HashMap"));
function _interopRequireDefault(e) {
return e && e.t ? e : {
default: e
};
}

View File

@@ -0,0 +1,120 @@
export declare const enum IteratorType {
NORMAL = 0,
REVERSE = 1
}
export declare abstract class ContainerIterator<T> {
/**
* @description Iterator's type.
*/
readonly iteratorType: IteratorType;
protected constructor(iteratorType?: IteratorType);
/**
* @description Pointers to element.
* @return The value of the pointer's element.
*/
abstract get pointer(): T;
/**
* @description Set pointer's value (some containers are unavailable).
* @param newValue The new value you want to set.
*/
abstract set pointer(newValue: T);
/**
* @description Move `this` iterator to pre.
*/
abstract pre(): this;
/**
* @description Move `this` iterator to next.
*/
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.<br/>
* We do not guarantee the safety of this function.<br/>
* Please ensure that the iterator will not fail.
* @return The copy of self.
*/
abstract copy(): ContainerIterator<T>;
}
export declare abstract class Base {
/**
* @return The size of the container.
*/
size(): number;
/**
* @return Boolean about if the container is empty.
*/
empty(): boolean;
/**
* @description Clear the container.
*/
abstract clear(): void;
}
export declare abstract class Container<T> extends Base {
/**
* @return Iterator pointing to the beginning element.
*/
abstract begin(): ContainerIterator<T>;
/**
* @return Iterator pointing to the super end like c++.
*/
abstract end(): ContainerIterator<T>;
/**
* @return Iterator pointing to the end element.
*/
abstract rBegin(): ContainerIterator<T>;
/**
* @return Iterator pointing to the super begin like c++.
*/
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.
*/
abstract forEach(callback: (element: T, index: number) => 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.
*/
abstract find(element: T): ContainerIterator<T>;
/**
* @description Gets the value of the element at the specified position.
*/
abstract getElementByPos(pos: number): T;
/**
* @description Removes the element at the specified position.
* @param pos The element's position you want to remove.
*/
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());
*/
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>;
/**
* @description Using for `for...of` syntax like Array.
*/
abstract [Symbol.iterator](): Generator<T, void, undefined>;
}
export declare type initContainer<T> = ({
size: number;
} | {
length: number;
} | {
size(): number;
}) & {
forEach(callback: (element: T) => void): void;
};

View File

@@ -0,0 +1,57 @@
var __extends = this && this.t || function() {
var extendStatics = function(n, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(n, t) {
n.__proto__ = t;
} || function(n, t) {
for (var r in t) if (Object.prototype.hasOwnProperty.call(t, r)) n[r] = t[r];
};
return extendStatics(n, t);
};
return function(n, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(n, t);
function __() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
var ContainerIterator = function() {
function ContainerIterator(n) {
if (n === void 0) {
n = 0;
}
this.iteratorType = n;
}
return ContainerIterator;
}();
export { ContainerIterator };
var Base = function() {
function Base() {
this.o = 0;
}
Base.prototype.size = function() {
return this.o;
};
Base.prototype.empty = function() {
return this.o === 0;
};
return Base;
}();
export { Base };
var Container = function(n) {
__extends(Container, n);
function Container() {
return n !== null && n.apply(this, arguments) || this;
}
return Container;
}(Base);
export { Container };

View 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;

View File

@@ -0,0 +1,62 @@
var __extends = this && this.t || function() {
var extendStatics = function(n, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(n, t) {
n.__proto__ = t;
} || function(n, t) {
for (var r in t) if (Object.prototype.hasOwnProperty.call(t, r)) n[r] = t[r];
};
return extendStatics(n, t);
};
return function(n, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(n, t);
function __() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
import { Base } from "../../ContainerBase";
var HashContainer = function(n) {
__extends(HashContainer, n);
function HashContainer(t, r) {
if (t === void 0) {
t = 16;
}
if (r === void 0) {
r = function(n) {
var t;
if (typeof n !== "string") {
t = JSON.stringify(n);
} else t = n;
var r = 0;
var i = t.length;
for (var e = 0; e < i; e++) {
var o = t.charCodeAt(e);
r = (r << 5) - r + o;
r |= 0;
}
return r >>> 0;
};
}
var i = n.call(this) || this;
if (t < 16 || (t & t - 1) !== 0) {
throw new RangeError("InitBucketNum range error");
}
i.l = i.nn = t;
i.p = r;
return i;
}
HashContainer.prototype.clear = function() {
this.o = 0;
this.l = this.nn;
this.h = [];
};
return HashContainer;
}(Base);
export default HashContainer;

View 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;

View File

@@ -0,0 +1,410 @@
var __extends = this && this.t || function() {
var extendStatics = function(r, e) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(r, e) {
r.__proto__ = e;
} || function(r, e) {
for (var t in e) if (Object.prototype.hasOwnProperty.call(e, t)) r[t] = e[t];
};
return extendStatics(r, e);
};
return function(r, e) {
if (typeof e !== "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
extendStatics(r, e);
function __() {
this.constructor = r;
}
r.prototype = e === null ? Object.create(e) : (__.prototype = e.prototype, new __);
};
}();
var __generator = this && this.i || function(r, e) {
var t = {
label: 0,
sent: function() {
if (a[0] & 1) throw a[1];
return a[1];
},
trys: [],
ops: []
}, n, i, a, f;
return f = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (f[Symbol.iterator] = function() {
return this;
}), f;
function verb(r) {
return function(e) {
return step([ r, e ]);
};
}
function step(f) {
if (n) throw new TypeError("Generator is already executing.");
while (t) try {
if (n = 1, i && (a = f[0] & 2 ? i["return"] : f[0] ? i["throw"] || ((a = i["return"]) && a.call(i),
0) : i.next) && !(a = a.call(i, f[1])).done) return a;
if (i = 0, a) f = [ f[0] & 2, a.value ];
switch (f[0]) {
case 0:
case 1:
a = f;
break;
case 4:
t.label++;
return {
value: f[1],
done: false
};
case 5:
t.label++;
i = f[1];
f = [ 0 ];
continue;
case 7:
f = t.ops.pop();
t.trys.pop();
continue;
default:
if (!(a = t.trys, a = a.length > 0 && a[a.length - 1]) && (f[0] === 6 || f[0] === 2)) {
t = 0;
continue;
}
if (f[0] === 3 && (!a || f[1] > a[0] && f[1] < a[3])) {
t.label = f[1];
break;
}
if (f[0] === 6 && t.label < a[1]) {
t.label = a[1];
a = f;
break;
}
if (a && t.label < a[2]) {
t.label = a[2];
t.ops.push(f);
break;
}
if (a[2]) t.ops.pop();
t.trys.pop();
continue;
}
f = e.call(r, t);
} catch (r) {
f = [ 6, r ];
i = 0;
} finally {
n = a = 0;
}
if (f[0] & 5) throw f[1];
return {
value: f[0] ? f[1] : void 0,
done: true
};
}
};
var __values = this && this.u || function(r) {
var e = typeof Symbol === "function" && Symbol.iterator, t = e && r[e], n = 0;
if (t) return t.call(r);
if (r && typeof r.length === "number") return {
next: function() {
if (r && n >= r.length) r = void 0;
return {
value: r && r[n++],
done: !r
};
}
};
throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import HashContainer from "./Base";
import Vector from "../SequentialContainer/Vector";
import OrderedMap from "../TreeContainer/OrderedMap";
var HashMap = function(r) {
__extends(HashMap, r);
function HashMap(e, t, n) {
if (e === void 0) {
e = [];
}
var i = r.call(this, t, n) || this;
i.h = [];
e.forEach((function(r) {
return i.setElement(r[0], r[1]);
}));
return i;
}
HashMap.prototype.v = function() {
var r = this;
if (this.l >= 1073741824) return;
var e = [];
var t = this.l;
this.l <<= 1;
var n = Object.keys(this.h);
var i = n.length;
var _loop_1 = function(i) {
var f = parseInt(n[i]);
var s = a.h[f];
var o = s.size();
if (o === 0) return "continue";
if (o === 1) {
var u = s.front();
e[a.p(u[0]) & a.l - 1] = new Vector([ u ], false);
return "continue";
}
var c = [];
var h = [];
s.forEach((function(e) {
var n = r.p(e[0]);
if ((n & t) === 0) {
c.push(e);
} else h.push(e);
}));
if (s instanceof OrderedMap) {
if (c.length > 6) {
e[f] = new OrderedMap(c);
} else {
e[f] = new Vector(c, false);
}
if (h.length > 6) {
e[f + t] = new OrderedMap(h);
} else {
e[f + t] = new Vector(h, false);
}
} else {
e[f] = new Vector(c, false);
e[f + t] = new Vector(h, false);
}
};
var a = this;
for (var f = 0; f < i; ++f) {
_loop_1(f);
}
this.h = e;
};
HashMap.prototype.forEach = function(r) {
var e = Object.values(this.h);
var t = e.length;
var n = 0;
for (var i = 0; i < t; ++i) {
e[i].forEach((function(e) {
return r(e, n++);
}));
}
};
HashMap.prototype.setElement = function(r, e) {
var t, n;
var i = this.p(r) & this.l - 1;
var a = this.h[i];
if (!a) {
this.o += 1;
this.h[i] = new Vector([ [ r, e ] ], false);
} else {
var f = a.size();
if (a instanceof Vector) {
try {
for (var s = __values(a), o = s.next(); !o.done; o = s.next()) {
var u = o.value;
if (u[0] === r) {
u[1] = e;
return;
}
}
} catch (r) {
t = {
error: r
};
} finally {
try {
if (o && !o.done && (n = s.return)) n.call(s);
} finally {
if (t) throw t.error;
}
}
a.pushBack([ r, e ]);
if (f + 1 >= 8) {
if (this.l <= 64) {
this.o += 1;
this.v();
return;
}
this.h[i] = new OrderedMap(this.h[i]);
}
this.o += 1;
} else {
a.setElement(r, e);
var c = a.size();
this.o += c - f;
}
}
if (this.o > this.l * .75) {
this.v();
}
};
HashMap.prototype.getElementByKey = function(r) {
var e, t;
var n = this.p(r) & this.l - 1;
var i = this.h[n];
if (!i) return undefined;
if (i instanceof OrderedMap) {
return i.getElementByKey(r);
} else {
try {
for (var a = __values(i), f = a.next(); !f.done; f = a.next()) {
var s = f.value;
if (s[0] === r) return s[1];
}
} catch (r) {
e = {
error: r
};
} finally {
try {
if (f && !f.done && (t = a.return)) t.call(a);
} finally {
if (e) throw e.error;
}
}
return undefined;
}
};
HashMap.prototype.eraseElementByKey = function(r) {
var e, t;
var n = this.p(r) & this.l - 1;
var i = this.h[n];
if (!i) return;
if (i instanceof Vector) {
var a = 0;
try {
for (var f = __values(i), s = f.next(); !s.done; s = f.next()) {
var o = s.value;
if (o[0] === r) {
i.eraseElementByPos(a);
this.o -= 1;
return;
}
a += 1;
}
} catch (r) {
e = {
error: r
};
} finally {
try {
if (s && !s.done && (t = f.return)) t.call(f);
} finally {
if (e) throw e.error;
}
}
} else {
var u = i.size();
i.eraseElementByKey(r);
var c = i.size();
this.o += c - u;
if (c <= 6) {
this.h[n] = new Vector(i);
}
}
};
HashMap.prototype.find = function(r) {
var e, t;
var n = this.p(r) & this.l - 1;
var i = this.h[n];
if (!i) return false;
if (i instanceof OrderedMap) {
return !i.find(r).equals(i.end());
}
try {
for (var a = __values(i), f = a.next(); !f.done; f = a.next()) {
var s = f.value;
if (s[0] === r) return true;
}
} catch (r) {
e = {
error: r
};
} finally {
try {
if (f && !f.done && (t = a.return)) t.call(a);
} finally {
if (e) throw e.error;
}
}
return false;
};
HashMap.prototype[Symbol.iterator] = function() {
return function() {
var r, e, t, n, i, a, f, s;
var o, u;
return __generator(this, (function(c) {
switch (c.label) {
case 0:
r = Object.values(this.h);
e = r.length;
t = 0;
c.label = 1;
case 1:
if (!(t < e)) return [ 3, 10 ];
n = r[t];
c.label = 2;
case 2:
c.trys.push([ 2, 7, 8, 9 ]);
i = (o = void 0, __values(n)), a = i.next();
c.label = 3;
case 3:
if (!!a.done) return [ 3, 6 ];
f = a.value;
return [ 4, f ];
case 4:
c.sent();
c.label = 5;
case 5:
a = i.next();
return [ 3, 3 ];
case 6:
return [ 3, 9 ];
case 7:
s = c.sent();
o = {
error: s
};
return [ 3, 9 ];
case 8:
try {
if (a && !a.done && (u = i.return)) u.call(i);
} finally {
if (o) throw o.error;
}
return [ 7 ];
case 9:
++t;
return [ 3, 1 ];
case 10:
return [ 2 ];
}
}));
}.bind(this)();
};
return HashMap;
}(HashContainer);
export default HashMap;

View 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;

View File

@@ -0,0 +1,325 @@
var __extends = this && this.t || function() {
var extendStatics = function(e, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(e, t) {
e.__proto__ = t;
} || function(e, t) {
for (var r in t) if (Object.prototype.hasOwnProperty.call(t, r)) e[r] = t[r];
};
return extendStatics(e, t);
};
return function(e, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(e, t);
function __() {
this.constructor = e;
}
e.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
var __generator = this && this.i || function(e, t) {
var r = {
label: 0,
sent: function() {
if (a[0] & 1) throw a[1];
return a[1];
},
trys: [],
ops: []
}, n, i, a, s;
return s = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function verb(e) {
return function(t) {
return step([ e, t ]);
};
}
function step(s) {
if (n) throw new TypeError("Generator is already executing.");
while (r) try {
if (n = 1, i && (a = s[0] & 2 ? i["return"] : s[0] ? i["throw"] || ((a = i["return"]) && a.call(i),
0) : i.next) && !(a = a.call(i, s[1])).done) return a;
if (i = 0, a) s = [ s[0] & 2, a.value ];
switch (s[0]) {
case 0:
case 1:
a = s;
break;
case 4:
r.label++;
return {
value: s[1],
done: false
};
case 5:
r.label++;
i = s[1];
s = [ 0 ];
continue;
case 7:
s = r.ops.pop();
r.trys.pop();
continue;
default:
if (!(a = r.trys, a = a.length > 0 && a[a.length - 1]) && (s[0] === 6 || s[0] === 2)) {
r = 0;
continue;
}
if (s[0] === 3 && (!a || s[1] > a[0] && s[1] < a[3])) {
r.label = s[1];
break;
}
if (s[0] === 6 && r.label < a[1]) {
r.label = a[1];
a = s;
break;
}
if (a && r.label < a[2]) {
r.label = a[2];
r.ops.push(s);
break;
}
if (a[2]) r.ops.pop();
r.trys.pop();
continue;
}
s = t.call(e, r);
} catch (e) {
s = [ 6, e ];
i = 0;
} finally {
n = a = 0;
}
if (s[0] & 5) throw s[1];
return {
value: s[0] ? s[1] : void 0,
done: true
};
}
};
var __values = this && this.u || function(e) {
var t = typeof Symbol === "function" && Symbol.iterator, r = t && e[t], n = 0;
if (r) return r.call(e);
if (e && typeof e.length === "number") return {
next: function() {
if (e && n >= e.length) e = void 0;
return {
value: e && e[n++],
done: !e
};
}
};
throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import HashContainer from "./Base";
import Vector from "../SequentialContainer/Vector";
import OrderedSet from "../TreeContainer/OrderedSet";
var HashSet = function(e) {
__extends(HashSet, e);
function HashSet(t, r, n) {
if (t === void 0) {
t = [];
}
var i = e.call(this, r, n) || this;
i.h = [];
t.forEach((function(e) {
return i.insert(e);
}));
return i;
}
HashSet.prototype.v = function() {
var e = this;
if (this.l >= 1073741824) return;
var t = [];
var r = this.l;
this.l <<= 1;
var n = Object.keys(this.h);
var i = n.length;
var _loop_1 = function(i) {
var s = parseInt(n[i]);
var o = a.h[s];
var f = o.size();
if (f === 0) return "continue";
if (f === 1) {
var u = o.front();
t[a.p(u) & a.l - 1] = new Vector([ u ], false);
return "continue";
}
var c = [];
var h = [];
o.forEach((function(t) {
var n = e.p(t);
if ((n & r) === 0) {
c.push(t);
} else h.push(t);
}));
if (o instanceof OrderedSet) {
if (c.length > 6) {
t[s] = new OrderedSet(c);
} else {
t[s] = new Vector(c, false);
}
if (h.length > 6) {
t[s + r] = new OrderedSet(h);
} else {
t[s + r] = new Vector(h, false);
}
} else {
t[s] = new Vector(c, false);
t[s + r] = new Vector(h, false);
}
};
var a = this;
for (var s = 0; s < i; ++s) {
_loop_1(s);
}
this.h = t;
};
HashSet.prototype.forEach = function(e) {
var t = Object.values(this.h);
var r = t.length;
var n = 0;
for (var i = 0; i < r; ++i) {
t[i].forEach((function(t) {
return e(t, n++);
}));
}
};
HashSet.prototype.insert = function(e) {
var t = this.p(e) & this.l - 1;
var r = this.h[t];
if (!r) {
this.h[t] = new Vector([ e ], false);
this.o += 1;
} else {
var n = r.size();
if (r instanceof Vector) {
if (!r.find(e).equals(r.end())) return;
r.pushBack(e);
if (n + 1 >= 8) {
if (this.l <= 64) {
this.o += 1;
this.v();
return;
}
this.h[t] = new OrderedSet(r);
}
this.o += 1;
} else {
r.insert(e);
var i = r.size();
this.o += i - n;
}
}
if (this.o > this.l * .75) {
this.v();
}
};
HashSet.prototype.eraseElementByKey = function(e) {
var t = this.p(e) & this.l - 1;
var r = this.h[t];
if (!r) return;
var n = r.size();
if (n === 0) return;
if (r instanceof Vector) {
r.eraseElementByValue(e);
var i = r.size();
this.o += i - n;
} else {
r.eraseElementByKey(e);
var i = r.size();
this.o += i - n;
if (i <= 6) {
this.h[t] = new Vector(r);
}
}
};
HashSet.prototype.find = function(e) {
var t = this.p(e) & this.l - 1;
var r = this.h[t];
if (!r) return false;
return !r.find(e).equals(r.end());
};
HashSet.prototype[Symbol.iterator] = function() {
return function() {
var e, t, r, n, i, a, s, o;
var f, u;
return __generator(this, (function(c) {
switch (c.label) {
case 0:
e = Object.values(this.h);
t = e.length;
r = 0;
c.label = 1;
case 1:
if (!(r < t)) return [ 3, 10 ];
n = e[r];
c.label = 2;
case 2:
c.trys.push([ 2, 7, 8, 9 ]);
i = (f = void 0, __values(n)), a = i.next();
c.label = 3;
case 3:
if (!!a.done) return [ 3, 6 ];
s = a.value;
return [ 4, s ];
case 4:
c.sent();
c.label = 5;
case 5:
a = i.next();
return [ 3, 3 ];
case 6:
return [ 3, 9 ];
case 7:
o = c.sent();
f = {
error: o
};
return [ 3, 9 ];
case 8:
try {
if (a && !a.done && (u = i.return)) u.call(i);
} finally {
if (f) throw f.error;
}
return [ 7 ];
case 9:
++r;
return [ 3, 1 ];
case 10:
return [ 2 ];
}
}));
}.bind(this)();
};
return HashSet;
}(HashContainer);
export default HashSet;

View File

@@ -0,0 +1,48 @@
import { Base, initContainer } from "../ContainerBase";
declare class PriorityQueue<T> extends Base {
/**
* @description PriorityQueue's constructor.
* @param container Initialize container, must have a forEach function.
* @param cmp Compare 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>, cmp?: (x: T, y: T) => number, copy?: boolean);
clear(): void;
/**
* @description Push element into a container in order.
* @param item The element you want to push.
*/
push(item: T): void;
/**
* @description Removes the top element.
*/
pop(): void;
/**
* @description Accesses the top element.
*/
top(): T | undefined;
/**
* @description Check if element is in heap.
* @param item The item want to find.
* @return Boolean about if element is in heap.
*/
find(item: T): boolean;
/**
* @description Remove specified item from heap.
* @param item The item want to remove.
* @return Boolean about if remove success.
*/
remove(item: T): boolean;
/**
* @description Update item and it's pos in the heap.
* @param item The item want to update.
* @return Boolean about if update success.
*/
updateItem(item: T): boolean;
/**
* @return Return a copy array of heap.
*/
toArray(): T[];
}
export default PriorityQueue;

View File

@@ -0,0 +1,167 @@
var __extends = this && this.t || function() {
var extendStatics = function(i, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(i, t) {
i.__proto__ = t;
} || function(i, t) {
for (var r in t) if (Object.prototype.hasOwnProperty.call(t, r)) i[r] = t[r];
};
return extendStatics(i, t);
};
return function(i, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(i, t);
function __() {
this.constructor = i;
}
i.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
var __read = this && this._ || function(i, t) {
var r = typeof Symbol === "function" && i[Symbol.iterator];
if (!r) return i;
var e = r.call(i), n, u = [], s;
try {
while ((t === void 0 || t-- > 0) && !(n = e.next()).done) u.push(n.value);
} catch (i) {
s = {
error: i
};
} finally {
try {
if (n && !n.done && (r = e["return"])) r.call(e);
} finally {
if (s) throw s.error;
}
}
return u;
};
var __spreadArray = this && this.P || function(i, t, r) {
if (r || arguments.length === 2) for (var e = 0, n = t.length, u; e < n; e++) {
if (u || !(e in t)) {
if (!u) u = Array.prototype.slice.call(t, 0, e);
u[e] = t[e];
}
}
return i.concat(u || Array.prototype.slice.call(t));
};
import { Base } from "../ContainerBase";
var PriorityQueue = function(i) {
__extends(PriorityQueue, i);
function PriorityQueue(t, r, e) {
if (t === void 0) {
t = [];
}
if (r === void 0) {
r = function(i, t) {
if (i > t) return -1;
if (i < t) return 1;
return 0;
};
}
if (e === void 0) {
e = true;
}
var n = i.call(this) || this;
n.A = r;
if (Array.isArray(t)) {
n.m = e ? __spreadArray([], __read(t), false) : t;
} else {
n.m = [];
t.forEach((function(i) {
return n.m.push(i);
}));
}
n.o = n.m.length;
var u = n.o >> 1;
for (var s = n.o - 1 >> 1; s >= 0; --s) {
n.j(s, u);
}
return n;
}
PriorityQueue.prototype.B = function(i) {
var t = this.m[i];
while (i > 0) {
var r = i - 1 >> 1;
var e = this.m[r];
if (this.A(e, t) <= 0) break;
this.m[i] = e;
i = r;
}
this.m[i] = t;
};
PriorityQueue.prototype.j = function(i, t) {
var r = this.m[i];
while (i < t) {
var e = i << 1 | 1;
var n = e + 1;
var u = this.m[e];
if (n < this.o && this.A(u, this.m[n]) > 0) {
e = n;
u = this.m[n];
}
if (this.A(u, r) >= 0) break;
this.m[i] = u;
i = e;
}
this.m[i] = r;
};
PriorityQueue.prototype.clear = function() {
this.o = 0;
this.m.length = 0;
};
PriorityQueue.prototype.push = function(i) {
this.m.push(i);
this.B(this.o);
this.o += 1;
};
PriorityQueue.prototype.pop = function() {
if (!this.o) return;
var i = this.m.pop();
this.o -= 1;
if (this.o) {
this.m[0] = i;
this.j(0, this.o >> 1);
}
};
PriorityQueue.prototype.top = function() {
return this.m[0];
};
PriorityQueue.prototype.find = function(i) {
return this.m.indexOf(i) >= 0;
};
PriorityQueue.prototype.remove = function(i) {
var t = this.m.indexOf(i);
if (t < 0) return false;
if (t === 0) {
this.pop();
} else if (t === this.o - 1) {
this.m.pop();
this.o -= 1;
} else {
this.m.splice(t, 1, this.m.pop());
this.o -= 1;
this.B(t);
this.j(t, this.o >> 1);
}
return true;
};
PriorityQueue.prototype.updateItem = function(i) {
var t = this.m.indexOf(i);
if (t < 0) return false;
this.B(t);
this.j(t, this.o >> 1);
return true;
};
PriorityQueue.prototype.toArray = function() {
return __spreadArray([], __read(this.m), false);
};
return PriorityQueue;
}(Base);
export default PriorityQueue;

View File

@@ -0,0 +1,18 @@
import { Base, initContainer } from "../ContainerBase";
declare class Queue<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Inserts element to queue's end.
*/
push(element: T): void;
/**
* @description Removes the first element.
*/
pop(): void;
/**
* @description Access the first element.
*/
front(): T | undefined;
}
export default Queue;

View File

@@ -0,0 +1,55 @@
var __extends = this && this.t || function() {
var extendStatics = function(e, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(e, t) {
e.__proto__ = t;
} || function(e, t) {
for (var n in t) if (Object.prototype.hasOwnProperty.call(t, n)) e[n] = t[n];
};
return extendStatics(e, t);
};
return function(e, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(e, t);
function __() {
this.constructor = e;
}
e.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
import Deque from "../SequentialContainer/Deque";
import { Base } from "../ContainerBase";
var Queue = function(e) {
__extends(Queue, e);
function Queue(t) {
if (t === void 0) {
t = [];
}
var n = e.call(this) || this;
n.q = new Deque(t);
n.o = n.q.size();
return n;
}
Queue.prototype.clear = function() {
this.q.clear();
this.o = 0;
};
Queue.prototype.push = function(e) {
this.q.pushBack(e);
this.o += 1;
};
Queue.prototype.pop = function() {
this.q.popFront();
if (this.o) this.o -= 1;
};
Queue.prototype.front = function() {
return this.q.front();
};
return Queue;
}(Base);
export default Queue;

View File

@@ -0,0 +1,18 @@
import { Base, initContainer } from "../ContainerBase";
declare class Stack<T> extends Base {
constructor(container?: initContainer<T>);
clear(): void;
/**
* @description Insert element to stack's end.
*/
push(element: T): void;
/**
* @description Removes the end element.
*/
pop(): void;
/**
* @description Accesses the end element.
*/
top(): T | undefined;
}
export default Stack;

View File

@@ -0,0 +1,55 @@
var __extends = this && this.t || function() {
var extendStatics = function(t, n) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, n) {
t.__proto__ = n;
} || function(t, n) {
for (var i in n) if (Object.prototype.hasOwnProperty.call(n, i)) t[i] = n[i];
};
return extendStatics(t, n);
};
return function(t, n) {
if (typeof n !== "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
extendStatics(t, n);
function __() {
this.constructor = t;
}
t.prototype = n === null ? Object.create(n) : (__.prototype = n.prototype, new __);
};
}();
import { Base } from "../ContainerBase";
var Stack = function(t) {
__extends(Stack, t);
function Stack(n) {
if (n === void 0) {
n = [];
}
var i = t.call(this) || this;
i.S = [];
n.forEach((function(t) {
return i.push(t);
}));
return i;
}
Stack.prototype.clear = function() {
this.o = 0;
this.S.length = 0;
};
Stack.prototype.push = function(t) {
this.S.push(t);
this.o += 1;
};
Stack.prototype.pop = function() {
this.S.pop();
if (this.o > 0) this.o -= 1;
};
Stack.prototype.top = function() {
return this.S[this.o - 1];
};
return Stack;
}(Base);
export default Stack;

View File

@@ -0,0 +1,8 @@
import { ContainerIterator } from "../../ContainerBase";
export declare abstract class RandomIterator<T> extends ContainerIterator<T> {
pre: () => this;
next: () => this;
get pointer(): T;
set pointer(newValue: T);
equals(obj: RandomIterator<T>): boolean;
}

View File

@@ -0,0 +1,87 @@
var __extends = this && this.t || function() {
var extendStatics = function(t, r) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, r) {
t.__proto__ = r;
} || function(t, r) {
for (var n in r) if (Object.prototype.hasOwnProperty.call(r, n)) t[n] = r[n];
};
return extendStatics(t, r);
};
return function(t, r) {
if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
extendStatics(t, r);
function __() {
this.constructor = t;
}
t.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
};
}();
import { ContainerIterator } from "../../ContainerBase";
var RandomIterator = function(t) {
__extends(RandomIterator, t);
function RandomIterator(r, n, e, i, o) {
var a = t.call(this, o) || this;
a.D = r;
a.I = n;
a.g = e;
a.R = i;
if (a.iteratorType === 0) {
a.pre = function() {
if (this.D === 0) {
throw new RangeError("Random iterator access denied!");
}
this.D -= 1;
return this;
};
a.next = function() {
if (this.D === this.I()) {
throw new RangeError("Random Iterator access denied!");
}
this.D += 1;
return this;
};
} else {
a.pre = function() {
if (this.D === this.I() - 1) {
throw new RangeError("Random iterator access denied!");
}
this.D += 1;
return this;
};
a.next = function() {
if (this.D === -1) {
throw new RangeError("Random iterator access denied!");
}
this.D -= 1;
return this;
};
}
return a;
}
Object.defineProperty(RandomIterator.prototype, "pointer", {
get: function() {
if (this.D < 0 || this.D > this.I() - 1) {
throw new RangeError;
}
return this.g(this.D);
},
set: function(t) {
if (this.D < 0 || this.D > this.I() - 1) {
throw new RangeError;
}
this.R(this.D, t);
},
enumerable: false,
configurable: true
});
RandomIterator.prototype.equals = function(t) {
return this.D === t.D;
};
return RandomIterator;
}(ContainerIterator);
export { RandomIterator };

View File

@@ -0,0 +1,44 @@
import { Container } from "../../ContainerBase";
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;

View File

@@ -0,0 +1,32 @@
var __extends = this && this.t || function() {
var extendStatics = function(n, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(n, t) {
n.__proto__ = t;
} || function(n, t) {
for (var e in t) if (Object.prototype.hasOwnProperty.call(t, e)) n[e] = t[e];
};
return extendStatics(n, t);
};
return function(n, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(n, t);
function __() {
this.constructor = n;
}
n.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
import { Container } from "../../ContainerBase";
var SequentialContainer = function(n) {
__extends(SequentialContainer, n);
function SequentialContainer() {
return n !== null && n.apply(this, arguments) || this;
}
return SequentialContainer;
}(Container);
export default SequentialContainer;

View File

@@ -0,0 +1,50 @@
import SequentialContainer from './Base';
import { initContainer } from "../ContainerBase";
import { RandomIterator } from "./Base/RandomIterator";
export declare class DequeIterator<T> extends RandomIterator<T> {
copy(): DequeIterator<T>;
}
declare class Deque<T> extends SequentialContainer<T> {
constructor(container?: initContainer<T>, _bucketSize?: number);
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;

View File

@@ -0,0 +1,493 @@
var __extends = this && this.t || function() {
var extendStatics = function(t, i) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, i) {
t.__proto__ = i;
} || function(t, i) {
for (var e in i) if (Object.prototype.hasOwnProperty.call(i, e)) t[e] = i[e];
};
return extendStatics(t, i);
};
return function(t, i) {
if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null");
extendStatics(t, i);
function __() {
this.constructor = t;
}
t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __);
};
}();
var __generator = this && this.i || function(t, i) {
var e = {
label: 0,
sent: function() {
if (h[0] & 1) throw h[1];
return h[1];
},
trys: [],
ops: []
}, r, s, h, n;
return n = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (n[Symbol.iterator] = function() {
return this;
}), n;
function verb(t) {
return function(i) {
return step([ t, i ]);
};
}
function step(n) {
if (r) throw new TypeError("Generator is already executing.");
while (e) try {
if (r = 1, s && (h = n[0] & 2 ? s["return"] : n[0] ? s["throw"] || ((h = s["return"]) && h.call(s),
0) : s.next) && !(h = h.call(s, n[1])).done) return h;
if (s = 0, h) n = [ n[0] & 2, h.value ];
switch (n[0]) {
case 0:
case 1:
h = n;
break;
case 4:
e.label++;
return {
value: n[1],
done: false
};
case 5:
e.label++;
s = n[1];
n = [ 0 ];
continue;
case 7:
n = e.ops.pop();
e.trys.pop();
continue;
default:
if (!(h = e.trys, h = h.length > 0 && h[h.length - 1]) && (n[0] === 6 || n[0] === 2)) {
e = 0;
continue;
}
if (n[0] === 3 && (!h || n[1] > h[0] && n[1] < h[3])) {
e.label = n[1];
break;
}
if (n[0] === 6 && e.label < h[1]) {
e.label = h[1];
h = n;
break;
}
if (h && e.label < h[2]) {
e.label = h[2];
e.ops.push(n);
break;
}
if (h[2]) e.ops.pop();
e.trys.pop();
continue;
}
n = i.call(t, e);
} catch (t) {
n = [ 6, t ];
s = 0;
} finally {
r = h = 0;
}
if (n[0] & 5) throw n[1];
return {
value: n[0] ? n[1] : void 0,
done: true
};
}
};
var __read = this && this._ || function(t, i) {
var e = typeof Symbol === "function" && t[Symbol.iterator];
if (!e) return t;
var r = e.call(t), s, h = [], n;
try {
while ((i === void 0 || i-- > 0) && !(s = r.next()).done) h.push(s.value);
} catch (t) {
n = {
error: t
};
} finally {
try {
if (s && !s.done && (e = r["return"])) e.call(r);
} finally {
if (n) throw n.error;
}
}
return h;
};
var __spreadArray = this && this.P || function(t, i, e) {
if (e || arguments.length === 2) for (var r = 0, s = i.length, h; r < s; r++) {
if (h || !(r in i)) {
if (!h) h = Array.prototype.slice.call(i, 0, r);
h[r] = i[r];
}
}
return t.concat(h || Array.prototype.slice.call(i));
};
import SequentialContainer from "./Base";
import { RandomIterator } from "./Base/RandomIterator";
var DequeIterator = function(t) {
__extends(DequeIterator, t);
function DequeIterator() {
return t !== null && t.apply(this, arguments) || this;
}
DequeIterator.prototype.copy = function() {
return new DequeIterator(this.D, this.I, this.g, this.R, this.iteratorType);
};
return DequeIterator;
}(RandomIterator);
export { DequeIterator };
var Deque = function(t) {
__extends(Deque, t);
function Deque(i, e) {
if (i === void 0) {
i = [];
}
if (e === void 0) {
e = 1 << 12;
}
var r = t.call(this) || this;
r.M = 0;
r.k = 0;
r.C = 0;
r.O = 0;
r.l = 0;
r.N = [];
var s;
if ("size" in i) {
if (typeof i.size === "number") {
s = i.size;
} else {
s = i.size();
}
} else if ("length" in i) {
s = i.length;
} else {
throw new RangeError("Can't get container's size!");
}
r.T = e;
r.l = Math.max(Math.ceil(s / r.T), 1);
for (var h = 0; h < r.l; ++h) {
r.N.push(new Array(r.T));
}
var n = Math.ceil(s / r.T);
r.M = r.C = (r.l >> 1) - (n >> 1);
r.k = r.O = r.T - s % r.T >> 1;
i.forEach((function(t) {
return r.pushBack(t);
}));
r.size = r.size.bind(r);
r.getElementByPos = r.getElementByPos.bind(r);
r.setElementByPos = r.setElementByPos.bind(r);
return r;
}
Deque.prototype.v = function() {
var t = [];
var i = Math.max(this.l >> 1, 1);
for (var e = 0; e < i; ++e) {
t[e] = new Array(this.T);
}
for (var e = this.M; e < this.l; ++e) {
t[t.length] = this.N[e];
}
for (var e = 0; e < this.C; ++e) {
t[t.length] = this.N[e];
}
t[t.length] = __spreadArray([], __read(this.N[this.C]), false);
this.M = i;
this.C = t.length - 1;
for (var e = 0; e < i; ++e) {
t[t.length] = new Array(this.T);
}
this.N = t;
this.l = t.length;
};
Deque.prototype.G = function(t) {
var i = this.k + t + 1;
var e = i % this.T;
var r = e - 1;
var s = this.M + (i - e) / this.T;
if (e === 0) s -= 1;
s %= this.l;
if (r < 0) r += this.T;
return {
curNodeBucketIndex: s,
curNodePointerIndex: r
};
};
Deque.prototype.clear = function() {
this.N = [ [] ];
this.l = 1;
this.M = this.C = this.o = 0;
this.k = this.O = this.T >> 1;
};
Deque.prototype.front = function() {
return this.N[this.M][this.k];
};
Deque.prototype.back = function() {
return this.N[this.C][this.O];
};
Deque.prototype.begin = function() {
return new DequeIterator(0, this.size, this.getElementByPos, this.setElementByPos);
};
Deque.prototype.end = function() {
return new DequeIterator(this.o, this.size, this.getElementByPos, this.setElementByPos);
};
Deque.prototype.rBegin = function() {
return new DequeIterator(this.o - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
};
Deque.prototype.rEnd = function() {
return new DequeIterator(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
};
Deque.prototype.pushBack = function(t) {
if (this.o) {
if (this.O < this.T - 1) {
this.O += 1;
} else if (this.C < this.l - 1) {
this.C += 1;
this.O = 0;
} else {
this.C = 0;
this.O = 0;
}
if (this.C === this.M && this.O === this.k) this.v();
}
this.o += 1;
this.N[this.C][this.O] = t;
};
Deque.prototype.popBack = function() {
if (!this.o) return;
this.N[this.C][this.O] = undefined;
if (this.o !== 1) {
if (this.O > 0) {
this.O -= 1;
} else if (this.C > 0) {
this.C -= 1;
this.O = this.T - 1;
} else {
this.C = this.l - 1;
this.O = this.T - 1;
}
}
this.o -= 1;
};
Deque.prototype.pushFront = function(t) {
if (this.o) {
if (this.k > 0) {
this.k -= 1;
} else if (this.M > 0) {
this.M -= 1;
this.k = this.T - 1;
} else {
this.M = this.l - 1;
this.k = this.T - 1;
}
if (this.M === this.C && this.k === this.O) this.v();
}
this.o += 1;
this.N[this.M][this.k] = t;
};
Deque.prototype.popFront = function() {
if (!this.o) return;
this.N[this.M][this.k] = undefined;
if (this.o !== 1) {
if (this.k < this.T - 1) {
this.k += 1;
} else if (this.M < this.l - 1) {
this.M += 1;
this.k = 0;
} else {
this.M = 0;
this.k = 0;
}
}
this.o -= 1;
};
Deque.prototype.forEach = function(t) {
for (var i = 0; i < this.o; ++i) {
t(this.getElementByPos(i), i);
}
};
Deque.prototype.getElementByPos = function(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
var i = this.G(t), e = i.curNodeBucketIndex, r = i.curNodePointerIndex;
return this.N[e][r];
};
Deque.prototype.setElementByPos = function(t, i) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
var e = this.G(t), r = e.curNodeBucketIndex, s = e.curNodePointerIndex;
this.N[r][s] = i;
};
Deque.prototype.insert = function(t, i, e) {
if (e === void 0) {
e = 1;
}
if (t < 0 || t > this.o) {
throw new RangeError;
}
if (t === 0) {
while (e--) this.pushFront(i);
} else if (t === this.o) {
while (e--) this.pushBack(i);
} else {
var r = [];
for (var s = t; s < this.o; ++s) {
r.push(this.getElementByPos(s));
}
this.cut(t - 1);
for (var s = 0; s < e; ++s) this.pushBack(i);
for (var s = 0; s < r.length; ++s) this.pushBack(r[s]);
}
};
Deque.prototype.cut = function(t) {
if (t < 0) {
this.clear();
return;
}
var i = this.G(t), e = i.curNodeBucketIndex, r = i.curNodePointerIndex;
this.C = e;
this.O = r;
this.o = t + 1;
};
Deque.prototype.eraseElementByPos = function(t) {
var i = this;
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
if (t === 0) this.popFront(); else if (t === this.o - 1) this.popBack(); else {
var e = [];
for (var r = t + 1; r < this.o; ++r) {
e.push(this.getElementByPos(r));
}
this.cut(t);
this.popBack();
e.forEach((function(t) {
return i.pushBack(t);
}));
}
};
Deque.prototype.eraseElementByValue = function(t) {
if (!this.o) return;
var i = [];
for (var e = 0; e < this.o; ++e) {
var r = this.getElementByPos(e);
if (r !== t) i.push(r);
}
var s = i.length;
for (var e = 0; e < s; ++e) this.setElementByPos(e, i[e]);
this.cut(s - 1);
};
Deque.prototype.eraseElementByIterator = function(t) {
var i = t.D;
this.eraseElementByPos(i);
t = t.next();
return t;
};
Deque.prototype.find = function(t) {
for (var i = 0; i < this.o; ++i) {
if (this.getElementByPos(i) === t) {
return new DequeIterator(i, this.size, this.getElementByPos, this.setElementByPos);
}
}
return this.end();
};
Deque.prototype.reverse = function() {
var t = 0;
var i = this.o - 1;
while (t < i) {
var e = this.getElementByPos(t);
this.setElementByPos(t, this.getElementByPos(i));
this.setElementByPos(i, e);
t += 1;
i -= 1;
}
};
Deque.prototype.unique = function() {
if (this.o <= 1) return;
var t = 1;
var i = this.getElementByPos(0);
for (var e = 1; e < this.o; ++e) {
var r = this.getElementByPos(e);
if (r !== i) {
i = r;
this.setElementByPos(t++, r);
}
}
while (this.o > t) this.popBack();
};
Deque.prototype.sort = function(t) {
var i = [];
for (var e = 0; e < this.o; ++e) {
i.push(this.getElementByPos(e));
}
i.sort(t);
for (var e = 0; e < this.o; ++e) this.setElementByPos(e, i[e]);
};
Deque.prototype.shrinkToFit = function() {
if (!this.o) return;
var t = [];
this.forEach((function(i) {
return t.push(i);
}));
this.l = Math.max(Math.ceil(this.o / this.T), 1);
this.o = this.M = this.C = this.k = this.O = 0;
this.N = [];
for (var i = 0; i < this.l; ++i) {
this.N.push(new Array(this.T));
}
for (var i = 0; i < t.length; ++i) this.pushBack(t[i]);
};
Deque.prototype[Symbol.iterator] = function() {
return function() {
var t;
return __generator(this, (function(i) {
switch (i.label) {
case 0:
t = 0;
i.label = 1;
case 1:
if (!(t < this.o)) return [ 3, 4 ];
return [ 4, this.getElementByPos(t) ];
case 2:
i.sent();
i.label = 3;
case 3:
++t;
return [ 3, 1 ];
case 4:
return [ 2 ];
}
}));
}.bind(this)();
};
return Deque;
}(SequentialContainer);
export default Deque;

View File

@@ -0,0 +1,49 @@
import SequentialContainer from './Base';
import { ContainerIterator, initContainer } from "../ContainerBase";
export declare class LinkListIterator<T> extends ContainerIterator<T> {
pre: () => this;
next: () => this;
get pointer(): T;
set pointer(newValue: T);
equals(obj: LinkListIterator<T>): boolean;
copy(): LinkListIterator<T>;
}
declare class LinkList<T> extends SequentialContainer<T> {
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;

View File

@@ -0,0 +1,500 @@
var __extends = this && this.t || function() {
var extendStatics = function(i, t) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(i, t) {
i.__proto__ = t;
} || function(i, t) {
for (var n in t) if (Object.prototype.hasOwnProperty.call(t, n)) i[n] = t[n];
};
return extendStatics(i, t);
};
return function(i, t) {
if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
extendStatics(i, t);
function __() {
this.constructor = i;
}
i.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
};
}();
var __generator = this && this.i || function(i, t) {
var n = {
label: 0,
sent: function() {
if (s[0] & 1) throw s[1];
return s[1];
},
trys: [],
ops: []
}, r, e, s, h;
return h = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (h[Symbol.iterator] = function() {
return this;
}), h;
function verb(i) {
return function(t) {
return step([ i, t ]);
};
}
function step(h) {
if (r) throw new TypeError("Generator is already executing.");
while (n) try {
if (r = 1, e && (s = h[0] & 2 ? e["return"] : h[0] ? e["throw"] || ((s = e["return"]) && s.call(e),
0) : e.next) && !(s = s.call(e, h[1])).done) return s;
if (e = 0, s) h = [ h[0] & 2, s.value ];
switch (h[0]) {
case 0:
case 1:
s = h;
break;
case 4:
n.label++;
return {
value: h[1],
done: false
};
case 5:
n.label++;
e = h[1];
h = [ 0 ];
continue;
case 7:
h = n.ops.pop();
n.trys.pop();
continue;
default:
if (!(s = n.trys, s = s.length > 0 && s[s.length - 1]) && (h[0] === 6 || h[0] === 2)) {
n = 0;
continue;
}
if (h[0] === 3 && (!s || h[1] > s[0] && h[1] < s[3])) {
n.label = h[1];
break;
}
if (h[0] === 6 && n.label < s[1]) {
n.label = s[1];
s = h;
break;
}
if (s && n.label < s[2]) {
n.label = s[2];
n.ops.push(h);
break;
}
if (s[2]) n.ops.pop();
n.trys.pop();
continue;
}
h = t.call(i, n);
} catch (i) {
h = [ 6, i ];
e = 0;
} finally {
r = s = 0;
}
if (h[0] & 5) throw h[1];
return {
value: h[0] ? h[1] : void 0,
done: true
};
}
};
import SequentialContainer from "./Base";
import { ContainerIterator } from "../ContainerBase";
var LinkNode = function() {
function LinkNode(i) {
this.L = undefined;
this.F = undefined;
this.H = undefined;
this.L = i;
}
return LinkNode;
}();
export { LinkNode };
var LinkListIterator = function(i) {
__extends(LinkListIterator, i);
function LinkListIterator(t, n, r) {
var e = i.call(this, r) || this;
e.D = t;
e.J = n;
if (e.iteratorType === 0) {
e.pre = function() {
if (this.D.F === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
this.D = this.D.F;
return this;
};
e.next = function() {
if (this.D === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
this.D = this.D.H;
return this;
};
} else {
e.pre = function() {
if (this.D.H === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
this.D = this.D.H;
return this;
};
e.next = function() {
if (this.D === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
this.D = this.D.F;
return this;
};
}
return e;
}
Object.defineProperty(LinkListIterator.prototype, "pointer", {
get: function() {
if (this.D === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
return this.D.L;
},
set: function(i) {
if (this.D === this.J) {
throw new RangeError("LinkList iterator access denied!");
}
this.D.L = i;
},
enumerable: false,
configurable: true
});
LinkListIterator.prototype.equals = function(i) {
return this.D === i.D;
};
LinkListIterator.prototype.copy = function() {
return new LinkListIterator(this.D, this.J, this.iteratorType);
};
return LinkListIterator;
}(ContainerIterator);
export { LinkListIterator };
var LinkList = function(i) {
__extends(LinkList, i);
function LinkList(t) {
if (t === void 0) {
t = [];
}
var n = i.call(this) || this;
n.J = new LinkNode;
n.K = undefined;
n.U = undefined;
t.forEach((function(i) {
return n.pushBack(i);
}));
return n;
}
LinkList.prototype.clear = function() {
this.o = 0;
this.K = this.U = undefined;
this.J.F = this.J.H = undefined;
};
LinkList.prototype.begin = function() {
return new LinkListIterator(this.K || this.J, this.J);
};
LinkList.prototype.end = function() {
return new LinkListIterator(this.J, this.J);
};
LinkList.prototype.rBegin = function() {
return new LinkListIterator(this.U || this.J, this.J, 1);
};
LinkList.prototype.rEnd = function() {
return new LinkListIterator(this.J, this.J, 1);
};
LinkList.prototype.front = function() {
return this.K ? this.K.L : undefined;
};
LinkList.prototype.back = function() {
return this.U ? this.U.L : undefined;
};
LinkList.prototype.forEach = function(i) {
if (!this.o) return;
var t = this.K;
var n = 0;
while (t !== this.J) {
i(t.L, n++);
t = t.H;
}
};
LinkList.prototype.getElementByPos = function(i) {
if (i < 0 || i > this.o - 1) {
throw new RangeError;
}
var t = this.K;
while (i--) {
t = t.H;
}
return t.L;
};
LinkList.prototype.eraseElementByPos = function(i) {
if (i < 0 || i > this.o - 1) {
throw new RangeError;
}
if (i === 0) this.popFront(); else if (i === this.o - 1) this.popBack(); else {
var t = this.K;
while (i--) {
t = t.H;
}
t = t;
var n = t.F;
var r = t.H;
r.F = n;
n.H = r;
this.o -= 1;
}
};
LinkList.prototype.eraseElementByValue = function(i) {
while (this.K && this.K.L === i) this.popFront();
while (this.U && this.U.L === i) this.popBack();
if (!this.K) return;
var t = this.K;
while (t !== this.J) {
if (t.L === i) {
var n = t.F;
var r = t.H;
r.F = n;
n.H = r;
this.o -= 1;
}
t = t.H;
}
};
LinkList.prototype.eraseElementByIterator = function(i) {
var t = i.D;
if (t === this.J) {
throw new RangeError("Invalid iterator");
}
i = i.next();
if (this.K === t) this.popFront(); else if (this.U === t) this.popBack(); else {
var n = t.F;
var r = t.H;
r.F = n;
n.H = r;
this.o -= 1;
}
return i;
};
LinkList.prototype.pushBack = function(i) {
this.o += 1;
var t = new LinkNode(i);
if (!this.U) {
this.K = this.U = t;
this.J.H = this.K;
this.K.F = this.J;
} else {
this.U.H = t;
t.F = this.U;
this.U = t;
}
this.U.H = this.J;
this.J.F = this.U;
};
LinkList.prototype.popBack = function() {
if (!this.U) return;
this.o -= 1;
if (this.K === this.U) {
this.K = this.U = undefined;
this.J.H = undefined;
} else {
this.U = this.U.F;
this.U.H = this.J;
}
this.J.F = this.U;
};
LinkList.prototype.setElementByPos = function(i, t) {
if (i < 0 || i > this.o - 1) {
throw new RangeError;
}
var n = this.K;
while (i--) {
n = n.H;
}
n.L = t;
};
LinkList.prototype.insert = function(i, t, n) {
if (n === void 0) {
n = 1;
}
if (i < 0 || i > this.o) {
throw new RangeError;
}
if (n <= 0) return;
if (i === 0) {
while (n--) this.pushFront(t);
} else if (i === this.o) {
while (n--) this.pushBack(t);
} else {
var r = this.K;
for (var e = 1; e < i; ++e) {
r = r.H;
}
var s = r.H;
this.o += n;
while (n--) {
r.H = new LinkNode(t);
r.H.F = r;
r = r.H;
}
r.H = s;
s.F = r;
}
};
LinkList.prototype.find = function(i) {
if (!this.K) return this.end();
var t = this.K;
while (t !== this.J) {
if (t.L === i) {
return new LinkListIterator(t, this.J);
}
t = t.H;
}
return this.end();
};
LinkList.prototype.reverse = function() {
if (this.o <= 1) return;
var i = this.K;
var t = this.U;
var n = 0;
while (n << 1 < this.o) {
var r = i.L;
i.L = t.L;
t.L = r;
i = i.H;
t = t.F;
n += 1;
}
};
LinkList.prototype.unique = function() {
if (this.o <= 1) return;
var i = this.K;
while (i !== this.J) {
var t = i;
while (t.H && t.L === t.H.L) {
t = t.H;
this.o -= 1;
}
i.H = t.H;
i.H.F = i;
i = i.H;
}
};
LinkList.prototype.sort = function(i) {
if (this.o <= 1) return;
var t = [];
this.forEach((function(i) {
return t.push(i);
}));
t.sort(i);
var n = this.K;
t.forEach((function(i) {
n.L = i;
n = n.H;
}));
};
LinkList.prototype.pushFront = function(i) {
this.o += 1;
var t = new LinkNode(i);
if (!this.K) {
this.K = this.U = t;
this.U.H = this.J;
this.J.F = this.U;
} else {
t.H = this.K;
this.K.F = t;
this.K = t;
}
this.J.H = this.K;
this.K.F = this.J;
};
LinkList.prototype.popFront = function() {
if (!this.K) return;
this.o -= 1;
if (this.K === this.U) {
this.K = this.U = undefined;
this.J.F = this.U;
} else {
this.K = this.K.H;
this.K.F = this.J;
}
this.J.H = this.K;
};
LinkList.prototype.merge = function(i) {
var t = this;
if (!this.K) {
i.forEach((function(i) {
return t.pushBack(i);
}));
return;
}
var n = this.K;
i.forEach((function(i) {
while (n && n !== t.J && n.L <= i) {
n = n.H;
}
if (n === t.J) {
t.pushBack(i);
n = t.U;
} else if (n === t.K) {
t.pushFront(i);
n = t.K;
} else {
t.o += 1;
var r = n.F;
r.H = new LinkNode(i);
r.H.F = r;
r.H.H = n;
n.F = r.H;
}
}));
};
LinkList.prototype[Symbol.iterator] = function() {
return function() {
var i;
return __generator(this, (function(t) {
switch (t.label) {
case 0:
if (!this.K) return [ 2 ];
i = this.K;
t.label = 1;
case 1:
if (!(i !== this.J)) return [ 3, 3 ];
return [ 4, i.L ];
case 2:
t.sent();
i = i.H;
return [ 3, 1 ];
case 3:
return [ 2 ];
}
}));
}.bind(this)();
};
return LinkList;
}(SequentialContainer);
export default LinkList;

View File

@@ -0,0 +1,37 @@
import SequentialContainer from './Base';
import { initContainer } from "../ContainerBase";
import { RandomIterator } from "./Base/RandomIterator";
export declare class VectorIterator<T> extends RandomIterator<T> {
copy(): VectorIterator<T>;
}
declare class Vector<T> extends SequentialContainer<T> {
/**
* @description Vector's constructor.
* @param container Initialize container, must have a forEach function.
* @param copy When the container is an array, you can choose to directly operate on the original object of
* the array or perform a shallow copy. The default is shallow copy.
*/
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;

View File

@@ -0,0 +1,318 @@
var __extends = this && this.t || function() {
var extendStatics = function(t, r) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, r) {
t.__proto__ = r;
} || function(t, r) {
for (var e in r) if (Object.prototype.hasOwnProperty.call(r, e)) t[e] = r[e];
};
return extendStatics(t, r);
};
return function(t, r) {
if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
extendStatics(t, r);
function __() {
this.constructor = t;
}
t.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
};
}();
var __generator = this && this.i || function(t, r) {
var e = {
label: 0,
sent: function() {
if (o[0] & 1) throw o[1];
return o[1];
},
trys: [],
ops: []
}, n, i, o, s;
return s = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (s[Symbol.iterator] = function() {
return this;
}), s;
function verb(t) {
return function(r) {
return step([ t, r ]);
};
}
function step(s) {
if (n) throw new TypeError("Generator is already executing.");
while (e) try {
if (n = 1, i && (o = s[0] & 2 ? i["return"] : s[0] ? i["throw"] || ((o = i["return"]) && o.call(i),
0) : i.next) && !(o = o.call(i, s[1])).done) return o;
if (i = 0, o) s = [ s[0] & 2, o.value ];
switch (s[0]) {
case 0:
case 1:
o = s;
break;
case 4:
e.label++;
return {
value: s[1],
done: false
};
case 5:
e.label++;
i = s[1];
s = [ 0 ];
continue;
case 7:
s = e.ops.pop();
e.trys.pop();
continue;
default:
if (!(o = e.trys, o = o.length > 0 && o[o.length - 1]) && (s[0] === 6 || s[0] === 2)) {
e = 0;
continue;
}
if (s[0] === 3 && (!o || s[1] > o[0] && s[1] < o[3])) {
e.label = s[1];
break;
}
if (s[0] === 6 && e.label < o[1]) {
e.label = o[1];
o = s;
break;
}
if (o && e.label < o[2]) {
e.label = o[2];
e.ops.push(s);
break;
}
if (o[2]) e.ops.pop();
e.trys.pop();
continue;
}
s = r.call(t, e);
} catch (t) {
s = [ 6, t ];
i = 0;
} finally {
n = o = 0;
}
if (s[0] & 5) throw s[1];
return {
value: s[0] ? s[1] : void 0,
done: true
};
}
};
var __read = this && this._ || function(t, r) {
var e = typeof Symbol === "function" && t[Symbol.iterator];
if (!e) return t;
var n = e.call(t), i, o = [], s;
try {
while ((r === void 0 || r-- > 0) && !(i = n.next()).done) o.push(i.value);
} catch (t) {
s = {
error: t
};
} finally {
try {
if (i && !i.done && (e = n["return"])) e.call(n);
} finally {
if (s) throw s.error;
}
}
return o;
};
var __spreadArray = this && this.P || function(t, r, e) {
if (e || arguments.length === 2) for (var n = 0, i = r.length, o; n < i; n++) {
if (o || !(n in r)) {
if (!o) o = Array.prototype.slice.call(r, 0, n);
o[n] = r[n];
}
}
return t.concat(o || Array.prototype.slice.call(r));
};
var __values = this && this.u || function(t) {
var r = typeof Symbol === "function" && Symbol.iterator, e = r && t[r], n = 0;
if (e) return e.call(t);
if (t && typeof t.length === "number") return {
next: function() {
if (t && n >= t.length) t = void 0;
return {
value: t && t[n++],
done: !t
};
}
};
throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import SequentialContainer from "./Base";
import { RandomIterator } from "./Base/RandomIterator";
var VectorIterator = function(t) {
__extends(VectorIterator, t);
function VectorIterator() {
return t !== null && t.apply(this, arguments) || this;
}
VectorIterator.prototype.copy = function() {
return new VectorIterator(this.D, this.I, this.g, this.R, this.iteratorType);
};
return VectorIterator;
}(RandomIterator);
export { VectorIterator };
var Vector = function(t) {
__extends(Vector, t);
function Vector(r, e) {
if (r === void 0) {
r = [];
}
if (e === void 0) {
e = true;
}
var n = t.call(this) || this;
if (Array.isArray(r)) {
n.V = e ? __spreadArray([], __read(r), false) : r;
n.o = r.length;
} else {
n.V = [];
r.forEach((function(t) {
return n.pushBack(t);
}));
}
n.size = n.size.bind(n);
n.getElementByPos = n.getElementByPos.bind(n);
n.setElementByPos = n.setElementByPos.bind(n);
return n;
}
Vector.prototype.clear = function() {
this.o = 0;
this.V.length = 0;
};
Vector.prototype.begin = function() {
return new VectorIterator(0, this.size, this.getElementByPos, this.setElementByPos);
};
Vector.prototype.end = function() {
return new VectorIterator(this.o, this.size, this.getElementByPos, this.setElementByPos);
};
Vector.prototype.rBegin = function() {
return new VectorIterator(this.o - 1, this.size, this.getElementByPos, this.setElementByPos, 1);
};
Vector.prototype.rEnd = function() {
return new VectorIterator(-1, this.size, this.getElementByPos, this.setElementByPos, 1);
};
Vector.prototype.front = function() {
return this.V[0];
};
Vector.prototype.back = function() {
return this.V[this.o - 1];
};
Vector.prototype.forEach = function(t) {
for (var r = 0; r < this.o; ++r) {
t(this.V[r], r);
}
};
Vector.prototype.getElementByPos = function(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
return this.V[t];
};
Vector.prototype.eraseElementByPos = function(t) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
this.V.splice(t, 1);
this.o -= 1;
};
Vector.prototype.eraseElementByValue = function(t) {
var r = 0;
for (var e = 0; e < this.o; ++e) {
if (this.V[e] !== t) {
this.V[r++] = this.V[e];
}
}
this.o = this.V.length = r;
};
Vector.prototype.eraseElementByIterator = function(t) {
var r = t.D;
t = t.next();
this.eraseElementByPos(r);
return t;
};
Vector.prototype.pushBack = function(t) {
this.V.push(t);
this.o += 1;
};
Vector.prototype.popBack = function() {
if (!this.o) return;
this.V.pop();
this.o -= 1;
};
Vector.prototype.setElementByPos = function(t, r) {
if (t < 0 || t > this.o - 1) {
throw new RangeError;
}
this.V[t] = r;
};
Vector.prototype.insert = function(t, r, e) {
var n;
if (e === void 0) {
e = 1;
}
if (t < 0 || t > this.o) {
throw new RangeError;
}
(n = this.V).splice.apply(n, __spreadArray([ t, 0 ], __read(new Array(e).fill(r)), false));
this.o += e;
};
Vector.prototype.find = function(t) {
for (var r = 0; r < this.o; ++r) {
if (this.V[r] === t) {
return new VectorIterator(r, this.size, this.getElementByPos, this.getElementByPos);
}
}
return this.end();
};
Vector.prototype.reverse = function() {
this.V.reverse();
};
Vector.prototype.unique = function() {
var t = 1;
for (var r = 1; r < this.o; ++r) {
if (this.V[r] !== this.V[r - 1]) {
this.V[t++] = this.V[r];
}
}
this.o = this.V.length = t;
};
Vector.prototype.sort = function(t) {
this.V.sort(t);
};
Vector.prototype[Symbol.iterator] = function() {
return function() {
return __generator(this, (function(t) {
switch (t.label) {
case 0:
return [ 5, __values(this.V) ];
case 1:
return [ 2, t.sent() ];
}
}));
}.bind(this)();
};
return Vector;
}(SequentialContainer);
export default Vector;

View File

@@ -0,0 +1,15 @@
import { ContainerIterator } from "../../ContainerBase";
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`.
*/
get index(): number;
equals(obj: TreeIterator<K, V>): boolean;
}
export default TreeIterator;

View File

@@ -0,0 +1,98 @@
var __extends = this && this.t || function() {
var extendStatics = function(t, r) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(t, r) {
t.__proto__ = r;
} || function(t, r) {
for (var e in r) if (Object.prototype.hasOwnProperty.call(r, e)) t[e] = r[e];
};
return extendStatics(t, r);
};
return function(t, r) {
if (typeof r !== "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
extendStatics(t, r);
function __() {
this.constructor = t;
}
t.prototype = r === null ? Object.create(r) : (__.prototype = r.prototype, new __);
};
}();
import { ContainerIterator } from "../../ContainerBase";
var TreeIterator = function(t) {
__extends(TreeIterator, t);
function TreeIterator(r, e, n) {
var i = t.call(this, n) || this;
i.D = r;
i.J = e;
if (i.iteratorType === 0) {
i.pre = function() {
if (this.D === this.J.Y) {
throw new RangeError("Tree iterator access denied!");
}
this.D = this.D.pre();
return this;
};
i.next = function() {
if (this.D === this.J) {
throw new RangeError("Tree iterator access denied!");
}
this.D = this.D.next();
return this;
};
} else {
i.pre = function() {
if (this.D === this.J.Z) {
throw new RangeError("Tree iterator access denied!");
}
this.D = this.D.next();
return this;
};
i.next = function() {
if (this.D === this.J) {
throw new RangeError("Tree iterator access denied!");
}
this.D = this.D.pre();
return this;
};
}
return i;
}
Object.defineProperty(TreeIterator.prototype, "index", {
get: function() {
var t = this.D;
var r = this.J.tt;
if (t === this.J) {
if (r) {
return r.rt - 1;
}
return 0;
}
var e = 0;
if (t.Y) {
e += t.Y.rt;
}
while (t !== r) {
var n = t.tt;
if (t === n.Z) {
e += 1;
if (n.Y) {
e += n.Y.rt;
}
}
t = n;
}
return e;
},
enumerable: false,
configurable: true
});
TreeIterator.prototype.equals = function(t) {
return this.D === t.D;
};
return TreeIterator;
}(ContainerIterator);
export default TreeIterator;

View File

@@ -0,0 +1,36 @@
export declare class TreeNode<K, V> {
constructor(_key?: K, _value?: V);
/**
* @description Get the pre node.
* @return TreeNode about the pre node.
*/
pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @return TreeNode about the next node.
*/
next(): TreeNode<K, V>;
/**
* @description Rotate _left.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate _right.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
}
export declare class TreeNodeEnableIndex<K, V> extends TreeNode<K, V> {
/**
* @description Rotate _left and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateLeft(): TreeNodeEnableIndex<K, V>;
/**
* @description Rotate _right and do recount.
* @return TreeNode about moved to original position after rotation.
*/
rotateRight(): TreeNode<K, V>;
recount(): void;
}

View File

@@ -0,0 +1,130 @@
var __extends = this && this.t || function() {
var extendStatics = function(e, n) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(e, n) {
e.__proto__ = n;
} || function(e, n) {
for (var i in n) if (Object.prototype.hasOwnProperty.call(n, i)) e[i] = n[i];
};
return extendStatics(e, n);
};
return function(e, n) {
if (typeof n !== "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
extendStatics(e, n);
function __() {
this.constructor = e;
}
e.prototype = n === null ? Object.create(n) : (__.prototype = n.prototype, new __);
};
}();
var TreeNode = function() {
function TreeNode(e, n) {
this.ee = 1;
this.W = undefined;
this.L = undefined;
this.Y = undefined;
this.Z = undefined;
this.tt = undefined;
this.W = e;
this.L = n;
}
TreeNode.prototype.pre = function() {
var e = this;
if (e.ee === 1 && e.tt.tt === e) {
e = e.Z;
} else if (e.Y) {
e = e.Y;
while (e.Z) {
e = e.Z;
}
} else {
var n = e.tt;
while (n.Y === e) {
e = n;
n = e.tt;
}
e = n;
}
return e;
};
TreeNode.prototype.next = function() {
var e = this;
if (e.Z) {
e = e.Z;
while (e.Y) {
e = e.Y;
}
return e;
} else {
var n = e.tt;
while (n.Z === e) {
e = n;
n = e.tt;
}
if (e.Z !== n) {
return n;
} else return e;
}
};
TreeNode.prototype.rotateLeft = function() {
var e = this.tt;
var n = this.Z;
var i = n.Y;
if (e.tt === this) e.tt = n; else if (e.Y === this) e.Y = n; else e.Z = n;
n.tt = e;
n.Y = this;
this.tt = n;
this.Z = i;
if (i) i.tt = this;
return n;
};
TreeNode.prototype.rotateRight = function() {
var e = this.tt;
var n = this.Y;
var i = n.Z;
if (e.tt === this) e.tt = n; else if (e.Y === this) e.Y = n; else e.Z = n;
n.tt = e;
n.Z = this;
this.tt = n;
this.Y = i;
if (i) i.tt = this;
return n;
};
return TreeNode;
}();
export { TreeNode };
var TreeNodeEnableIndex = function(e) {
__extends(TreeNodeEnableIndex, e);
function TreeNodeEnableIndex() {
var n = e !== null && e.apply(this, arguments) || this;
n.Y = undefined;
n.Z = undefined;
n.tt = undefined;
n.rt = 1;
return n;
}
TreeNodeEnableIndex.prototype.rotateLeft = function() {
var n = e.prototype.rotateLeft.call(this);
this.recount();
n.recount();
return n;
};
TreeNodeEnableIndex.prototype.rotateRight = function() {
var n = e.prototype.rotateRight.call(this);
this.recount();
n.recount();
return n;
};
TreeNodeEnableIndex.prototype.recount = function() {
this.rt = 1;
if (this.Y) this.rt += this.Y.rt;
if (this.Z) this.rt += this.Z.rt;
};
return TreeNodeEnableIndex;
}(TreeNode);
export { TreeNodeEnableIndex };

View File

@@ -0,0 +1,55 @@
import type TreeIterator from './TreeIterator';
import { Container } from "../../ContainerBase";
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.
*/
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;
}
export default TreeContainer;

View File

@@ -0,0 +1,525 @@
var __extends = this && this.t || function() {
var extendStatics = function(e, i) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(e, i) {
e.__proto__ = i;
} || function(e, i) {
for (var r in i) if (Object.prototype.hasOwnProperty.call(i, r)) e[r] = i[r];
};
return extendStatics(e, i);
};
return function(e, i) {
if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null");
extendStatics(e, i);
function __() {
this.constructor = e;
}
e.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __);
};
}();
var __read = this && this._ || function(e, i) {
var r = typeof Symbol === "function" && e[Symbol.iterator];
if (!r) return e;
var t = r.call(e), n, s = [], f;
try {
while ((i === void 0 || i-- > 0) && !(n = t.next()).done) s.push(n.value);
} catch (e) {
f = {
error: e
};
} finally {
try {
if (n && !n.done && (r = t["return"])) r.call(t);
} finally {
if (f) throw f.error;
}
}
return s;
};
import { Container } from "../../ContainerBase";
import { TreeNode, TreeNodeEnableIndex } from "./TreeNode";
var TreeContainer = function(e) {
__extends(TreeContainer, e);
function TreeContainer(i, r) {
if (i === void 0) {
i = function(e, i) {
if (e < i) return -1;
if (e > i) return 1;
return 0;
};
}
if (r === void 0) {
r = false;
}
var t = e.call(this) || this;
t.rr = undefined;
t.ie = function(e, i) {
if (e === undefined) return false;
var r = t.ie(e.Y, i);
if (r) return true;
if (i(e)) return true;
return t.ie(e.Z, i);
};
t.A = i;
if (r) {
t.re = TreeNodeEnableIndex;
t.ir = function(e, i, r) {
var t = this.te(e, i, r);
if (t) {
var n = t.tt;
while (n !== this.J) {
n.rt += 1;
n = n.tt;
}
var s = this.ne(t);
if (s) {
var f = s, h = f.parentNode, u = f.grandParent, a = f.curNode;
h.recount();
u.recount();
a.recount();
}
}
};
t.se = function(e) {
var i = this.fe(e);
while (i !== this.J) {
i.rt -= 1;
i = i.tt;
}
};
} else {
t.re = TreeNode;
t.ir = function(e, i, r) {
var t = this.te(e, i, r);
if (t) this.ne(t);
};
t.se = t.fe;
}
t.J = new t.re;
return t;
}
TreeContainer.prototype.$ = function(e, i) {
var r;
while (e) {
var t = this.A(e.W, i);
if (t < 0) {
e = e.Z;
} else if (t > 0) {
r = e;
e = e.Y;
} else return e;
}
return r === undefined ? this.J : r;
};
TreeContainer.prototype.er = function(e, i) {
var r;
while (e) {
var t = this.A(e.W, i);
if (t <= 0) {
e = e.Z;
} else {
r = e;
e = e.Y;
}
}
return r === undefined ? this.J : r;
};
TreeContainer.prototype.tr = function(e, i) {
var r;
while (e) {
var t = this.A(e.W, i);
if (t < 0) {
r = e;
e = e.Z;
} else if (t > 0) {
e = e.Y;
} else return e;
}
return r === undefined ? this.J : r;
};
TreeContainer.prototype.nr = function(e, i) {
var r;
while (e) {
var t = this.A(e.W, i);
if (t < 0) {
r = e;
e = e.Z;
} else {
e = e.Y;
}
}
return r === undefined ? this.J : r;
};
TreeContainer.prototype.he = function(e) {
while (true) {
var i = e.tt;
if (i === this.J) return;
if (e.ee === 1) {
e.ee = 0;
return;
}
if (e === i.Y) {
var r = i.Z;
if (r.ee === 1) {
r.ee = 0;
i.ee = 1;
if (i === this.rr) {
this.rr = i.rotateLeft();
} else i.rotateLeft();
} else {
if (r.Z && r.Z.ee === 1) {
r.ee = i.ee;
i.ee = 0;
r.Z.ee = 0;
if (i === this.rr) {
this.rr = i.rotateLeft();
} else i.rotateLeft();
return;
} else if (r.Y && r.Y.ee === 1) {
r.ee = 1;
r.Y.ee = 0;
r.rotateRight();
} else {
r.ee = 1;
e = i;
}
}
} else {
var r = i.Y;
if (r.ee === 1) {
r.ee = 0;
i.ee = 1;
if (i === this.rr) {
this.rr = i.rotateRight();
} else i.rotateRight();
} else {
if (r.Y && r.Y.ee === 1) {
r.ee = i.ee;
i.ee = 0;
r.Y.ee = 0;
if (i === this.rr) {
this.rr = i.rotateRight();
} else i.rotateRight();
return;
} else if (r.Z && r.Z.ee === 1) {
r.ee = 1;
r.Z.ee = 0;
r.rotateLeft();
} else {
r.ee = 1;
e = i;
}
}
}
}
};
TreeContainer.prototype.fe = function(e) {
var i, r;
if (this.o === 1) {
this.clear();
return this.J;
}
var t = e;
while (t.Y || t.Z) {
if (t.Z) {
t = t.Z;
while (t.Y) t = t.Y;
} else {
t = t.Y;
}
i = __read([ t.W, e.W ], 2), e.W = i[0], t.W = i[1];
r = __read([ t.L, e.L ], 2), e.L = r[0], t.L = r[1];
e = t;
}
if (this.J.Y === t) {
this.J.Y = t.tt;
} else if (this.J.Z === t) {
this.J.Z = t.tt;
}
this.he(t);
var n = t.tt;
if (t === n.Y) {
n.Y = undefined;
} else n.Z = undefined;
this.o -= 1;
this.rr.ee = 0;
return n;
};
TreeContainer.prototype.ne = function(e) {
while (true) {
var i = e.tt;
if (i.ee === 0) return;
var r = i.tt;
if (i === r.Y) {
var t = r.Z;
if (t && t.ee === 1) {
t.ee = i.ee = 0;
if (r === this.rr) return;
r.ee = 1;
e = r;
continue;
} else if (e === i.Z) {
e.ee = 0;
if (e.Y) e.Y.tt = i;
if (e.Z) e.Z.tt = r;
i.Z = e.Y;
r.Y = e.Z;
e.Y = i;
e.Z = r;
if (r === this.rr) {
this.rr = e;
this.J.tt = e;
} else {
var n = r.tt;
if (n.Y === r) {
n.Y = e;
} else n.Z = e;
}
e.tt = r.tt;
i.tt = e;
r.tt = e;
r.ee = 1;
return {
parentNode: i,
grandParent: r,
curNode: e
};
} else {
i.ee = 0;
if (r === this.rr) {
this.rr = r.rotateRight();
} else r.rotateRight();
r.ee = 1;
}
} else {
var t = r.Y;
if (t && t.ee === 1) {
t.ee = i.ee = 0;
if (r === this.rr) return;
r.ee = 1;
e = r;
continue;
} else if (e === i.Y) {
e.ee = 0;
if (e.Y) e.Y.tt = r;
if (e.Z) e.Z.tt = i;
r.Z = e.Y;
i.Y = e.Z;
e.Y = r;
e.Z = i;
if (r === this.rr) {
this.rr = e;
this.J.tt = e;
} else {
var n = r.tt;
if (n.Y === r) {
n.Y = e;
} else n.Z = e;
}
e.tt = r.tt;
i.tt = e;
r.tt = e;
r.ee = 1;
return {
parentNode: i,
grandParent: r,
curNode: e
};
} else {
i.ee = 0;
if (r === this.rr) {
this.rr = r.rotateLeft();
} else r.rotateLeft();
r.ee = 1;
}
}
return;
}
};
TreeContainer.prototype.te = function(e, i, r) {
if (this.rr === undefined) {
this.o += 1;
this.rr = new this.re(e, i);
this.rr.ee = 0;
this.rr.tt = this.J;
this.J.tt = this.rr;
this.J.Y = this.rr;
this.J.Z = this.rr;
return;
}
var t;
var n = this.J.Y;
var s = this.A(n.W, e);
if (s === 0) {
n.L = i;
return;
} else if (s > 0) {
n.Y = new this.re(e, i);
n.Y.tt = n;
t = n.Y;
this.J.Y = t;
} else {
var f = this.J.Z;
var h = this.A(f.W, e);
if (h === 0) {
f.L = i;
return;
} else if (h < 0) {
f.Z = new this.re(e, i);
f.Z.tt = f;
t = f.Z;
this.J.Z = t;
} else {
if (r !== undefined) {
var u = r.D;
if (u !== this.J) {
var a = this.A(u.W, e);
if (a === 0) {
u.L = i;
return;
} else if (a > 0) {
var o = u.pre();
var l = this.A(o.W, e);
if (l === 0) {
o.L = i;
return;
} else if (l < 0) {
t = new this.re(e, i);
if (o.Z === undefined) {
o.Z = t;
t.tt = o;
} else {
u.Y = t;
t.tt = u;
}
}
}
}
}
if (t === undefined) {
t = this.rr;
while (true) {
var d = this.A(t.W, e);
if (d > 0) {
if (t.Y === undefined) {
t.Y = new this.re(e, i);
t.Y.tt = t;
t = t.Y;
break;
}
t = t.Y;
} else if (d < 0) {
if (t.Z === undefined) {
t.Z = new this.re(e, i);
t.Z.tt = t;
t = t.Z;
break;
}
t = t.Z;
} else {
t.L = i;
return;
}
}
}
}
}
this.o += 1;
return t;
};
TreeContainer.prototype.clear = function() {
this.o = 0;
this.rr = undefined;
this.J.tt = undefined;
this.J.Y = this.J.Z = undefined;
};
TreeContainer.prototype.updateKeyByIterator = function(e, i) {
var r = e.D;
if (r === this.J) {
throw new TypeError("Invalid iterator!");
}
if (this.o === 1) {
r.W = i;
return true;
}
if (r === this.J.Y) {
if (this.A(r.next().W, i) > 0) {
r.W = i;
return true;
}
return false;
}
if (r === this.J.Z) {
if (this.A(r.pre().W, i) < 0) {
r.W = i;
return true;
}
return false;
}
var t = r.pre().W;
if (this.A(t, i) >= 0) return false;
var n = r.next().W;
if (this.A(n, i) <= 0) return false;
r.W = i;
return true;
};
TreeContainer.prototype.eraseElementByPos = function(e) {
var i = this;
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
var r = 0;
this.ie(this.rr, (function(t) {
if (e === r) {
i.se(t);
return true;
}
r += 1;
return false;
}));
};
TreeContainer.prototype.ar = function(e, i) {
while (e) {
var r = this.A(e.W, i);
if (r < 0) {
e = e.Z;
} else if (r > 0) {
e = e.Y;
} else return e;
}
return e;
};
TreeContainer.prototype.eraseElementByKey = function(e) {
if (!this.o) return;
var i = this.ar(this.rr, e);
if (i === undefined) return;
this.se(i);
};
TreeContainer.prototype.eraseElementByIterator = function(e) {
var i = e.D;
if (i === this.J) {
throw new RangeError("Invalid iterator");
}
if (i.Z === undefined) {
e = e.next();
}
this.se(i);
return e;
};
TreeContainer.prototype.getHeight = function() {
if (!this.o) return 0;
var traversal = function(e) {
if (!e) return 0;
return Math.max(traversal(e.Y), traversal(e.Z)) + 1;
};
return traversal(this.rr);
};
return TreeContainer;
}(Container);
export default TreeContainer;

View File

@@ -0,0 +1,42 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { initContainer } from "../ContainerBase";
export 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.
*/
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) => 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.
*/
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.
*/
getElementByKey(_key: K): V | undefined;
getElementByPos(pos: number): [K, V];
union(other: OrderedMap<K, V>): void;
[Symbol.iterator](): Generator<[K, V], void, undefined>;
}
export default OrderedMap;

View File

@@ -0,0 +1,334 @@
var __extends = this && this.t || function() {
var extendStatics = function(r, e) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function(r, e) {
r.__proto__ = e;
} || function(r, e) {
for (var t in e) if (Object.prototype.hasOwnProperty.call(e, t)) r[t] = e[t];
};
return extendStatics(r, e);
};
return function(r, e) {
if (typeof e !== "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
extendStatics(r, e);
function __() {
this.constructor = r;
}
r.prototype = e === null ? Object.create(e) : (__.prototype = e.prototype, new __);
};
}();
var __generator = this && this.i || function(r, e) {
var t = {
label: 0,
sent: function() {
if (a[0] & 1) throw a[1];
return a[1];
},
trys: [],
ops: []
}, n, i, a, o;
return o = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (o[Symbol.iterator] = function() {
return this;
}), o;
function verb(r) {
return function(e) {
return step([ r, e ]);
};
}
function step(o) {
if (n) throw new TypeError("Generator is already executing.");
while (t) try {
if (n = 1, i && (a = o[0] & 2 ? i["return"] : o[0] ? i["throw"] || ((a = i["return"]) && a.call(i),
0) : i.next) && !(a = a.call(i, o[1])).done) return a;
if (i = 0, a) o = [ o[0] & 2, a.value ];
switch (o[0]) {
case 0:
case 1:
a = o;
break;
case 4:
t.label++;
return {
value: o[1],
done: false
};
case 5:
t.label++;
i = o[1];
o = [ 0 ];
continue;
case 7:
o = t.ops.pop();
t.trys.pop();
continue;
default:
if (!(a = t.trys, a = a.length > 0 && a[a.length - 1]) && (o[0] === 6 || o[0] === 2)) {
t = 0;
continue;
}
if (o[0] === 3 && (!a || o[1] > a[0] && o[1] < a[3])) {
t.label = o[1];
break;
}
if (o[0] === 6 && t.label < a[1]) {
t.label = a[1];
a = o;
break;
}
if (a && t.label < a[2]) {
t.label = a[2];
t.ops.push(o);
break;
}
if (a[2]) t.ops.pop();
t.trys.pop();
continue;
}
o = e.call(r, t);
} catch (r) {
o = [ 6, r ];
i = 0;
} finally {
n = a = 0;
}
if (o[0] & 5) throw o[1];
return {
value: o[0] ? o[1] : void 0,
done: true
};
}
};
var __read = this && this._ || function(r, e) {
var t = typeof Symbol === "function" && r[Symbol.iterator];
if (!t) return r;
var n = t.call(r), i, a = [], o;
try {
while ((e === void 0 || e-- > 0) && !(i = n.next()).done) a.push(i.value);
} catch (r) {
o = {
error: r
};
} finally {
try {
if (i && !i.done && (t = n["return"])) t.call(n);
} finally {
if (o) throw o.error;
}
}
return a;
};
var __values = this && this.u || function(r) {
var e = typeof Symbol === "function" && Symbol.iterator, t = e && r[e], n = 0;
if (t) return t.call(r);
if (r && typeof r.length === "number") return {
next: function() {
if (r && n >= r.length) r = void 0;
return {
value: r && r[n++],
done: !r
};
}
};
throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import TreeContainer from "./Base";
import TreeIterator from "./Base/TreeIterator";
var OrderedMapIterator = function(r) {
__extends(OrderedMapIterator, r);
function OrderedMapIterator() {
return r !== null && r.apply(this, arguments) || this;
}
Object.defineProperty(OrderedMapIterator.prototype, "pointer", {
get: function() {
var r = this;
if (this.D === this.J) {
throw new RangeError("OrderedMap iterator access denied");
}
return new Proxy([], {
get: function(e, t) {
if (t === "0") return r.D.W; else if (t === "1") return r.D.L;
},
set: function(e, t, n) {
if (t !== "1") {
throw new TypeError("props must be 1");
}
r.D.L = n;
return true;
}
});
},
enumerable: false,
configurable: true
});
OrderedMapIterator.prototype.copy = function() {
return new OrderedMapIterator(this.D, this.J, this.iteratorType);
};
return OrderedMapIterator;
}(TreeIterator);
export { OrderedMapIterator };
var OrderedMap = function(r) {
__extends(OrderedMap, r);
function OrderedMap(e, t, n) {
if (e === void 0) {
e = [];
}
var i = r.call(this, t, n) || this;
i.X = function(r) {
return __generator(this, (function(e) {
switch (e.label) {
case 0:
if (r === undefined) return [ 2 ];
return [ 5, __values(this.X(r.Y)) ];
case 1:
e.sent();
return [ 4, [ r.W, r.L ] ];
case 2:
e.sent();
return [ 5, __values(this.X(r.Z)) ];
case 3:
e.sent();
return [ 2 ];
}
}));
};
e.forEach((function(r) {
var e = __read(r, 2), t = e[0], n = e[1];
return i.setElement(t, n);
}));
return i;
}
OrderedMap.prototype.begin = function() {
return new OrderedMapIterator(this.J.Y || this.J, this.J);
};
OrderedMap.prototype.end = function() {
return new OrderedMapIterator(this.J, this.J);
};
OrderedMap.prototype.rBegin = function() {
return new OrderedMapIterator(this.J.Z || this.J, this.J, 1);
};
OrderedMap.prototype.rEnd = function() {
return new OrderedMapIterator(this.J, this.J, 1);
};
OrderedMap.prototype.front = function() {
if (!this.o) return undefined;
var r = this.J.Y;
return [ r.W, r.L ];
};
OrderedMap.prototype.back = function() {
if (!this.o) return undefined;
var r = this.J.Z;
return [ r.W, r.L ];
};
OrderedMap.prototype.forEach = function(r) {
var e, t;
var n = 0;
try {
for (var i = __values(this), a = i.next(); !a.done; a = i.next()) {
var o = a.value;
r(o, n++);
}
} catch (r) {
e = {
error: r
};
} finally {
try {
if (a && !a.done && (t = i.return)) t.call(i);
} finally {
if (e) throw e.error;
}
}
};
OrderedMap.prototype.lowerBound = function(r) {
var e = this.$(this.rr, r);
return new OrderedMapIterator(e, this.J);
};
OrderedMap.prototype.upperBound = function(r) {
var e = this.er(this.rr, r);
return new OrderedMapIterator(e, this.J);
};
OrderedMap.prototype.reverseLowerBound = function(r) {
var e = this.tr(this.rr, r);
return new OrderedMapIterator(e, this.J);
};
OrderedMap.prototype.reverseUpperBound = function(r) {
var e = this.nr(this.rr, r);
return new OrderedMapIterator(e, this.J);
};
OrderedMap.prototype.setElement = function(r, e, t) {
this.ir(r, e, t);
};
OrderedMap.prototype.find = function(r) {
var e = this.ar(this.rr, r);
if (e !== undefined) {
return new OrderedMapIterator(e, this.J);
}
return this.end();
};
OrderedMap.prototype.getElementByKey = function(r) {
var e = this.ar(this.rr, r);
return e ? e.L : undefined;
};
OrderedMap.prototype.getElementByPos = function(r) {
var e, t;
if (r < 0 || r > this.o - 1) {
throw new RangeError;
}
var n;
var i = 0;
try {
for (var a = __values(this), o = a.next(); !o.done; o = a.next()) {
var u = o.value;
if (i === r) {
n = u;
break;
}
i += 1;
}
} catch (r) {
e = {
error: r
};
} finally {
try {
if (o && !o.done && (t = a.return)) t.call(a);
} finally {
if (e) throw e.error;
}
}
return n;
};
OrderedMap.prototype.union = function(r) {
var e = this;
r.forEach((function(r) {
var t = __read(r, 2), n = t[0], i = t[1];
return e.setElement(n, i);
}));
};
OrderedMap.prototype[Symbol.iterator] = function() {
return this.X(this.rr);
};
return OrderedMap;
}(TreeContainer);
export default OrderedMap;

View File

@@ -0,0 +1,37 @@
import TreeContainer from './Base';
import TreeIterator from './Base/TreeIterator';
import { initContainer } from "../ContainerBase";
export declare class OrderedSetIterator<K> extends TreeIterator<K, undefined> {
get pointer(): K;
copy(): OrderedSetIterator<K>;
}
declare class OrderedSet<K> extends TreeContainer<K, undefined> {
/**
* @param container The initialization container.
* @param cmp The compare function.
* @param enableIndex Whether to enable iterator indexing function.
*/
constructor(container?: initContainer<K>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedSetIterator<K>;
end(): OrderedSetIterator<K>;
rBegin(): OrderedSetIterator<K>;
rEnd(): OrderedSetIterator<K>;
front(): K | undefined;
back(): K | undefined;
forEach(callback: (element: K, index: number) => void): void;
getElementByPos(pos: number): K;
/**
* @description Insert element to set.
* @param _key The _key want to insert.
* @param hint You can give an iterator hint to improve insertion efficiency.
*/
insert(_key: K, hint?: OrderedSetIterator<K>): void;
find(element: K): OrderedSetIterator<K>;
lowerBound(_key: K): OrderedSetIterator<K>;
upperBound(_key: K): OrderedSetIterator<K>;
reverseLowerBound(_key: K): OrderedSetIterator<K>;
reverseUpperBound(_key: K): OrderedSetIterator<K>;
union(other: OrderedSet<K>): void;
[Symbol.iterator](): Generator<K, void, undefined>;
}
export default OrderedSet;

View File

@@ -0,0 +1,292 @@
var __extends = this && this.t || function() {
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);
};
return function(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 __);
};
}();
var __generator = this && this.i || function(e, r) {
var t = {
label: 0,
sent: function() {
if (o[0] & 1) throw o[1];
return o[1];
},
trys: [],
ops: []
}, n, i, o, u;
return u = {
next: verb(0),
throw: verb(1),
return: verb(2)
}, typeof Symbol === "function" && (u[Symbol.iterator] = function() {
return this;
}), u;
function verb(e) {
return function(r) {
return step([ e, r ]);
};
}
function step(u) {
if (n) throw new TypeError("Generator is already executing.");
while (t) try {
if (n = 1, i && (o = u[0] & 2 ? i["return"] : u[0] ? i["throw"] || ((o = i["return"]) && o.call(i),
0) : i.next) && !(o = o.call(i, u[1])).done) return o;
if (i = 0, o) u = [ u[0] & 2, o.value ];
switch (u[0]) {
case 0:
case 1:
o = u;
break;
case 4:
t.label++;
return {
value: u[1],
done: false
};
case 5:
t.label++;
i = u[1];
u = [ 0 ];
continue;
case 7:
u = t.ops.pop();
t.trys.pop();
continue;
default:
if (!(o = t.trys, o = o.length > 0 && o[o.length - 1]) && (u[0] === 6 || u[0] === 2)) {
t = 0;
continue;
}
if (u[0] === 3 && (!o || u[1] > o[0] && u[1] < o[3])) {
t.label = u[1];
break;
}
if (u[0] === 6 && t.label < o[1]) {
t.label = o[1];
o = u;
break;
}
if (o && t.label < o[2]) {
t.label = o[2];
t.ops.push(u);
break;
}
if (o[2]) t.ops.pop();
t.trys.pop();
continue;
}
u = r.call(e, t);
} catch (e) {
u = [ 6, e ];
i = 0;
} finally {
n = o = 0;
}
if (u[0] & 5) throw u[1];
return {
value: u[0] ? u[1] : void 0,
done: true
};
}
};
var __values = this && this.u || function(e) {
var r = typeof Symbol === "function" && Symbol.iterator, t = r && e[r], n = 0;
if (t) return t.call(e);
if (e && typeof e.length === "number") return {
next: function() {
if (e && n >= e.length) e = void 0;
return {
value: e && e[n++],
done: !e
};
}
};
throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import TreeContainer from "./Base";
import TreeIterator from "./Base/TreeIterator";
var OrderedSetIterator = function(e) {
__extends(OrderedSetIterator, e);
function OrderedSetIterator() {
return e !== null && e.apply(this, arguments) || this;
}
Object.defineProperty(OrderedSetIterator.prototype, "pointer", {
get: function() {
if (this.D === this.J) {
throw new RangeError("OrderedSet iterator access denied!");
}
return this.D.W;
},
enumerable: false,
configurable: true
});
OrderedSetIterator.prototype.copy = function() {
return new OrderedSetIterator(this.D, this.J, this.iteratorType);
};
return OrderedSetIterator;
}(TreeIterator);
export { OrderedSetIterator };
var OrderedSet = function(e) {
__extends(OrderedSet, e);
function OrderedSet(r, t, n) {
if (r === void 0) {
r = [];
}
var i = e.call(this, t, n) || this;
i.X = function(e) {
return __generator(this, (function(r) {
switch (r.label) {
case 0:
if (e === undefined) return [ 2 ];
return [ 5, __values(this.X(e.Y)) ];
case 1:
r.sent();
return [ 4, e.W ];
case 2:
r.sent();
return [ 5, __values(this.X(e.Z)) ];
case 3:
r.sent();
return [ 2 ];
}
}));
};
r.forEach((function(e) {
return i.insert(e);
}));
return i;
}
OrderedSet.prototype.begin = function() {
return new OrderedSetIterator(this.J.Y || this.J, this.J);
};
OrderedSet.prototype.end = function() {
return new OrderedSetIterator(this.J, this.J);
};
OrderedSet.prototype.rBegin = function() {
return new OrderedSetIterator(this.J.Z || this.J, this.J, 1);
};
OrderedSet.prototype.rEnd = function() {
return new OrderedSetIterator(this.J, this.J, 1);
};
OrderedSet.prototype.front = function() {
return this.J.Y ? this.J.Y.W : undefined;
};
OrderedSet.prototype.back = function() {
return this.J.Z ? this.J.Z.W : undefined;
};
OrderedSet.prototype.forEach = function(e) {
var r, t;
var n = 0;
try {
for (var i = __values(this), o = i.next(); !o.done; o = i.next()) {
var u = o.value;
e(u, n++);
}
} catch (e) {
r = {
error: e
};
} finally {
try {
if (o && !o.done && (t = i.return)) t.call(i);
} finally {
if (r) throw r.error;
}
}
};
OrderedSet.prototype.getElementByPos = function(e) {
var r, t;
if (e < 0 || e > this.o - 1) {
throw new RangeError;
}
var n;
var i = 0;
try {
for (var o = __values(this), u = o.next(); !u.done; u = o.next()) {
var d = u.value;
if (i === e) {
n = d;
break;
}
i += 1;
}
} catch (e) {
r = {
error: e
};
} finally {
try {
if (u && !u.done && (t = o.return)) t.call(o);
} finally {
if (r) throw r.error;
}
}
return n;
};
OrderedSet.prototype.insert = function(e, r) {
this.ir(e, undefined, r);
};
OrderedSet.prototype.find = function(e) {
var r = this.ar(this.rr, e);
if (r !== undefined) {
return new OrderedSetIterator(r, this.J);
}
return this.end();
};
OrderedSet.prototype.lowerBound = function(e) {
var r = this.$(this.rr, e);
return new OrderedSetIterator(r, this.J);
};
OrderedSet.prototype.upperBound = function(e) {
var r = this.er(this.rr, e);
return new OrderedSetIterator(r, this.J);
};
OrderedSet.prototype.reverseLowerBound = function(e) {
var r = this.tr(this.rr, e);
return new OrderedSetIterator(r, this.J);
};
OrderedSet.prototype.reverseUpperBound = function(e) {
var r = this.nr(this.rr, e);
return new OrderedSetIterator(r, this.J);
};
OrderedSet.prototype.union = function(e) {
var r = this;
e.forEach((function(e) {
return r.insert(e);
}));
};
OrderedSet.prototype[Symbol.iterator] = function() {
return this.X(this.rr);
};
return OrderedSet;
}(TreeContainer);
export default OrderedSet;

19
node_modules/js-sdsl/dist/esm/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
export { default as Stack } from "./container/OtherContainer/Stack";
export { default as Queue } from "./container/OtherContainer/Queue";
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue";
export { default as Vector } from "./container/SequentialContainer/Vector";
export { default as LinkList } from "./container/SequentialContainer/LinkList";
export { default as Deque } from "./container/SequentialContainer/Deque";
export { default as OrderedSet } from "./container/TreeContainer/OrderedSet";
export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
export { default as HashSet } from "./container/HashContainer/HashSet";
export { default as HashMap } from "./container/HashContainer/HashMap";
export type { VectorIterator } from "./container/SequentialContainer/Vector";
export type { LinkListIterator } from "./container/SequentialContainer/LinkList";
export type { DequeIterator } from "./container/SequentialContainer/Deque";
export type { OrderedSetIterator } from "./container/TreeContainer/OrderedSet";
export type { OrderedMapIterator } from "./container/TreeContainer/OrderedMap";
export type { IteratorType, Container, ContainerIterator } from "./container/ContainerBase";
export type { default as SequentialContainer } from "./container/SequentialContainer/Base";
export type { default as TreeContainer } from "./container/TreeContainer/Base";
export type { default as HashContainer } from "./container/HashContainer/Base";

19
node_modules/js-sdsl/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
export { default as Stack } from "./container/OtherContainer/Stack";
export { default as Queue } from "./container/OtherContainer/Queue";
export { default as PriorityQueue } from "./container/OtherContainer/PriorityQueue";
export { default as Vector } from "./container/SequentialContainer/Vector";
export { default as LinkList } from "./container/SequentialContainer/LinkList";
export { default as Deque } from "./container/SequentialContainer/Deque";
export { default as OrderedSet } from "./container/TreeContainer/OrderedSet";
export { default as OrderedMap } from "./container/TreeContainer/OrderedMap";
export { default as HashSet } from "./container/HashContainer/HashSet";
export { default as HashMap } from "./container/HashContainer/HashMap";

2752
node_modules/js-sdsl/dist/umd/js-sdsl.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2
node_modules/js-sdsl/dist/umd/js-sdsl.min.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/js-sdsl/dist/umd/js-sdsl.min.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

157
node_modules/js-sdsl/package.json generated vendored Normal file
View File

@@ -0,0 +1,157 @@
{
"name": "js-sdsl",
"version": "4.1.5",
"description": "javascript standard data structure library which benchmark against C++ STL",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"author": {
"name": "ZLY201",
"email": "951711127@qq.com",
"url": "https://github.com/js-sdsl/js-sdsl"
},
"browserslist": [
"last 2 version",
"> 1%",
"not dead",
"maintained node versions"
],
"sideEffects": false,
"homepage": "https://js-sdsl.github.io",
"scripts": {
"setup": "rm -rf node_modules && yarn install",
"dev": "ttsc --project tsconfig.dev.json --watch",
"build": "gulp",
"build:cjs": "gulp cjs",
"build:esm": "gulp esm",
"build:umd": "gulp umd",
"build:umd:min": "yarn build:umd && gulp umd:min",
"build:isolate": "gulp isolate",
"test": "yarn test:unit && yarn test:browser && yarn test:performance",
"test:unit": "nyc ts-mocha --paths 'test/**/*.test.ts' --timeout 10000",
"test:browser": "karma start",
"test:performance": "gulp performance && node dist/performance/performance/index.js",
"lint": "eslint --fix --color --cache --max-warnings=0 .",
"generate": "typedoc src/index.ts",
"generate:dev": "typedoc src/index.ts --watch",
"prepare": "husky install"
},
"lint-staged": {
"*.{js,ts}": [
"yarn lint"
]
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@rollup/plugin-babel": "^5.3.1",
"@types/babel__core": "^7.1.19",
"@types/chai": "^4.3.3",
"@types/delete-empty": "^3.0.2",
"@types/gulp": "^4.0.9",
"@types/gulp-babel": "^6.1.30",
"@types/gulp-filter": "^3.0.34",
"@types/gulp-rename": "^2.0.1",
"@types/gulp-sourcemaps": "^0.0.35",
"@types/gulp-tap": "^1.0.1",
"@types/gulp-terser": "^1.2.1",
"@types/gulp-uglify": "^3.0.7",
"@types/karma": "^6.3.3",
"@types/merge-stream": "^1.1.2",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"all-contributors-cli": "^6.20.0",
"babel-plugin-remove-unused-import": "^2.1.1",
"browserslist": "^4.21.3",
"caniuse-lite": "^1.0.30001380",
"chai": "^4.3.6",
"commitlint": "^17.0.3",
"compare-versions": "^5.0.1",
"conventional-changelog-conventionalcommits": "^5.0.0",
"delete-empty": "^3.0.0",
"eslint": "^8.23.1",
"eslint-plugin-compat": "^4.0.2",
"get-npm-package-version": "^1.1.1",
"gh-pages": "^3.2.3",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-clean": "^0.4.0",
"gulp-filter": "^7.0.0",
"gulp-rename": "^2.0.0",
"gulp-rollup-2": "^1.3.1",
"gulp-sourcemaps": "^3.0.0",
"gulp-tap": "^2.0.0",
"gulp-terser": "^2.1.0",
"gulp-typescript": "^5.0.0",
"gulp-uglify": "^3.0.2",
"husky": "^8.0.1",
"karma": "^6.4.1",
"karma-chrome-launcher": "^3.1.1",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-requirejs": "^1.1.0",
"karma-typescript": "^5.5.3",
"lint-staged": "^13.0.3",
"merge-stream": "^2.0.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"requirejs": "^2.3.6",
"rollup": "^2.79.1",
"rollup-plugin-typescript2": "^0.33.0",
"ts-macros": "^1.3.3",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"ts-transform-paths": "^2.0.3",
"tsconfig-paths": "^4.0.0",
"tslib": "^2.4.0",
"ttypescript": "^1.5.13",
"typedoc": "^0.23.10",
"typedoc-plugin-missing-exports": "^1.0.0",
"typescript": "~4.7.4"
},
"repository": {
"type": "github",
"url": "https://github.com/js-sdsl/js-sdsl.git"
},
"license": "MIT",
"files": [
"dist/cjs",
"dist/esm",
"dist/umd",
"CHANGELOG.md"
],
"keywords": [
"data",
"structure",
"data structure",
"rbTree",
"rbtree",
"RBTree",
"red black tree",
"ordered",
"set",
"map",
"ordered map",
"ordered set",
"deque",
"heap",
"priority queue",
"link list",
"LinkList",
"linkedList",
"vector",
"stack",
"queue",
"hash",
"hash set",
"hash map",
"c++",
"stl"
],
"bugs": {
"email": "951711127@qq.com",
"url": "https://github.com/js-sdsl/js-sdsl/issues"
},
"dependencies": {}
}