initial commit

This commit is contained in:
2025-09-01 22:12:29 +02:00
parent b1873f9c1d
commit 02a54f61c0
5598 changed files with 903558 additions and 0 deletions

237
server/node_modules/@js-sdsl/ordered-map/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,237 @@
# 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.4.2] - 2023.07.21
### Fixed
- The pointer of Adapter container's iterator cannot as array to be deconstructed.
### Added
- Add `isAccessible` function to iterators for iterable containers.
## [4.4.1] - 2023.06.05
### Fixed
- Tree container with less than 3 items reverse iteration infinite loop
## [4.4.0] - 2023.03.17
### Changed
- Optimized inOrder travel function for tree container.
- Optimized `Symbol.iterator` function.
- Optimized `TreeContainer` `erase` function.
- Optimized some details of deque.
- Change `reverse` and `sort` returned value to `this`.
## [4.3.0] - 2023.01.20
### Added
- Add public member `container` to `Iterator` which means the container that the iterator pointed to.
### Changed
- Reimplement `Queue`, separate `Queue` from `Deque`.
## [4.2.0] - 2022.11.20
### Changed
- Optimized the structure of class `TreeNodeEnableIndex`.
- Change the `iterator access denied` error message to reduce the packing size.
- Change the internal storage of the hash container to the form of a linked list, traversing in insertion order.
- Standardize hash container. Make it extends from `Container` and add general functions.
- Refactor `LinkList` to do optimization.
### Added
- Add public `length` property to all the container.
- Add returned value to `pop` function including `popBack` and `popFront` to all the container which has such function.
- Add returned value to `eraseElementByKey` which means whether erase successfully.
- Add returned value to `push` or `insert` function which means the size of the container.
### Fixed
- Fixed wrong error type when `updateKeyByIterator`.
- Fixed wrong iterator was returned when erase tree reverse iterator.
## [4.2.0-beta.1] - 2022.11.06
### Changed
- Remove all the arrow function to optimize.
- Modify `HashContainer` implementation to optimize.
## [4.2.0-beta.0] - 2022.10.30
### Added
- Add `ts` sourcemap for debug mode.
- Add `this` param for `forEach` function.
- Support single package umd build.
### Changed
- Changed the packaging method of isolation packages release and the method of the member export.
## [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
server/node_modules/@js-sdsl/ordered-map/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.

270
server/node_modules/@js-sdsl/ordered-map/README.md generated vendored Normal file
View File

@@ -0,0 +1,270 @@
<p align="center">
<a href="https://js-sdsl.org/" target="_blank" rel="noopener noreferrer">
<img src="https://js-sdsl.org/assets/image/logo/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/actions/workflow/status/js-sdsl/js-sdsl/build.yml" 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
- **Stack** - first in last out stack.
- **Queue** - first in first out queue.
- **PriorityQueue** - heap-implemented priority queue.
- **Vector** - protected array, cannot to operate properties like `length` directly.
- **LinkList** - linked list of non-contiguous memory addresses.
- **Deque** - double-ended-queue, O(1) time complexity to `unshift` or getting elements by index.
- **OrderedSet** - sorted set which implemented by red black tree.
- **OrderedMap** - sorted map which implemented by red black tree.
- **HashSet** - refer to the [polyfill of ES6 Set](https://github.com/rousan/collections-es6).
- **HashMap** - refer to the [polyfill of ES6 Map](https://github.com/rousan/collections-es6).
## ⚔️ 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.org/#/test/benchmark-analyze).
## 🖥 Supported platforms
| ![][Edge-Icon]<br/>IE / Edge | ![][Firefox-Icon]<br/>Firefox | ![][Chrome-Icon]<br/>Chrome | ![][Safari-Icon]<br/>Safari | ![][Opera-Icon]<br/>Opera | ![][NodeJs-Icon]<br/>NodeJs |
|:----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------:|:-------------------------:|:---------------------------:|
| Edge 12 | 36 | 49 | 10 | 36 | 10 |
## 📦 Download
Download directly by 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)
Or install js-sdsl using npm:
```bash
npm install js-sdsl
```
Or you can download the isolation packages containing only the containers you want:
| package | npm | size | docs |
|---------------------------------------------------|-----------------------------------------------------------------------|------------------------------------------------------------------|-----------------------------|
| [@js-sdsl/stack][stack-package] | [![NPM Package][stack-npm-version]][stack-npm-link] | [![GZIP Size][stack-umd-size]][stack-umd-link] | [link][stack-docs] |
| [@js-sdsl/queue][queue-package] | [![NPM Package][queue-npm-version]][queue-npm-link] | [![GZIP Size][queue-umd-size]][queue-umd-link] | [link][queue-docs] |
| [@js-sdsl/priority-queue][priority-queue-package] | [![NPM Package][priority-queue-npm-version]][priority-queue-npm-link] | [![GZIP Size][priority-queue-umd-size]][priority-queue-umd-link] | [link][priority-queue-docs] |
| [@js-sdsl/vector][vector-package] | [![NPM Package][vector-npm-version]][vector-npm-link] | [![GZIP Size][vector-umd-size]][vector-umd-link] | [link][vector-docs] |
| [@js-sdsl/link-list][link-list-package] | [![NPM Package][link-list-npm-version]][link-list-npm-link] | [![GZIP Size][link-list-umd-size]][link-list-umd-link] | [link][link-list-docs] |
| [@js-sdsl/deque][deque-package] | [![NPM Package][deque-npm-version]][deque-npm-link] | [![GZIP Size][deque-umd-size]][deque-umd-link] | [link][deque-docs] |
| [@js-sdsl/ordered-set][ordered-set-package] | [![NPM Package][ordered-set-npm-version]][ordered-set-npm-link] | [![GZIP Size][ordered-set-umd-size]][ordered-set-umd-link] | [link][ordered-set-docs] |
| [@js-sdsl/ordered-map][ordered-map-package] | [![NPM Package][ordered-map-npm-version]][ordered-map-npm-link] | [![GZIP Size][ordered-map-umd-size]][ordered-map-umd-link] | [link][ordered-map-docs] |
| [@js-sdsl/hash-set][hash-set-package] | [![NPM Package][hash-set-npm-version]][hash-set-npm-link] | [![GZIP Size][hash-set-umd-size]][hash-set-umd-link] | [link][hash-set-docs] |
| [@js-sdsl/hash-map][hash-map-package] | [![NPM Package][hash-map-npm-version]][hash-map-npm-link] | [![GZIP Size][hash-map-umd-size]][hash-map-umd-link] | [link][hash-map-docs] |
## 🪒 Usage
You can visit our [official website](https://js-sdsl.org/) to get more information.
To help you have a better use, we also provide this [API document](https://js-sdsl.org/js-sdsl/index.html).
For previous versions of the documentation, please visit:
`https://js-sdsl.org/js-sdsl/previous/v${version}/index.html`
E.g.
[https://js-sdsl.org/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.org/js-sdsl/previous/v4.1.5/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
```
## 🛠 Test
### Unit test
We use [karma](https://karma-runner.github.io/) and [mocha](https://mochajs.org/) frame to do unit tests and synchronize to [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.org/#/test/performance-test) to get the result.
## ⌨️ Development
Use Gitpod, a free online dev environment for GitHub.
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl)
Or clone locally:
```bash
$ git clone https://github.com/js-sdsl/js-sdsl.git
$ cd js-sdsl
$ npm install
$ npm run dev # development mode
```
Then you can see the output in `dist/cjs` folder.
## 🤝 Contributing
Feel free to dive in! Open an issue or submit PRs. It may be helpful to read the [Contributor Guide](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md).
### 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!
## ❤️ Sponsors and Backers
The special thanks to these sponsors or backers because they provided support at a very early stage:
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/image/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a>
Thanks also give to these sponsors or backers:
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
## 🪪 License
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201)
[Edge-Icon]: https://js-sdsl.org/assets/image/platform/edge.png
[Firefox-Icon]: https://js-sdsl.org/assets/image/platform/firefox.png
[Chrome-Icon]: https://js-sdsl.org/assets/image/platform/chrome.png
[Safari-Icon]: https://js-sdsl.org/assets/image/platform/safari.png
[Opera-Icon]: https://js-sdsl.org/assets/image/platform/opera.png
[NodeJs-Icon]: https://js-sdsl.org/assets/image/platform/nodejs.png
[stack-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Stack.ts
[stack-npm-version]: https://img.shields.io/npm/v/@js-sdsl/stack
[stack-npm-link]: https://www.npmjs.com/package/@js-sdsl/stack
[stack-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js?compression=gzip&style=flat-square/
[stack-umd-link]: https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js
[stack-docs]: https://js-sdsl.org/js-sdsl/classes/Stack.html
[queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Queue.ts
[queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/queue
[queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/queue
[queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js?compression=gzip&style=flat-square/
[queue-umd-link]: https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js
[queue-docs]: https://js-sdsl.org/js-sdsl/classes/Queue.html
[priority-queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/PriorityQueue.ts
[priority-queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/priority-queue
[priority-queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/priority-queue
[priority-queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js?compression=gzip&style=flat-square/
[priority-queue-umd-link]: https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js
[priority-queue-docs]: https://js-sdsl.org/js-sdsl/classes/PriorityQueue.html
[vector-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Vector.ts
[vector-npm-version]: https://img.shields.io/npm/v/@js-sdsl/vector
[vector-npm-link]: https://www.npmjs.com/package/@js-sdsl/vector
[vector-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js?compression=gzip&style=flat-square/
[vector-umd-link]: https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js
[vector-docs]: https://js-sdsl.org/js-sdsl/classes/Vector.html
[link-list-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/LinkList.ts
[link-list-npm-version]: https://img.shields.io/npm/v/@js-sdsl/link-list
[link-list-npm-link]: https://www.npmjs.com/package/@js-sdsl/link-list
[link-list-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js?compression=gzip&style=flat-square/
[link-list-umd-link]: https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js
[link-list-docs]: https://js-sdsl.org/js-sdsl/classes/LinkList.html
[deque-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Deque.ts
[deque-npm-version]: https://img.shields.io/npm/v/@js-sdsl/deque
[deque-npm-link]: https://www.npmjs.com/package/@js-sdsl/deque
[deque-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js?compression=gzip&style=flat-square/
[deque-umd-link]: https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js
[deque-docs]: https://js-sdsl.org/js-sdsl/classes/Deque.html
[ordered-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedSet.ts
[ordered-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-set
[ordered-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-set
[ordered-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js?compression=gzip&style=flat-square/
[ordered-set-umd-link]: https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js
[ordered-set-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedSet.html
[ordered-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedMap.ts
[ordered-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-map
[ordered-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-map
[ordered-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js?compression=gzip&style=flat-square/
[ordered-map-umd-link]: https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js
[ordered-map-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedMap.html
[hash-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashSet.ts
[hash-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-set
[hash-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-set
[hash-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js?compression=gzip&style=flat-square/
[hash-set-umd-link]: https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js
[hash-set-docs]: https://js-sdsl.org/js-sdsl/classes/HashSet.html
[hash-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashMap.ts
[hash-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-map
[hash-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-map
[hash-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js?compression=gzip&style=flat-square/
[hash-map-umd-link]: https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js
[hash-map-docs]: https://js-sdsl.org/js-sdsl/classes/HashMap.html

View File

@@ -0,0 +1,272 @@
<p align="center">
<a href="https://js-sdsl.org/" target="_blank" rel="noopener noreferrer">
<img src="https://js-sdsl.org/assets/image/logo/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/actions/workflow/status/js-sdsl/js-sdsl/build.yml" 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>
## ✨ 包含的数据结构
- **Stack** - 先进后出的堆栈
- **Queue** - 先进先出的队列
- **PriorityQueue** - 堆实现的优先级队列
- **Vector** - 受保护的数组,不能直接操作像 `length` 这样的属性
- **LinkList** - 非连续内存地址的链表
- **Deque** - 双端队列,向前和向后插入元素或按索引获取元素的时间复杂度为 O(1)
- **OrderedSet** - 由红黑树实现的排序集合
- **OrderedMap** - 由红黑树实现的排序字典
- **HashSet** - 参考 [ES6 Set polyfill](https://github.com/rousan/collections-es6) 实现的哈希集合
- **HashMap** - 参考 [ES6 Set polyfill](https://github.com/rousan/collections-es6) 实现的哈希字典
## ⚔️ 基准测试
我们和其他数据结构库进行了基准测试,在某些场景我们甚至超过了当前最流行的库
查看 [benchmark](https://js-sdsl.org/#/zh-cn/test/benchmark-analyze) 以获取更多信息
## 🖥 支持的平台
| ![][Edge-Icon]<br/>IE / Edge | ![][Firefox-Icon]<br/>Firefox | ![][Chrome-Icon]<br/>Chrome | ![][Safari-Icon]<br/>Safari | ![][Opera-Icon]<br/>Opera | ![][NodeJs-Icon]<br/>NodeJs |
|:----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------:|:-------------------------:|:---------------------------:|
| Edge 12 | 36 | 49 | 10 | 36 | 10 |
## 📦 下载
使用 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
```
或者根据需要安装以下任意单个包
| package | npm | size | docs |
|---------------------------------------------------|-----------------------------------------------------------------------|------------------------------------------------------------------|-----------------------------|
| [@js-sdsl/stack][stack-package] | [![NPM Package][stack-npm-version]][stack-npm-link] | [![GZIP Size][stack-umd-size]][stack-umd-link] | [link][stack-docs] |
| [@js-sdsl/queue][queue-package] | [![NPM Package][queue-npm-version]][queue-npm-link] | [![GZIP Size][queue-umd-size]][queue-umd-link] | [link][queue-docs] |
| [@js-sdsl/priority-queue][priority-queue-package] | [![NPM Package][priority-queue-npm-version]][priority-queue-npm-link] | [![GZIP Size][priority-queue-umd-size]][priority-queue-umd-link] | [link][priority-queue-docs] |
| [@js-sdsl/vector][vector-package] | [![NPM Package][vector-npm-version]][vector-npm-link] | [![GZIP Size][vector-umd-size]][vector-umd-link] | [link][vector-docs] |
| [@js-sdsl/link-list][link-list-package] | [![NPM Package][link-list-npm-version]][link-list-npm-link] | [![GZIP Size][link-list-umd-size]][link-list-umd-link] | [link][link-list-docs] |
| [@js-sdsl/deque][deque-package] | [![NPM Package][deque-npm-version]][deque-npm-link] | [![GZIP Size][deque-umd-size]][deque-umd-link] | [link][deque-docs] |
| [@js-sdsl/ordered-set][ordered-set-package] | [![NPM Package][ordered-set-npm-version]][ordered-set-npm-link] | [![GZIP Size][ordered-set-umd-size]][ordered-set-umd-link] | [link][ordered-set-docs] |
| [@js-sdsl/ordered-map][ordered-map-package] | [![NPM Package][ordered-map-npm-version]][ordered-map-npm-link] | [![GZIP Size][ordered-map-umd-size]][ordered-map-umd-link] | [link][ordered-map-docs] |
| [@js-sdsl/hash-set][hash-set-package] | [![NPM Package][hash-set-npm-version]][hash-set-npm-link] | [![GZIP Size][hash-set-umd-size]][hash-set-umd-link] | [link][hash-set-docs] |
| [@js-sdsl/hash-map][hash-map-package] | [![NPM Package][hash-map-npm-version]][hash-map-npm-link] | [![GZIP Size][hash-map-umd-size]][hash-map-umd-link] | [link][hash-map-docs] |
## 🪒 使用说明
您可以[访问我们的主页](https://js-sdsl.org/)获取更多信息
并且我们提供了完整的 [API 文档](https://js-sdsl.org/js-sdsl/index.html)供您参考
想要查看从前版本的文档,请访问:
`https://js-sdsl.org/js-sdsl/previous/v${version}/index.html`
例如:
[https://js-sdsl.org/js-sdsl/previous/v4.1.5/index.html](https://js-sdsl.org/js-sdsl/previous/v4.1.5/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
```
## 🛠 测试
### 单元测试
我们使用 [karma](https://karma-runner.github.io/) 和 [mocha](https://mochajs.org/) 框架进行单元测试,并同步到 [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.org/#/zh-cn/test/performance-test)来获取结果
## ⌨️ 开发
可以使用 Gitpod 进行在线编辑:
[![Open in Gippod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/js-sdsl/js-sdsl)
或者在本地使用以下命令获取源码进行开发:
```bash
$ git clone https://github.com/js-sdsl/js-sdsl.git
$ cd js-sdsl
$ npm install
$ npm run dev # development mode
```
之后您在 `dist/cjs` 文件夹中可以看到在 `dev` 模式下打包生成的产物
## 🤝 贡献
我们欢迎所有的开发人员提交 issue 或 pull request阅读[贡献者指南](https://github.com/js-sdsl/js-sdsl/blob/main/.github/CONTRIBUTING.md)可能会有所帮助
### 贡献者
感谢对本项目做出贡献的开发者们:
<!-- 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) 规范。 欢迎任何形式的贡献!
## ❤️ 赞助者
特别鸣谢下列赞助商和支持者们,他们在非常早期的时候为我们提供了支持:
<a href="https://eslint.org/"><img src="https://js-sdsl.org/assets/image/sponsors/eslint-logo-color.png" alt="eslint logo" width="150"></a>
同样感谢这些赞助商和支持者们:
[![sponsors](https://opencollective.com/js-sdsl/tiers/sponsors.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
[![backers](https://opencollective.com/js-sdsl/tiers/backers.svg?avatarHeight=36)](https://opencollective.com/js-sdsl#support)
## 🪪 许可证
[MIT](https://github.com/js-sdsl/js-sdsl/blob/main/LICENSE) © [ZLY201](https://github.com/zly201)
[Edge-Icon]: https://js-sdsl.org/assets/image/platform/edge.png
[Firefox-Icon]: https://js-sdsl.org/assets/image/platform/firefox.png
[Chrome-Icon]: https://js-sdsl.org/assets/image/platform/chrome.png
[Safari-Icon]: https://js-sdsl.org/assets/image/platform/safari.png
[Opera-Icon]: https://js-sdsl.org/assets/image/platform/opera.png
[NodeJs-Icon]: https://js-sdsl.org/assets/image/platform/nodejs.png
[stack-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Stack.ts
[stack-npm-version]: https://img.shields.io/npm/v/@js-sdsl/stack
[stack-npm-link]: https://www.npmjs.com/package/@js-sdsl/stack
[stack-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js?compression=gzip&style=flat-square/
[stack-umd-link]: https://unpkg.com/@js-sdsl/stack/dist/umd/stack.min.js
[stack-docs]: https://js-sdsl.org/js-sdsl/classes/Stack.html
[queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/Queue.ts
[queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/queue
[queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/queue
[queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js?compression=gzip&style=flat-square/
[queue-umd-link]: https://unpkg.com/@js-sdsl/queue/dist/umd/queue.min.js
[queue-docs]: https://js-sdsl.org/js-sdsl/classes/Queue.html
[priority-queue-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/OtherContainer/PriorityQueue.ts
[priority-queue-npm-version]: https://img.shields.io/npm/v/@js-sdsl/priority-queue
[priority-queue-npm-link]: https://www.npmjs.com/package/@js-sdsl/priority-queue
[priority-queue-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js?compression=gzip&style=flat-square/
[priority-queue-umd-link]: https://unpkg.com/@js-sdsl/priority-queue/dist/umd/priority-queue.min.js
[priority-queue-docs]: https://js-sdsl.org/js-sdsl/classes/PriorityQueue.html
[vector-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Vector.ts
[vector-npm-version]: https://img.shields.io/npm/v/@js-sdsl/vector
[vector-npm-link]: https://www.npmjs.com/package/@js-sdsl/vector
[vector-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js?compression=gzip&style=flat-square/
[vector-umd-link]: https://unpkg.com/@js-sdsl/vector/dist/umd/vector.min.js
[vector-docs]: https://js-sdsl.org/js-sdsl/classes/Vector.html
[link-list-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/LinkList.ts
[link-list-npm-version]: https://img.shields.io/npm/v/@js-sdsl/link-list
[link-list-npm-link]: https://www.npmjs.com/package/@js-sdsl/link-list
[link-list-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js?compression=gzip&style=flat-square/
[link-list-umd-link]: https://unpkg.com/@js-sdsl/link-list/dist/umd/link-list.min.js
[link-list-docs]: https://js-sdsl.org/js-sdsl/classes/LinkList.html
[deque-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/SequentialContainer/Deque.ts
[deque-npm-version]: https://img.shields.io/npm/v/@js-sdsl/deque
[deque-npm-link]: https://www.npmjs.com/package/@js-sdsl/deque
[deque-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js?compression=gzip&style=flat-square/
[deque-umd-link]: https://unpkg.com/@js-sdsl/deque/dist/umd/deque.min.js
[deque-docs]: https://js-sdsl.org/js-sdsl/classes/Deque.html
[ordered-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedSet.ts
[ordered-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-set
[ordered-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-set
[ordered-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js?compression=gzip&style=flat-square/
[ordered-set-umd-link]: https://unpkg.com/@js-sdsl/ordered-set/dist/umd/ordered-set.min.js
[ordered-set-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedSet.html
[ordered-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/TreeContainer/OrderedMap.ts
[ordered-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/ordered-map
[ordered-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/ordered-map
[ordered-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js?compression=gzip&style=flat-square/
[ordered-map-umd-link]: https://unpkg.com/@js-sdsl/ordered-map/dist/umd/ordered-map.min.js
[ordered-map-docs]: https://js-sdsl.org/js-sdsl/classes/OrderedMap.html
[hash-set-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashSet.ts
[hash-set-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-set
[hash-set-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-set
[hash-set-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js?compression=gzip&style=flat-square/
[hash-set-umd-link]: https://unpkg.com/@js-sdsl/hash-set/dist/umd/hash-set.min.js
[hash-set-docs]: https://js-sdsl.org/js-sdsl/classes/HashSet.html
[hash-map-package]: https://github.com/js-sdsl/js-sdsl/blob/main/src/container/HashContainer/HashMap.ts
[hash-map-npm-version]: https://img.shields.io/npm/v/@js-sdsl/hash-map
[hash-map-npm-link]: https://www.npmjs.com/package/@js-sdsl/hash-map
[hash-map-umd-size]: https://img.badgesize.io/https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js?compression=gzip&style=flat-square/
[hash-map-umd-link]: https://unpkg.com/@js-sdsl/hash-map/dist/umd/hash-map.min.js
[hash-map-docs]: https://js-sdsl.org/js-sdsl/classes/HashMap.html

View File

@@ -0,0 +1,402 @@
/**
* @description The iterator type including `NORMAL` and `REVERSE`.
*/
declare const enum IteratorType {
NORMAL = 0,
REVERSE = 1
}
declare abstract class ContainerIterator<T> {
/**
* @description The container pointed to by the iterator.
*/
abstract readonly container: Container<T>;
/**
* @description Iterator's type.
* @example
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true
*/
readonly iteratorType: IteratorType;
/**
* @param iter - The other iterator you want to compare.
* @returns Whether this equals to obj.
* @example
* container.find(1).equals(container.end());
*/
equals(iter: ContainerIterator<T>): boolean;
/**
* @description Pointers to element.
* @returns The value of the pointer's element.
* @example
* const val = container.begin().pointer;
*/
abstract get pointer(): T;
/**
* @description Set pointer's value (some containers are unavailable).
* @param newValue - The new value you want to set.
* @example
* (<LinkList<number>>container).begin().pointer = 1;
*/
abstract set pointer(newValue: T);
/**
* @description Move `this` iterator to pre.
* @returns The iterator's self.
* @example
* const iter = container.find(1); // container = [0, 1]
* const pre = iter.pre();
* console.log(pre === iter); // true
* console.log(pre.equals(iter)); // true
* console.log(pre.pointer, iter.pointer); // 0, 0
*/
abstract pre(): this;
/**
* @description Move `this` iterator to next.
* @returns The iterator's self.
* @example
* const iter = container.find(1); // container = [1, 2]
* const next = iter.next();
* console.log(next === iter); // true
* console.log(next.equals(iter)); // true
* console.log(next.pointer, iter.pointer); // 2, 2
*/
abstract next(): this;
/**
* @description Get a copy of itself.
* @returns The copy of self.
* @example
* const iter = container.find(1); // container = [1, 2]
* const next = iter.copy().next();
* console.log(next === iter); // false
* console.log(next.equals(iter)); // false
* console.log(next.pointer, iter.pointer); // 2, 1
*/
abstract copy(): ContainerIterator<T>;
abstract isAccessible(): boolean;
}
declare abstract class Base {
/**
* @returns The size of the container.
* @example
* const container = new Vector([1, 2]);
* console.log(container.length); // 2
*/
get length(): number;
/**
* @returns The size of the container.
* @example
* const container = new Vector([1, 2]);
* console.log(container.size()); // 2
*/
size(): number;
/**
* @returns Whether the container is empty.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
empty(): boolean;
/**
* @description Clear the container.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
abstract clear(): void;
}
declare abstract class Container<T> extends Base {
/**
* @returns Iterator pointing to the beginning element.
* @example
* const begin = container.begin();
* const end = container.end();
* for (const it = begin; !it.equals(end); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract begin(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the super end like c++.
* @example
* const begin = container.begin();
* const end = container.end();
* for (const it = begin; !it.equals(end); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract end(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the end element.
* @example
* const rBegin = container.rBegin();
* const rEnd = container.rEnd();
* for (const it = rBegin; !it.equals(rEnd); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract rBegin(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the super begin like c++.
* @example
* const rBegin = container.rBegin();
* const rEnd = container.rEnd();
* for (const it = rBegin; !it.equals(rEnd); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract rEnd(): ContainerIterator<T>;
/**
* @returns The first element of the container.
*/
abstract front(): T | undefined;
/**
* @returns The last element of the container.
*/
abstract back(): T | undefined;
/**
* @param element - The element you want to find.
* @returns An iterator pointing to the element if found, or super end if not found.
* @example
* container.find(1).equals(container.end());
*/
abstract find(element: T): ContainerIterator<T>;
/**
* @description Iterate over all elements in the container.
* @param callback - Callback function like Array.forEach.
* @example
* container.forEach((element, index) => console.log(element, index));
*/
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void;
/**
* @description Gets the value of the element at the specified position.
* @example
* const val = container.getElementByPos(-1); // throw a RangeError
*/
abstract getElementByPos(pos: number): T;
/**
* @description Removes the element at the specified position.
* @param pos - The element's position you want to remove.
* @returns The container length after erasing.
* @example
* container.eraseElementByPos(-1); // throw a RangeError
*/
abstract eraseElementByPos(pos: number): number;
/**
* @description Removes element by iterator and move `iter` to next.
* @param iter - The iterator you want to erase.
* @returns The next iterator.
* @example
* container.eraseElementByIterator(container.begin());
* container.eraseElementByIterator(container.end()); // throw a RangeError
*/
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>;
/**
* @description Using for `for...of` syntax like Array.
* @example
* for (const element of container) {
* console.log(element);
* }
*/
abstract [Symbol.iterator](): Generator<T, void>;
}
/**
* @description The initial data type passed in when initializing the container.
*/
type initContainer<T> = {
size?: number | (() => number);
length?: number;
forEach: (callback: (el: T) => void) => void;
};
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [
K,
V
]> {
abstract readonly container: TreeContainer<K, V>;
/**
* @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`.
* @returns The index subscript of the node in the tree.
* @example
* const st = new OrderedSet([1, 2, 3], true);
* console.log(st.begin().next().index); // 1
*/
get index(): number;
isAccessible(): boolean;
// @ts-ignore
pre(): this;
// @ts-ignore
next(): this;
}
declare const enum TreeNodeColor {
RED = 1,
BLACK = 0
}
declare class TreeNode<K, V> {
_color: TreeNodeColor;
_key: K | undefined;
_value: V | undefined;
_left: TreeNode<K, V> | undefined;
_right: TreeNode<K, V> | undefined;
_parent: TreeNode<K, V> | undefined;
constructor(key?: K, value?: V, color?: TreeNodeColor);
/**
* @description Get the pre node.
* @returns TreeNode about the pre node.
*/
_pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @returns TreeNode about the next node.
*/
_next(): TreeNode<K, V>;
/**
* @description Rotate left.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate right.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateRight(): TreeNode<K, V>;
}
declare abstract class TreeContainer<K, V> extends Container<K | [
K,
V
]> {
enableIndex: boolean;
protected _inOrderTraversal(): TreeNode<K, V>[];
protected _inOrderTraversal(pos: number): TreeNode<K, V>;
protected _inOrderTraversal(callback: (node: TreeNode<K, V>, index: number, map: this) => void): TreeNode<K, V>;
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.
* @returns Whether the modification is successful.
* @example
* const st = new orderedSet([1, 2, 5]);
* const iter = st.find(2);
* st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
*/
updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
eraseElementByPos(pos: number): number;
/**
* @description Remove the element of the specified key.
* @param key - The key you want to remove.
* @returns Whether erase successfully.
*/
eraseElementByKey(key: K): boolean;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
/**
* @description Get the height of the tree.
* @returns Number about the height of the RB-tree.
*/
getHeight(): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns The size of the tree after union.
*/
abstract union(other: TreeContainer<K, V>): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns 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.
* @returns An iterator to the first element greater than the given key.
*/
abstract upperBound(key: K): TreeIterator<K, V>;
}
declare class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
container: OrderedMap<K, V>;
constructor(node: TreeNode<K, V>, header: TreeNode<K, V>, container: OrderedMap<K, V>, iteratorType?: IteratorType);
get pointer(): [
K,
V
];
copy(): OrderedMapIterator<K, V>;
// @ts-ignore
equals(iter: OrderedMapIterator<K, V>): boolean;
}
declare class OrderedMap<K, V> extends TreeContainer<K, V> {
/**
* @param container - The initialization container.
* @param cmp - The compare function.
* @param enableIndex - Whether to enable iterator indexing function.
* @example
* new OrderedMap();
* new OrderedMap([[0, 1], [2, 1]]);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y, true);
*/
constructor(container?: initContainer<[
K,
V
]>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedMapIterator<K, V>;
end(): OrderedMapIterator<K, V>;
rBegin(): OrderedMapIterator<K, V>;
rEnd(): OrderedMapIterator<K, V>;
front(): [
K,
V
] | undefined;
back(): [
K,
V
] | undefined;
lowerBound(key: K): OrderedMapIterator<K, V>;
upperBound(key: K): OrderedMapIterator<K, V>;
reverseLowerBound(key: K): OrderedMapIterator<K, V>;
reverseUpperBound(key: K): OrderedMapIterator<K, V>;
forEach(callback: (element: [
K,
V
], index: number, map: OrderedMap<K, V>) => void): void;
/**
* @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.
* @return The size of container after setting.
* @example
* const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
* const iter = mp.begin();
* mp.setElement(1, 0);
* mp.setElement(3, 0, iter); // give a hint will be faster.
*/
setElement(key: K, value: V, hint?: OrderedMapIterator<K, V>): number;
getElementByPos(pos: number): [
K,
V
];
find(key: K): OrderedMapIterator<K, V>;
/**
* @description Get the value of the element of the specified key.
* @param key - The specified key you want to get.
* @example
* const val = container.getElementByKey(1);
*/
getElementByKey(key: K): V | undefined;
union(other: OrderedMap<K, V>): number;
[Symbol.iterator](): Generator<[
K,
V
], void, unknown>;
// @ts-ignore
eraseElementByIterator(iter: OrderedMapIterator<K, V>): OrderedMapIterator<K, V>;
}
export { OrderedMap };
export type { OrderedMapIterator, IteratorType, Container, ContainerIterator, TreeContainer };

View File

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

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,402 @@
/**
* @description The iterator type including `NORMAL` and `REVERSE`.
*/
declare const enum IteratorType {
NORMAL = 0,
REVERSE = 1
}
declare abstract class ContainerIterator<T> {
/**
* @description The container pointed to by the iterator.
*/
abstract readonly container: Container<T>;
/**
* @description Iterator's type.
* @example
* console.log(container.end().iteratorType === IteratorType.NORMAL); // true
*/
readonly iteratorType: IteratorType;
/**
* @param iter - The other iterator you want to compare.
* @returns Whether this equals to obj.
* @example
* container.find(1).equals(container.end());
*/
equals(iter: ContainerIterator<T>): boolean;
/**
* @description Pointers to element.
* @returns The value of the pointer's element.
* @example
* const val = container.begin().pointer;
*/
abstract get pointer(): T;
/**
* @description Set pointer's value (some containers are unavailable).
* @param newValue - The new value you want to set.
* @example
* (<LinkList<number>>container).begin().pointer = 1;
*/
abstract set pointer(newValue: T);
/**
* @description Move `this` iterator to pre.
* @returns The iterator's self.
* @example
* const iter = container.find(1); // container = [0, 1]
* const pre = iter.pre();
* console.log(pre === iter); // true
* console.log(pre.equals(iter)); // true
* console.log(pre.pointer, iter.pointer); // 0, 0
*/
abstract pre(): this;
/**
* @description Move `this` iterator to next.
* @returns The iterator's self.
* @example
* const iter = container.find(1); // container = [1, 2]
* const next = iter.next();
* console.log(next === iter); // true
* console.log(next.equals(iter)); // true
* console.log(next.pointer, iter.pointer); // 2, 2
*/
abstract next(): this;
/**
* @description Get a copy of itself.
* @returns The copy of self.
* @example
* const iter = container.find(1); // container = [1, 2]
* const next = iter.copy().next();
* console.log(next === iter); // false
* console.log(next.equals(iter)); // false
* console.log(next.pointer, iter.pointer); // 2, 1
*/
abstract copy(): ContainerIterator<T>;
abstract isAccessible(): boolean;
}
declare abstract class Base {
/**
* @returns The size of the container.
* @example
* const container = new Vector([1, 2]);
* console.log(container.length); // 2
*/
get length(): number;
/**
* @returns The size of the container.
* @example
* const container = new Vector([1, 2]);
* console.log(container.size()); // 2
*/
size(): number;
/**
* @returns Whether the container is empty.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
empty(): boolean;
/**
* @description Clear the container.
* @example
* container.clear();
* console.log(container.empty()); // true
*/
abstract clear(): void;
}
declare abstract class Container<T> extends Base {
/**
* @returns Iterator pointing to the beginning element.
* @example
* const begin = container.begin();
* const end = container.end();
* for (const it = begin; !it.equals(end); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract begin(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the super end like c++.
* @example
* const begin = container.begin();
* const end = container.end();
* for (const it = begin; !it.equals(end); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract end(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the end element.
* @example
* const rBegin = container.rBegin();
* const rEnd = container.rEnd();
* for (const it = rBegin; !it.equals(rEnd); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract rBegin(): ContainerIterator<T>;
/**
* @returns Iterator pointing to the super begin like c++.
* @example
* const rBegin = container.rBegin();
* const rEnd = container.rEnd();
* for (const it = rBegin; !it.equals(rEnd); it.next()) {
* doSomething(it.pointer);
* }
*/
abstract rEnd(): ContainerIterator<T>;
/**
* @returns The first element of the container.
*/
abstract front(): T | undefined;
/**
* @returns The last element of the container.
*/
abstract back(): T | undefined;
/**
* @param element - The element you want to find.
* @returns An iterator pointing to the element if found, or super end if not found.
* @example
* container.find(1).equals(container.end());
*/
abstract find(element: T): ContainerIterator<T>;
/**
* @description Iterate over all elements in the container.
* @param callback - Callback function like Array.forEach.
* @example
* container.forEach((element, index) => console.log(element, index));
*/
abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void;
/**
* @description Gets the value of the element at the specified position.
* @example
* const val = container.getElementByPos(-1); // throw a RangeError
*/
abstract getElementByPos(pos: number): T;
/**
* @description Removes the element at the specified position.
* @param pos - The element's position you want to remove.
* @returns The container length after erasing.
* @example
* container.eraseElementByPos(-1); // throw a RangeError
*/
abstract eraseElementByPos(pos: number): number;
/**
* @description Removes element by iterator and move `iter` to next.
* @param iter - The iterator you want to erase.
* @returns The next iterator.
* @example
* container.eraseElementByIterator(container.begin());
* container.eraseElementByIterator(container.end()); // throw a RangeError
*/
abstract eraseElementByIterator(iter: ContainerIterator<T>): ContainerIterator<T>;
/**
* @description Using for `for...of` syntax like Array.
* @example
* for (const element of container) {
* console.log(element);
* }
*/
abstract [Symbol.iterator](): Generator<T, void>;
}
/**
* @description The initial data type passed in when initializing the container.
*/
type initContainer<T> = {
size?: number | (() => number);
length?: number;
forEach: (callback: (el: T) => void) => void;
};
declare abstract class TreeIterator<K, V> extends ContainerIterator<K | [
K,
V
]> {
abstract readonly container: TreeContainer<K, V>;
/**
* @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`.
* @returns The index subscript of the node in the tree.
* @example
* const st = new OrderedSet([1, 2, 3], true);
* console.log(st.begin().next().index); // 1
*/
get index(): number;
isAccessible(): boolean;
// @ts-ignore
pre(): this;
// @ts-ignore
next(): this;
}
declare const enum TreeNodeColor {
RED = 1,
BLACK = 0
}
declare class TreeNode<K, V> {
_color: TreeNodeColor;
_key: K | undefined;
_value: V | undefined;
_left: TreeNode<K, V> | undefined;
_right: TreeNode<K, V> | undefined;
_parent: TreeNode<K, V> | undefined;
constructor(key?: K, value?: V, color?: TreeNodeColor);
/**
* @description Get the pre node.
* @returns TreeNode about the pre node.
*/
_pre(): TreeNode<K, V>;
/**
* @description Get the next node.
* @returns TreeNode about the next node.
*/
_next(): TreeNode<K, V>;
/**
* @description Rotate left.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateLeft(): TreeNode<K, V>;
/**
* @description Rotate right.
* @returns TreeNode about moved to original position after rotation.
*/
_rotateRight(): TreeNode<K, V>;
}
declare abstract class TreeContainer<K, V> extends Container<K | [
K,
V
]> {
enableIndex: boolean;
protected _inOrderTraversal(): TreeNode<K, V>[];
protected _inOrderTraversal(pos: number): TreeNode<K, V>;
protected _inOrderTraversal(callback: (node: TreeNode<K, V>, index: number, map: this) => void): TreeNode<K, V>;
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.
* @returns Whether the modification is successful.
* @example
* const st = new orderedSet([1, 2, 5]);
* const iter = st.find(2);
* st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]
*/
updateKeyByIterator(iter: TreeIterator<K, V>, key: K): boolean;
eraseElementByPos(pos: number): number;
/**
* @description Remove the element of the specified key.
* @param key - The key you want to remove.
* @returns Whether erase successfully.
*/
eraseElementByKey(key: K): boolean;
eraseElementByIterator(iter: TreeIterator<K, V>): TreeIterator<K, V>;
/**
* @description Get the height of the tree.
* @returns Number about the height of the RB-tree.
*/
getHeight(): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns The size of the tree after union.
*/
abstract union(other: TreeContainer<K, V>): number;
/**
* @param key - The given key you want to compare.
* @returns 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.
* @returns 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.
* @returns An iterator to the first element greater than the given key.
*/
abstract upperBound(key: K): TreeIterator<K, V>;
}
declare class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
container: OrderedMap<K, V>;
constructor(node: TreeNode<K, V>, header: TreeNode<K, V>, container: OrderedMap<K, V>, iteratorType?: IteratorType);
get pointer(): [
K,
V
];
copy(): OrderedMapIterator<K, V>;
// @ts-ignore
equals(iter: OrderedMapIterator<K, V>): boolean;
}
declare class OrderedMap<K, V> extends TreeContainer<K, V> {
/**
* @param container - The initialization container.
* @param cmp - The compare function.
* @param enableIndex - Whether to enable iterator indexing function.
* @example
* new OrderedMap();
* new OrderedMap([[0, 1], [2, 1]]);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y);
* new OrderedMap([[0, 1], [2, 1]], (x, y) => x - y, true);
*/
constructor(container?: initContainer<[
K,
V
]>, cmp?: (x: K, y: K) => number, enableIndex?: boolean);
begin(): OrderedMapIterator<K, V>;
end(): OrderedMapIterator<K, V>;
rBegin(): OrderedMapIterator<K, V>;
rEnd(): OrderedMapIterator<K, V>;
front(): [
K,
V
] | undefined;
back(): [
K,
V
] | undefined;
lowerBound(key: K): OrderedMapIterator<K, V>;
upperBound(key: K): OrderedMapIterator<K, V>;
reverseLowerBound(key: K): OrderedMapIterator<K, V>;
reverseUpperBound(key: K): OrderedMapIterator<K, V>;
forEach(callback: (element: [
K,
V
], index: number, map: OrderedMap<K, V>) => void): void;
/**
* @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.
* @return The size of container after setting.
* @example
* const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
* const iter = mp.begin();
* mp.setElement(1, 0);
* mp.setElement(3, 0, iter); // give a hint will be faster.
*/
setElement(key: K, value: V, hint?: OrderedMapIterator<K, V>): number;
getElementByPos(pos: number): [
K,
V
];
find(key: K): OrderedMapIterator<K, V>;
/**
* @description Get the value of the element of the specified key.
* @param key - The specified key you want to get.
* @example
* const val = container.getElementByKey(1);
*/
getElementByKey(key: K): V | undefined;
union(other: OrderedMap<K, V>): number;
[Symbol.iterator](): Generator<[
K,
V
], void, unknown>;
// @ts-ignore
eraseElementByIterator(iter: OrderedMapIterator<K, V>): OrderedMapIterator<K, V>;
}
export { OrderedMap };
export type { OrderedMapIterator, IteratorType, Container, ContainerIterator, TreeContainer };

View File

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

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

138
server/node_modules/@js-sdsl/ordered-map/package.json generated vendored Normal file
View File

@@ -0,0 +1,138 @@
{
"name": "@js-sdsl/ordered-map",
"version": "4.4.2",
"description": "javascript standard data structure library which benchmark against C++ STL",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"author": {
"name": "ZLY201",
"email": "951711127@qq.com",
"url": "https://github.com/js-sdsl/js-sdsl"
},
"sideEffects": false,
"homepage": "https://js-sdsl.org",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/js-sdsl"
},
"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",
"@rollup/plugin-typescript": "^9.0.2",
"@types/babel__core": "^7.1.19",
"@types/chai": "^3.5.2",
"@types/delete-empty": "^3.0.2",
"@types/glob": "^8.1.0",
"@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",
"chai": "^3.5.0",
"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-import-resolver-typescript": "^3.5.2",
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-import": "^2.26.0",
"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-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-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-requirejs": "^1.1.0",
"karma-safarinative-launcher": "^1.1.0",
"karma-typescript": "^5.5.3",
"lint-staged": "^13.0.3",
"merge-stream": "^2.0.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"requirejs": "^2.3.6",
"rollup": "^2.79.1",
"rollup-plugin-license": "^3.0.0",
"rollup-plugin-ts": "^3.0.2",
"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",
"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": {}
}