working rss feed to nostr publish

This commit is contained in:
2023-11-24 00:43:28 -05:00
parent 06edcb57ae
commit 88d2f9cfec
8396 changed files with 783105 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at samchon@samchon.org. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
+120
View File
@@ -0,0 +1,120 @@
# Contribution Guide
## Publishing a Issue
Thanks for your advise. Before publishing a issue, please check some components.
### 1. Search for duplicates
Before publishing a issue, please check whether the duplicated issue exists or not.
- [Ordinary Issues](https://github.com/samchon/tstl/issues)
### 2. Did you find a bug?
When you reporting a bug, then please write about those items:
- What version of TSTL you're using
- If possible, give me an isolated way to reproduce the behavior.
- The behavior your expect to see, and the actual behavior.
### 3. Do you have a suggestion?
I always welcome your suggestion. When you publishing a suggestion, then please write such items:
- A description of the problem you're trying to solve.
- An overview of the suggested solution.
- Examples of how the suggestion whould work in various places.
- Code examples showing the expected behavior.
- If relevant, precedent in C++/STL can be useful for establishing context and expected behavior.
## Contributing Code
### Test your code
Before sending a pull request, please test your new code. You type the command `npm run build`, then compiling your code and test-automation will be all processed.
```bash
# COMPILE & TEST AT ONCE
npm run build
####
# SPECIAL COMMANDS
####
tsc # COMPILE ONLY
npm run test # TEST ONLY
npm run clean # CLEAN COMPILED RESULTS UP
```
If you succeeded to compile, but failed to pass the test-automation, then *debug* the test-automation module. I've configured the `.vscode/launch.json`. You just run the `VSCode` and click the `Start Debugging` button or press `F5` key. By the *debugging*, find the reason why the *test* is failed and fix it.
### Adding a Test
If you want to add a testing-logic, then goto the `src/test` directory. It's the directory containing the test-automation module. Declare some functions starting from the prefix `test_`. Then, they will be called after the next testing.
Note that, the special functions starting from the prefix `test_` must be `export`ed. They also must return one of them:
- `void`
- `Promise<void>`
When you detect an error, then throw exception such below:
```typescript
export function test_my_specific_logic1(): void
{
const vec = new std.Vector<number>();
for (let i: number = 0; i < 100; ++i)
vec.push_back(Math.random());
std.sort(vec.begin(), vec.end());
if (std.is_sorted(vec.begin(), vec.end()) === false)
throw new std.DomainError("std.sort doesn't work.");
}
export async function test_my_specific_logic2(): Promise<void>
{
const t1: Date = new Date();
await std.sleep_for(1000);
const t2: Date = new Date();
if (t2.getTime() - t1.getTime() < 1000)
throw new std.DomainError("std.sleep_for doesn't work.");
}
```
## Sending a Pull Request
Thanks for your contributing. Before sending a pull request to me, please check those components.
### 1. Include enough descriptions
When you send a pull request, please include a description, of what your change intends to do, on the content. Title, make it clear and simple such below:
- Refactor features
- Fix issue #17
- Add tests for issue #28
### 2. Include adequate tests
As I've mentioned in the `Contributing Code` section, your PR should pass the test-automation module. Your PR includes *new features* that have not being handled in the ordinary test-automation module, then also update *add the testing unit* please.
If there're some specific reasons that could not pass the test-automation (not error but *intended*), then please update the ordinary test-automation module or write the reasons on your PR content and *const me update the test-automation module*.
### 3. Follow coding conventions
The basic coding convention of STL is the [`snake_case`](https://en.wikipedia.org/wiki/Snake_case). TypeScript-STL follows the basic coding convention; `snake_case`. However, there's a difference when naming the classes. TSTL uses `snake_case` and [`PascalCase`](https://en.wikipedia.org/wiki/PascalCase) on the classes at the same time.
```typescript
export class Vector<T> // class base: PascalCase
{
// methods: snake_cases
public push_back(val: T): void;
public pop_back(): void;
}
export import vector = Vector; // class alias := snake_case
// global functions: snake_case
export function less_equal_to<T>(x: T, y: T): boolean;
export function sleep_until(at: Date): Promise<void>;
```
Thus, when you creating a new class, the make it to follow the [PascalCase] and make an alias following the `snake_case`. Methods in the classes or global functions, they just use the basic coding convention; `snake_case`.
- The detailed coding convention will be provided soon.
## References
I've referenced contribution guidance of the TypeScript.
- https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md
Generated Vendored
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Jeongho Nam
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.
+140
View File
@@ -0,0 +1,140 @@
# TypeScript Standard Template Library
![TSTL logo](https://raw.githubusercontent.com/samchon/logos/master/tstl.svg?token=ADEMSNKR53UIHDFF5VDPHBLBZ4M4U)
```bash
npm install --save tstl
```
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/tstl/blob/master/LICENSE)
[![npm version](https://badge.fury.io/js/tstl.svg)](https://www.npmjs.com/package/tstl)
[![Downloads](https://img.shields.io/npm/dm/tstl.svg)](https://www.npmjs.com/package/tstl)
[![Build Status](https://github.com/samchon/tstl/workflows/build/badge.svg)](https://github.com/samchon/tstl/actions?query=workflow%3Abuild)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsamchon%2Ftstl.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsamchon%2Ftstl?ref=badge_shield)
[![Chat on Gitter](https://badges.gitter.im/samchon/tstl.svg)](https://gitter.im/samchon/tstl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Implementation of STL (Standard Template Library) in TypeScript.
- Containers
- Iterators
- Algorithms
- Functors
**TSTL** is an open-source project providing features of STL, migrated from *C++* to *TypeScript*. You can enjoy the STL's own specific *containers*, *algorithms* and *functors* in the JavaScript. If TypeScript, you also can take advantage of type restrictions and generic programming with the TypeScript.
Below components are list of provided objects in the **TSTL**. If you want to know more about the **TSTL**, then please read the [**Guide Documents**](https://github.com/samchon/tstl/wiki).
## Features
### Containers
- **Linear Containers**
- [Vector](https://samchon.github.io/tstl/api/classes/std.vector.html)
- [Deque](https://samchon.github.io/tstl/api/classes/std.deque.html)
- [List](https://samchon.github.io/tstl/api/classes/std.list.html)
- [ForwardList](https://samchon.github.io/tstl/api/classes/std.forwardlist.html)
- [VectorBoolean](https://samchon.github.io/tstl/api/classes/std.vectorboolean.html)
- **Associative Containers**
- *Tree-structured Containers*
- [TreeSet](https://samchon.github.io/tstl/api/classes/std.treeset.html)
- [TreeMultiSet](https://samchon.github.io/tstl/api/classes/std.treemultiset.html)
- [TreeMap](https://samchon.github.io/tstl/api/classes/std.treemap.html)
- [TreeMultiMap](https://samchon.github.io/tstl/api/classes/std.treemultimap.html)
- *Hash-buckets based Container*
- [HashSet](https://samchon.github.io/tstl/api/classes/std.hashset.html)
- [HashMultiSet](https://samchon.github.io/tstl/api/classes/std.hashmultiset.html)
- [HashMap](https://samchon.github.io/tstl/api/classes/std.hashmap.html)
- [HashMultiMap](https://samchon.github.io/tstl/api/classes/std.hashmultimap.html)
- **Adaptor Containers**
- *Linear Adaptors*
- [Queue](https://samchon.github.io/tstl/api/classes/std.queue.html)
- [Stack](https://samchon.github.io/tstl/api/classes/std.stack.html)
- [PriorityQueue](https://samchon.github.io/tstl/api/classes/std.priorityqueue.html)
- Associative Adaptors
- (experimental) [FlatSet](https://samchon.github.io/tstl/api/classes/std_experimental.flatset.html)
- (experimental) [FlatMultiSet](https://samchon.github.io/tstl/api/classes/std_experimental.flatmultiset.html)
- (experimental) [FlatMap](https://samchon.github.io/tstl/api/classes/std_experimental.flatmap.html)
- (experimental) [FlatMultiMap](https://samchon.github.io/tstl/api/classes/std_experimental.flatmultimap.html)
### Algorithms
- [`<algorithm>`](http://www.cplusplus.com/reference/algorithm/)
- [iterations](https://github.com/samchon/tstl/blob/master/src/algorithm/iterations.ts)
- [modifiers](https://github.com/samchon/tstl/blob/master/src/algorithm/modifiers.ts)
- [partitions](https://github.com/samchon/tstl/blob/master/src/algorithm/partitions.ts)
- [sortings](https://github.com/samchon/tstl/blob/master/src/algorithm/sortings.ts)
- [binary searches](https://github.com/samchon/tstl/blob/master/src/algorithm/binary_searches.ts)
- [union sets](https://github.com/samchon/tstl/blob/master/src/algorithm/union_sets.ts)
- [heaps](https://github.com/samchon/tstl/blob/master/src/algorithm/heaps.ts)
- [mathematics](https://github.com/samchon/tstl/blob/master/src/algorithm/mathematics.ts)
### Functors
- [`<exception>`](http://www.cplusplus.com/reference/exception/)
- [Exception](https://samchon.github.io/tstl/api/classes/std.exception.html)
- [LogicError](https://samchon.github.io/tstl/api/classes/std.logicerror.html)
- [RuntimeError](https://samchon.github.io/tstl/api/classes/std.runtimeerror.html)
- [`<functional>`](http://www.cplusplus.com/reference/functional/)
- [IComparable](https://samchon.github.io/tstl/api/interfaces/std.icomparable.html)
- [IPointer](https://samchon.github.io/tstl/api/interfaces/std.ipointer.html)
- [`<utility>`](http://www.cplusplus.com/reference/utility/)
- [Pair](https://samchon.github.io/tstl/api/classes/std.pair.html)
- [`<numeric>`](http://en.cppreference.com/w/cpp/numeric)
- [IComputable](https://github.com/samchon/tstl/blob/master/src/numeric/IComputable.ts)
- [operations](https://github.com/samchon/tstl/blob/master/src/numeric/operations.ts)
- [special math](http://en.cppreference.com/w/cpp/numeric/special_math)
- [`<thread>`](https://github.com/samchon/tstl/blob/master/src/thread.ts)
- [ConditionVariable](https://samchon.github.io/tstl/api/classes/std.conditionvariable.html)
- [Mutex](https://samchon.github.io/tstl/api/classes/std.mutex.html) & [TimedMutex](https://samchon.github.io/tstl/api/classes/std.timedmutex.html)
- [SharedMutex](https://samchon.github.io/tstl/api/classes/std.sharedmutex.html) & [SharedTimeMutex](https://samchon.github.io/tstl/api/classes/std.sharedtimedmutex.html)
- [Semaphore](https://samchon.github.io/tstl/api/classes/std.semaphore.html)
- [Latch](https://samchon.github.io/tstl/api/classes/std.latch.html)
- [Barrier](https://samchon.github.io/tstl/api/classes/std.barrier.html)
## Installation
### NPM Module
Installing **TSTL** in *NodeJS* is very easy. Just install with the `npm`
```bash
# Install TSTL from the NPM module
npm install --save tstl
```
### Usage
``` typescript
import std from "tstl";
function main(): void
{
const map: std.TreeMap<number, string> = new std.TreeMap();
map.emplace(1, "First");
map.emplace(4, "Fourth");
map.emplace(5, "Fifth");
map.set(9, "Nineth");
for (const it of map)
console.log(it.first, it.second);
const it: std.TreeMap.Iterator<number, string> = map.lower_bound(3);
console.log(`lower bound of 3 is: ${x.first}, ${x.second}`);
}
main();
```
## Appendix
- **Repositories**
- [GitHub Repository](https://github.com/samchon/tstl)
- [NPM Repository](https://www.npmjs.com/package/tstl)
- **Documents**
- [**Guide Documents**](https://github.com/samchon/tstl/wiki)
- [API Documents](https://samchon.github.io/tstl/api)
- [Release Notes](https://github.com/samchon/tstl/releases)
- **Extensions**
- [ASTL](https://github.com/samchon/astl) - C++ STL for AssemblyScript
- [ECol](https://github.com/samchon/ecol) - Collections dispatching events
- [**TGrid**](https://github.com/samchon/tgrid) - Network & Thread extension
- [Mutex-Server](https://github.com/samchon/mutex-server) - Critical sections in the network level
+52
View File
@@ -0,0 +1,52 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPointer } from "../functional/IPointer";
import { Pair } from "../utility/Pair";
import { Comparator } from "../internal/functional/Comparator";
/**
* Get iterator to lower bound.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element equal or after the val.
*/
export declare function lower_bound<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, val: IPointer.ValueType<ForwardIterator>, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Get iterator to upper bound.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element after the key.
*/
export declare function upper_bound<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, val: IPointer.ValueType<ForwardIterator>, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Get range of equal elements.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Pair of {@link lower_bound} and {@link upper_bound}.
*/
export declare function equal_range<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, val: IPointer.ValueType<ForwardIterator>, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): Pair<ForwardIterator, ForwardIterator>;
/**
* Test whether a value exists in sorted range.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the value exists or not.
*/
export declare function binary_search<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, val: IPointer.ValueType<ForwardIterator>, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): boolean;
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.binary_search = exports.equal_range = exports.upper_bound = exports.lower_bound = void 0;
var Pair_1 = require("../utility/Pair");
var global_1 = require("../iterator/global");
var comparators_1 = require("../functional/comparators");
/* =========================================================
BINARY SEARCH
========================================================= */
/**
* Get iterator to lower bound.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element equal or after the val.
*/
function lower_bound(first, last, val, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var count = (0, global_1.distance)(first, last);
while (count > 0) {
var step = Math.floor(count / 2);
var it = (0, global_1.advance)(first, step);
if (comp(it.value, val)) {
first = it.next();
count -= step + 1;
}
else
count = step;
}
return first;
}
exports.lower_bound = lower_bound;
/**
* Get iterator to upper bound.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element after the key.
*/
function upper_bound(first, last, val, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var count = (0, global_1.distance)(first, last);
while (count > 0) {
var step = Math.floor(count / 2);
var it = (0, global_1.advance)(first, step);
if (!comp(val, it.value)) {
first = it.next();
count -= step + 1;
}
else
count = step;
}
return first;
}
exports.upper_bound = upper_bound;
/**
* Get range of equal elements.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Pair of {@link lower_bound} and {@link upper_bound}.
*/
function equal_range(first, last, val, comp) {
if (comp === void 0) { comp = comparators_1.less; }
first = lower_bound(first, last, val, comp);
var second = upper_bound(first, last, val, comp);
return new Pair_1.Pair(first, second);
}
exports.equal_range = equal_range;
/**
* Test whether a value exists in sorted range.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param val Value to search for.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the value exists or not.
*/
function binary_search(first, last, val, comp) {
if (comp === void 0) { comp = comparators_1.less; }
first = lower_bound(first, last, val, comp);
return !first.equals(last) && !comp(val, first.value);
}
exports.binary_search = binary_search;
//# sourceMappingURL=binary_search.js.map
+60
View File
@@ -0,0 +1,60 @@
/**
* @packageDocumentation
* @module std
*/
import { IRandomAccessIterator } from "../iterator/IRandomAccessIterator";
import { IPointer } from "../functional/IPointer";
import { Comparator } from "../internal/functional/Comparator";
import { General } from "../internal/functional/General";
/**
* Make a heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function make_heap<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Push an element into heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function push_heap<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Pop an element from heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function pop_heap<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Test whether a range is heap.
*
* @param first Bi-directional iteartor of the first position.
* @param last Bi-directional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the range is heap.
*/
export declare function is_heap<RandomAccessIterator extends Readonly<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): boolean;
/**
* Find the first element not in heap order.
*
* @param first Bi-directional iteartor of the first position.
* @param last Bi-directional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element not in heap order.
*/
export declare function is_heap_until<RandomAccessIterator extends Readonly<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): RandomAccessIterator;
/**
* Sort elements of a heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function sort_heap<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
+143
View File
@@ -0,0 +1,143 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sort_heap = exports.is_heap_until = exports.is_heap = exports.pop_heap = exports.push_heap = exports.make_heap = void 0;
var comparators_1 = require("../functional/comparators");
var global_1 = require("../iterator/global");
/* =========================================================
EA-STL (https://github.com/electronicarts/EASTL/blob/master/include/EASTL/heap.h)
- PUSH & POP
- SORT
- INTERNAL
============================================================
PUSH & POP
--------------------------------------------------------- */
/**
* Make a heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function make_heap(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var heapSize = (0, global_1.distance)(first, last);
if (heapSize < 2)
return;
var parentPosition = ((heapSize - 2) >> 1) + 1;
do {
var temp = first.advance(--parentPosition).value;
_Adjust_heap(first, parentPosition, heapSize, parentPosition, temp, comp);
} while (parentPosition !== 0);
}
exports.make_heap = make_heap;
/**
* Push an element into heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function push_heap(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var temp = last.prev().value;
_Promote_heap(first, 0, (0, global_1.distance)(first, last) - 1, temp, comp);
}
exports.push_heap = push_heap;
/**
* Pop an element from heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function pop_heap(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var bottom = last.prev();
var temp = bottom.value;
bottom.value = first.value;
_Adjust_heap(first, 0, (0, global_1.distance)(first, last) - 1, 0, temp, comp);
}
exports.pop_heap = pop_heap;
/* ---------------------------------------------------------
SORT
--------------------------------------------------------- */
/**
* Test whether a range is heap.
*
* @param first Bi-directional iteartor of the first position.
* @param last Bi-directional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the range is heap.
*/
function is_heap(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var it = is_heap_until(first, last, comp);
return it.equals(last);
}
exports.is_heap = is_heap;
/**
* Find the first element not in heap order.
*
* @param first Bi-directional iteartor of the first position.
* @param last Bi-directional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element not in heap order.
*/
function is_heap_until(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var counter = 0;
for (var child = first.next(); _Comp_it(child, last.index()); child = child.next(), counter ^= 1) {
if (comp(first.value, child.value))
return child;
first = (0, global_1.advance)(first, counter);
}
return last;
}
exports.is_heap_until = is_heap_until;
/**
* Sort elements of a heap.
*
* @param first Random access iteartor of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function sort_heap(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
for (; (0, global_1.distance)(first, last) > 1; last = last.prev())
pop_heap(first, last, comp);
}
exports.sort_heap = sort_heap;
/* ---------------------------------------------------------
INTERNAL
--------------------------------------------------------- */
function _Promote_heap(first, topPosition, position, value, comp) {
for (var parentPosition = (position - 1) >> 1; position > topPosition &&
comp(first.advance(parentPosition).value, value); parentPosition = (position - 1) >> 1) {
first.advance(position).value = first.advance(parentPosition).value;
position = parentPosition;
}
first.advance(position).value = value;
}
function _Adjust_heap(first, topPosition, heapSize, position, value, comp) {
var childPosition = 2 * position + 2;
for (; childPosition < heapSize; childPosition = 2 * childPosition + 2) {
if (comp(first.advance(childPosition).value, first.advance(childPosition - 1).value))
--childPosition;
first.advance(position).value = first.advance(childPosition).value;
position = childPosition;
}
if (childPosition === heapSize) {
first.advance(position).value = first.advance(childPosition - 1).value;
position = childPosition - 1;
}
_Promote_heap(first, topPosition, position, value, comp);
}
function _Comp_it(x, y) {
if (x.base instanceof Function)
return y < x;
else
return x < y;
}
//# sourceMappingURL=heap.js.map
+13
View File
@@ -0,0 +1,13 @@
/**
* @packageDocumentation
* @module std
*/
export * from "./binary_search";
export * from "./heap";
export * from "./iterations";
export * from "./mathematics";
export * from "./modifiers";
export * from "./partition";
export * from "./random";
export * from "./sorting";
export * from "./merge";
+36
View File
@@ -0,0 +1,36 @@
"use strict";
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
// <algorithm>
//
// @reference http://www.cplusplus.com/reference/algorithm
// @author Jeongho Nam - https://github.com/samchon
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./binary_search"), exports);
__exportStar(require("./heap"), exports);
__exportStar(require("./iterations"), exports);
__exportStar(require("./mathematics"), exports);
__exportStar(require("./modifiers"), exports);
__exportStar(require("./partition"), exports);
__exportStar(require("./random"), exports);
__exportStar(require("./sorting"), exports);
__exportStar(require("./merge"), exports);
//# sourceMappingURL=index.js.map
+255
View File
@@ -0,0 +1,255 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPointer } from "../functional/IPointer";
import { Pair } from "../utility/Pair";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { UnaryPredicator } from "../internal/functional/UnaryPredicator";
/**
* Apply a function to elements in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param fn The function to apply.
*
* @return The function *fn* itself.
*/
export declare function for_each<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, Func extends (val: IPointer.ValueType<InputIterator>) => any>(first: InputIterator, last: InputIterator, fn: Func): Func;
/**
* Apply a function to elements in steps.
*
* @param first Input iteartor of the starting position.
* @param n Steps to maximum advance.
* @param fn The function to apply.
*
* @return Iterator advanced from *first* for *n* steps.
*/
export declare function for_each_n<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, Func extends (val: IPointer.ValueType<InputIterator>) => any>(first: InputIterator, n: number, fn: Func): InputIterator;
/**
* Test whether all elements meet a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* returns always `true` for all elements.
*/
export declare function all_of<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): boolean;
/**
* Test whether any element meets a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* returns at least a `true` for all elements.
*/
export declare function any_of<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): boolean;
/**
* Test whether any element doesn't meet a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* doesn't return `true` for all elements.
*/
export declare function none_of<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): boolean;
/**
* Test whether two ranges are equal.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return Whether two ranges are equal.
*/
export declare function equal<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2): boolean;
/**
* Test whether two ranges are equal.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return Whether two ranges are equal.
*/
export declare function equal<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator2>, InputIterator2>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, pred: BinaryPredicator<IPointer.ValueType<InputIterator1>, IPointer.ValueType<InputIterator2>>): boolean;
/**
* Compare lexicographically.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the 1st range precedes the 2nd.
*/
export declare function lexicographical_compare<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, comp?: BinaryPredicator<IPointer.ValueType<Iterator1>>): boolean;
/**
* Find a value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to find.
*
* @return Iterator to the first element {@link equal to equal_to} the value.
*/
export declare function find<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, val: IPointer.ValueType<InputIterator>): InputIterator;
/**
* Find a matched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Iterator to the first element *pred* returns `true`.
*/
export declare function find_if<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): InputIterator;
/**
* Find a mismatched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Iterator to the first element *pred* returns `false`.
*/
export declare function find_if_not<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): InputIterator;
/**
* Find the last sub range.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
*
* @return Iterator to the first element of the last sub range.
*/
export declare function find_end<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1;
/**
* Find the last sub range.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return Iterator to the first element of the last sub range.
*/
export declare function find_end<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator2>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: BinaryPredicator<IPointer.ValueType<Iterator1>, IPointer.ValueType<Iterator2>>): Iterator1;
/**
* Find the first sub range.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
*
* @return Iterator to the first element of the first sub range.
*/
export declare function find_first_of<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2): Iterator1;
/**
* Find the first sub range.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return Iterator to the first element of the first sub range.
*/
export declare function find_first_of<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator2>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, last2: Iterator2, pred: BinaryPredicator<IPointer.ValueType<Iterator1>, IPointer.ValueType<Iterator2>>): Iterator1;
/**
* Find the first adjacent element.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Iterator to the first element of adjacent find.
*/
export declare function adjacent_find<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred?: BinaryPredicator<IPointer.ValueType<InputIterator>>): InputIterator;
/**
* Search sub range.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
* @param last2 Forward iterator of the last position of the 2nd range.
*
* @return Iterator to the first element of the sub range.
*/
export declare function search<ForwardIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator1>>, ForwardIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator2>>>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2): ForwardIterator1;
/**
* Search sub range.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
* @param last2 Forward iterator of the last position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return Iterator to the first element of the sub range.
*/
export declare function search<ForwardIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator1>>, ForwardIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator2>, ForwardIterator2>>>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, last2: ForwardIterator2, pred: BinaryPredicator<IPointer.ValueType<ForwardIterator1>, IPointer.ValueType<ForwardIterator2>>): ForwardIterator1;
/**
* Search specific and repeated elements.
*
* @param first Forward iteartor of the first position.
* @param last Forward iterator of the last position.
* @param count Count to be repeated.
* @param val Value to search.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Iterator to the first element of the repetition.
*/
export declare function search_n<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, count: number, val: IPointer.ValueType<ForwardIterator>, pred?: BinaryPredicator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Find the first mistmached position between two ranges.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
*
* @return A {@link Pair} of mismatched positions.
*/
export declare function mismatch<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2): Pair<Iterator1, Iterator2>;
/**
* Find the first mistmached position between two ranges.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param pred A binary function predicates two arguments are equal.
*
* @return A {@link Pair} of mismatched positions.
*/
export declare function mismatch<Iterator1 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator1>, Iterator1>>, Iterator2 extends Readonly<IForwardIterator<IPointer.ValueType<Iterator2>, Iterator2>>>(first1: Iterator1, last1: Iterator1, first2: Iterator2, pred: BinaryPredicator<IPointer.ValueType<Iterator1>, IPointer.ValueType<Iterator2>>): Pair<Iterator1, Iterator2>;
/**
* Count matched value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to count.
*
* @return The matched count.
*/
export declare function count<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, val: IPointer.ValueType<InputIterator>): number;
/**
* Count matched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return The matched count.
*/
export declare function count_if<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): number;
+319
View File
@@ -0,0 +1,319 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.count_if = exports.count = exports.mismatch = exports.search_n = exports.search = exports.adjacent_find = exports.find_first_of = exports.find_end = exports.find_if_not = exports.find_if = exports.find = exports.lexicographical_compare = exports.equal = exports.none_of = exports.any_of = exports.all_of = exports.for_each_n = exports.for_each = void 0;
var Pair_1 = require("../utility/Pair");
var comparators_1 = require("../functional/comparators");
var global_1 = require("../iterator/global");
/* =========================================================
ITERATIONS (NON-MODIFYING SEQUENCE)
- FOR_EACH
- AGGREGATE CONDITIONS
- FINDERS
- COUNTERS
============================================================
FOR_EACH
--------------------------------------------------------- */
/**
* Apply a function to elements in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param fn The function to apply.
*
* @return The function *fn* itself.
*/
function for_each(first, last, fn) {
for (var it = first; !it.equals(last); it = it.next())
fn(it.value);
return fn;
}
exports.for_each = for_each;
/**
* Apply a function to elements in steps.
*
* @param first Input iteartor of the starting position.
* @param n Steps to maximum advance.
* @param fn The function to apply.
*
* @return Iterator advanced from *first* for *n* steps.
*/
function for_each_n(first, n, fn) {
for (var i = 0; i < n; ++i) {
fn(first.value);
first = first.next();
}
return first;
}
exports.for_each_n = for_each_n;
/* ---------------------------------------------------------
AGGREGATE CONDITIONS
--------------------------------------------------------- */
/**
* Test whether all elements meet a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* returns always `true` for all elements.
*/
function all_of(first, last, pred) {
for (var it = first; !it.equals(last); it = it.next())
if (pred(it.value) === false)
return false;
return true;
}
exports.all_of = all_of;
/**
* Test whether any element meets a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* returns at least a `true` for all elements.
*/
function any_of(first, last, pred) {
for (var it = first; !it.equals(last); it = it.next())
if (pred(it.value) === true)
return true;
return false;
}
exports.any_of = any_of;
/**
* Test whether any element doesn't meet a specific condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Whether the *pred* doesn't return `true` for all elements.
*/
function none_of(first, last, pred) {
return !any_of(first, last, pred);
}
exports.none_of = none_of;
function equal(first1, last1, first2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
while (!first1.equals(last1))
if (!pred(first1.value, first2.value))
return false;
else {
first1 = first1.next();
first2 = first2.next();
}
return true;
}
exports.equal = equal;
/**
* Compare lexicographically.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the 1st range precedes the 2nd.
*/
function lexicographical_compare(first1, last1, first2, last2, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (!first1.equals(last1))
if (first2.equals(last2) || comp(first2.value, first1.value))
return false;
else if (comp(first1.value, first2.value))
return true;
else {
first1 = first1.next();
first2 = first2.next();
}
return !first2.equals(last2);
}
exports.lexicographical_compare = lexicographical_compare;
/* ---------------------------------------------------------
FINDERS
--------------------------------------------------------- */
/**
* Find a value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to find.
*
* @return Iterator to the first element {@link equal to equal_to} the value.
*/
function find(first, last, val) {
return find_if(first, last, function (elem) { return (0, comparators_1.equal_to)(elem, val); });
}
exports.find = find;
/**
* Find a matched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Iterator to the first element *pred* returns `true`.
*/
function find_if(first, last, pred) {
for (var it = first; !it.equals(last); it = it.next())
if (pred(it.value))
return it;
return last;
}
exports.find_if = find_if;
/**
* Find a mismatched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return Iterator to the first element *pred* returns `false`.
*/
function find_if_not(first, last, pred) {
return find_if(first, last, function (elem) { return !pred(elem); });
}
exports.find_if_not = find_if_not;
function find_end(first1, last1, first2, last2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (first2.equals(last2))
return last1;
var ret = last1;
for (; !first1.equals(last1); first1 = first1.next()) {
var it1 = first1;
var it2 = first2;
while (pred(it1.value, it2.value)) {
it1 = it1.next();
it2 = it2.next();
if (it2.equals(last2)) {
ret = first1;
break;
}
else if (it1.equals(last1))
return ret;
}
}
return ret;
}
exports.find_end = find_end;
function find_first_of(first1, last1, first2, last2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
for (; !first1.equals(last1); first1 = first1.next())
for (var it = first2; !it.equals(last2); it = it.next())
if (pred(first1.value, it.value))
return first1;
return last1;
}
exports.find_first_of = find_first_of;
/**
* Find the first adjacent element.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Iterator to the first element of adjacent find.
*/
function adjacent_find(first, last, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (!first.equals(last)) {
var next = first.next();
while (!next.equals(last)) {
if (pred(first.value, next.value))
return first;
first = first.next();
next = next.next();
}
}
return last;
}
exports.adjacent_find = adjacent_find;
function search(first1, last1, first2, last2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (first2.equals(last2))
return first1;
for (; !first1.equals(last1); first1 = first1.next()) {
var it1 = first1;
var it2 = first2;
while (pred(it1.value, it2.value)) {
if (it2.equals(last2))
return first1;
else if (it1.equals(last1))
return last1;
it1 = it1.next();
it2 = it2.next();
}
}
return last1;
}
exports.search = search;
/**
* Search specific and repeated elements.
*
* @param first Forward iteartor of the first position.
* @param last Forward iterator of the last position.
* @param count Count to be repeated.
* @param val Value to search.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Iterator to the first element of the repetition.
*/
function search_n(first, last, count, val, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
var limit = (0, global_1.advance)(first, (0, global_1.distance)(first, last) - count);
for (; !first.equals(limit); first = first.next()) {
var it = first;
var i = 0;
while (pred(it.value, val)) {
it = it.next();
if (++i === count)
return first;
}
}
return last;
}
exports.search_n = search_n;
function mismatch(first1, last1, first2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
while (!first1.equals(last1) && pred(first1.value, first2.value)) {
first1 = first1.next();
first2 = first2.next();
}
return new Pair_1.Pair(first1, first2);
}
exports.mismatch = mismatch;
/* ---------------------------------------------------------
COUNTERS
--------------------------------------------------------- */
/**
* Count matched value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to count.
*
* @return The matched count.
*/
function count(first, last, val) {
return count_if(first, last, function (elem) { return (0, comparators_1.equal_to)(elem, val); });
}
exports.count = count;
/**
* Count matched condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A function predicates the specific condition.
*
* @return The matched count.
*/
function count_if(first, last, pred) {
var ret = 0;
for (var it = first; !it.equals(last); it = it.next())
if (pred(it.value))
++ret;
return ret;
}
exports.count_if = count_if;
//# sourceMappingURL=iterations.js.map
+109
View File
@@ -0,0 +1,109 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IBidirectionalIterator } from "../iterator/IBidirectionalIterator";
import { IPointer } from "../functional/IPointer";
import { General } from "../internal/functional/General";
import { Pair } from "../utility/Pair";
import { Comparator } from "../internal/functional/Comparator";
/**
* Get the minium value.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The minimum value.
*/
export declare function min<T>(items: T[], comp?: Comparator<T>): T;
/**
* Get the maximum value.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The maximum value.
*/
export declare function max<T>(items: T[], comp?: Comparator<T>): T;
/**
* Get the minimum & maximum values.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return A {@link Pair} of minimum & maximum values.
*/
export declare function minmax<T>(items: T[], comp?: Comparator<T>): Pair<T, T>;
/**
* Get the minimum element in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the minimum element.
*/
export declare function min_element<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Get the maximum element in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the maximum element.
*/
export declare function max_element<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Get the minimum & maximum elements in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return A {@link Pair} of iterators to the minimum & maximum elements.
*/
export declare function minmax_element<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, comp?: Comparator<IPointer.ValueType<ForwardIterator>>): Pair<ForwardIterator, ForwardIterator>;
/**
* Get the clamp value.
*
* @param v The value to clamp.
* @param lo Lower value than *hi*.
* @param hi Higher value than *lo*.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The clamp value.
*/
export declare function clamp<T>(v: T, lo: T, hi: T, comp?: Comparator<T>): T;
/**
* Test whether two ranges are in permutation relationship.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Whether permutation or not.
*/
export declare function is_permutation<ForwardIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator1>>, ForwardIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator2>>>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2, pred?: Comparator<IPointer.ValueType<ForwardIterator1>>): boolean;
/**
* Transform to the previous permutation.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the transformation was meaningful.
*/
export declare function prev_permutation<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator, comp?: Comparator<IPointer.ValueType<BidirectionalIterator>>): boolean;
/**
* Transform to the next permutation.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the transformation was meaningful.
*/
export declare function next_permutation<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator, comp?: Comparator<IPointer.ValueType<BidirectionalIterator>>): boolean;
+257
View File
@@ -0,0 +1,257 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.next_permutation = exports.prev_permutation = exports.is_permutation = exports.clamp = exports.minmax_element = exports.max_element = exports.min_element = exports.minmax = exports.max = exports.min = void 0;
var Pair_1 = require("../utility/Pair");
var comparators_1 = require("../functional/comparators");
var global_1 = require("../iterator/global");
var iterations_1 = require("./iterations");
var modifiers_1 = require("./modifiers");
/* =========================================================
MATHMATICS
- MIN & MAX
- PERMUTATION
============================================================
MIN & MAX
--------------------------------------------------------- */
/**
* Get the minium value.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The minimum value.
*/
function min(items, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var minimum = items[0];
for (var i = 1; i < items.length; ++i)
if (comp(items[i], minimum))
minimum = items[i];
return minimum;
}
exports.min = min;
/**
* Get the maximum value.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The maximum value.
*/
function max(items, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var maximum = items[0];
for (var i = 1; i < items.length; ++i)
if (comp(maximum, items[i]))
maximum = items[i];
return maximum;
}
exports.max = max;
/**
* Get the minimum & maximum values.
*
* @param items Items to search through.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return A {@link Pair} of minimum & maximum values.
*/
function minmax(items, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var minimum = items[0];
var maximum = items[0];
for (var i = 1; i < items.length; ++i) {
if (comp(items[i], minimum))
minimum = items[i];
if (comp(maximum, items[i]))
maximum = items[i];
}
return new Pair_1.Pair(minimum, maximum);
}
exports.minmax = minmax;
/**
* Get the minimum element in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the minimum element.
*/
function min_element(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var smallest = first;
first = first.next();
for (; !first.equals(last); first = first.next())
if (comp(first.value, smallest.value))
smallest = first;
return smallest;
}
exports.min_element = min_element;
/**
* Get the maximum element in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the maximum element.
*/
function max_element(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var largest = first;
first = first.next();
for (; !first.equals(last); first = first.next())
if (comp(largest.value, first.value))
largest = first;
return largest;
}
exports.max_element = max_element;
/**
* Get the minimum & maximum elements in range.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return A {@link Pair} of iterators to the minimum & maximum elements.
*/
function minmax_element(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var smallest = first;
var largest = first;
first = first.next();
for (; !first.equals(last); first = first.next()) {
if (comp(first.value, smallest.value))
// first is less than the smallest.
smallest = first;
if (comp(largest.value, first.value))
// first is not less than the largest.
largest = first;
}
return new Pair_1.Pair(smallest, largest);
}
exports.minmax_element = minmax_element;
/**
* Get the clamp value.
*
* @param v The value to clamp.
* @param lo Lower value than *hi*.
* @param hi Higher value than *lo*.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return The clamp value.
*/
function clamp(v, lo, hi, comp) {
if (comp === void 0) { comp = comparators_1.less; }
return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}
exports.clamp = clamp;
/* ---------------------------------------------------------
PERMUATATIONS
--------------------------------------------------------- */
/**
* Test whether two ranges are in permutation relationship.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Whether permutation or not.
*/
function is_permutation(first1, last1, first2, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
// find the mismatched
var pair = ((0, iterations_1.mismatch)(first1, last1, first2, pred));
first1 = pair.first;
first2 = pair.second;
if (first1.equals(last1))
return true;
var last2 = (0, global_1.advance)(first2, (0, global_1.distance)(first1, last1));
var _loop_1 = function (it) {
var lambda = function (val) {
return pred(val, it.value);
};
if ((0, iterations_1.find_if)(first1, it, lambda).equals(it)) {
var n = (0, iterations_1.count_if)(first2, last2, lambda);
if (n === 0 || (0, iterations_1.count_if)(it, last1, lambda) !== n)
return { value: false };
}
};
for (var it = first1; !it.equals(last1); it = it.next()) {
var state_1 = _loop_1(it);
if (typeof state_1 === "object")
return state_1.value;
}
return true;
}
exports.is_permutation = is_permutation;
/**
* Transform to the previous permutation.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the transformation was meaningful.
*/
function prev_permutation(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
if (first.equals(last) === true)
return false;
var previous = last.prev();
if (first.equals(previous) === true)
return false;
while (true) {
var x = previous;
previous = previous.prev();
if (comp(x.value, previous.value) === true) {
var y = last.prev();
while (comp(y.value, previous.value) === false)
y = y.prev();
(0, modifiers_1.iter_swap)(previous, y);
(0, modifiers_1.reverse)(x, last);
return true;
}
if (previous.equals(first) === true) {
(0, modifiers_1.reverse)(first, last);
return false;
}
}
}
exports.prev_permutation = prev_permutation;
/**
* Transform to the next permutation.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether the transformation was meaningful.
*/
function next_permutation(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
if (first.equals(last) === true)
return false;
var previous = last.prev();
if (first.equals(previous) === true)
return false;
while (true) {
var x = previous;
previous = previous.prev();
if (comp(previous.value, x.value) === true) {
var y = last.prev();
while (comp(previous.value, y.value) === false)
y = y.prev();
(0, modifiers_1.iter_swap)(previous, y);
(0, modifiers_1.reverse)(x, last);
return true;
}
if (previous.equals(first) === true) {
(0, modifiers_1.reverse)(first, last);
return false;
}
}
}
exports.next_permutation = next_permutation;
//# sourceMappingURL=mathematics.js.map
+96
View File
@@ -0,0 +1,96 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IBidirectionalIterator } from "../iterator/IBidirectionalIterator";
import { IPointer } from "../functional/IPointer";
import { General } from "../internal/functional/General";
import { Writeonly } from "../internal/functional/Writeonly";
import { Comparator } from "../internal/functional/Comparator";
/**
* Merge two sorted ranges.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function merge<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator1>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, output: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator1>>): OutputIterator;
/**
* Merge two sorted & consecutive ranges.
*
* @param first Bidirectional iterator of the first position.
* @param middle Bidirectional iterator of the initial position of the 2nd range.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function inplace_merge<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator, comp?: Comparator<IPointer.ValueType<BidirectionalIterator>>): void;
/**
* Test whether two sorted ranges are in inclusion relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether [first, last1) includes [first2, last2).
*/
export declare function includes<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, comp?: Comparator<IPointer.ValueType<InputIterator1>>): boolean;
/**
* Combine two sorted ranges to union relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function set_union<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator1>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, output: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator1>>): OutputIterator;
/**
* Combine two sorted ranges to intersection relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function set_intersection<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator1>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, output: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator1>>): OutputIterator;
/**
* Combine two sorted ranges to difference relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function set_difference<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator1>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, output: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator1>>): OutputIterator;
/**
* Combine two sorted ranges to symmetric difference relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function set_symmetric_difference<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator1>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, last2: InputIterator2, output: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator1>>): OutputIterator;
+218
View File
@@ -0,0 +1,218 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.set_symmetric_difference = exports.set_difference = exports.set_intersection = exports.set_union = exports.includes = exports.inplace_merge = exports.merge = void 0;
var comparators_1 = require("../functional/comparators");
var modifiers_1 = require("./modifiers");
var factory_1 = require("../iterator/factory");
var Vector_1 = require("../container/Vector");
/* =========================================================
MERGE & SET OPERATIONS
- MERGE
- SET OPERATION
============================================================
MERGE
--------------------------------------------------------- */
/**
* Merge two sorted ranges.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function merge(first1, last1, first2, last2, output, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (true) {
if (first1.equals(last1))
return (0, modifiers_1.copy)(first2, last2, output);
else if (first2.equals(last2))
return (0, modifiers_1.copy)(first1, last1, output);
if (comp(first1.value, first2.value)) {
output.value = first1.value;
first1 = first1.next();
}
else {
output.value = first2.value;
first2 = first2.next();
}
output = output.next();
}
}
exports.merge = merge;
/**
* Merge two sorted & consecutive ranges.
*
* @param first Bidirectional iterator of the first position.
* @param middle Bidirectional iterator of the initial position of the 2nd range.
* @param last Bidirectional iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function inplace_merge(first, middle, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var vector = new Vector_1.Vector();
merge(first, middle, middle, last, (0, factory_1.back_inserter)(vector), comp);
(0, modifiers_1.copy)(vector.begin(), vector.end(), first);
}
exports.inplace_merge = inplace_merge;
/* ---------------------------------------------------------
SET OPERATIONS
--------------------------------------------------------- */
/**
* Test whether two sorted ranges are in inclusion relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether [first, last1) includes [first2, last2).
*/
function includes(first1, last1, first2, last2, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (!first2.equals(last2)) {
if (first1.equals(last1) || comp(first2.value, first1.value))
return false;
else if (!comp(first1.value, first2.value))
first2 = first2.next();
first1 = first1.next();
}
return true;
}
exports.includes = includes;
/**
* Combine two sorted ranges to union relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function set_union(first1, last1, first2, last2, output, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (true) {
if (first1.equals(last1))
return (0, modifiers_1.copy)(first2, last2, output);
else if (first2.equals(last2))
return (0, modifiers_1.copy)(first1, last1, output);
if (comp(first1.value, first2.value)) {
output.value = first1.value;
first1 = first1.next();
}
else if (comp(first2.value, first1.value)) {
output.value = first2.value;
first2 = first2.next();
}
else {
// equals
output.value = first1.value;
first1 = first1.next();
first2 = first2.next();
}
output = output.next();
}
}
exports.set_union = set_union;
/**
* Combine two sorted ranges to intersection relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function set_intersection(first1, last1, first2, last2, output, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (!first1.equals(last1) && !first2.equals(last2))
if (comp(first1.value, first2.value))
first1 = first1.next();
else if (comp(first2.value, first1.value))
first2 = first2.next();
else {
output.value = first1.value;
output = output.next();
first1 = first1.next();
first2 = first2.next();
}
return output;
}
exports.set_intersection = set_intersection;
/**
* Combine two sorted ranges to difference relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function set_difference(first1, last1, first2, last2, output, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (!first1.equals(last1) && !first2.equals(last2))
if (comp(first1.value, first2.value)) {
output.value = first1.value;
output = output.next();
first1 = first1.next();
}
else if (comp(first2.value, first1.value))
first2 = first2.next();
else {
first1 = first1.next();
first2 = first2.next();
}
return (0, modifiers_1.copy)(first1, last1, output);
}
exports.set_difference = set_difference;
/**
* Combine two sorted ranges to symmetric difference relationship.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param last2 Input iterator of the last position of the 2nd range.
* @param output Output iterator of the first position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function set_symmetric_difference(first1, last1, first2, last2, output, comp) {
if (comp === void 0) { comp = comparators_1.less; }
while (true) {
if (first1.equals(last1))
return (0, modifiers_1.copy)(first2, last2, output);
else if (first2.equals(last2))
return (0, modifiers_1.copy)(first1, last1, output);
if (comp(first1.value, first2.value)) {
output.value = first1.value;
output = output.next();
first1 = first1.next();
}
else if (comp(first2.value, first1.value)) {
output.value = first2.value;
output = output.next();
first2 = first2.next();
}
else {
// equals
first1 = first1.next();
first2 = first2.next();
}
}
}
exports.set_symmetric_difference = set_symmetric_difference;
//# sourceMappingURL=merge.js.map
+296
View File
@@ -0,0 +1,296 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IBidirectionalIterator } from "../iterator/IBidirectionalIterator";
import { IRandomAccessIterator } from "../iterator/IRandomAccessIterator";
import { IPointer } from "../functional/IPointer";
import { UnaryPredicator } from "../internal/functional/UnaryPredicator";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { General } from "../internal/functional/General";
import { Writeonly } from "../internal/functional/Writeonly";
declare type UnaryOperatorInferrer<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>> = (val: IPointer.ValueType<InputIterator>) => IPointer.ValueType<OutputIterator>;
declare type BinaryOperatorInferrer<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator2>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>> = (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator2>) => IPointer.ValueType<OutputIterator>;
/**
* Copy elements in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator): OutputIterator;
/**
* Copy *n* elements.
*
* @param first Input iteartor of the first position.
* @param n Number of elements to copy.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function copy_n<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, n: number, output: OutputIterator): OutputIterator;
/**
* Copy specific elements by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param pred A function predicates the specific condition.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function copy_if<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): OutputIterator;
/**
* Copy elements reversely.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function copy_backward<InputIterator extends Readonly<IBidirectionalIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IBidirectionalIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator): OutputIterator;
/**
* Fill range elements
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to fill.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function fill<ForwardIterator extends Writeonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, val: IPointer.ValueType<ForwardIterator>): void;
/**
* Fill *n* elements.
*
* @param first Input iteartor of the first position.
* @param n Number of elements to fill.
* @param val The value to fill.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function fill_n<OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>>(first: OutputIterator, n: number, val: IPointer.ValueType<OutputIterator>): OutputIterator;
/**
* Transform elements.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param op Unary function determines the transform.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function transform<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, result: OutputIterator, op: UnaryOperatorInferrer<InputIterator, OutputIterator>): OutputIterator;
/**
* Transform elements.
*
* @param first1 Input iteartor of the first position of the 1st range.
* @param last1 Input iterator of the last position of the 1st range.
* @param first2 Input iterator of the first position of the 2nd range.
* @param output Output iterator of the first position.
* @param op Binary function determines the transform.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function transform<InputIterator1 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator1>, InputIterator1>>, InputIterator2 extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator2>, InputIterator2>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>>(first1: InputIterator1, last1: InputIterator1, first2: InputIterator2, result: OutputIterator, op: BinaryOperatorInferrer<InputIterator1, InputIterator2, OutputIterator>): OutputIterator;
/**
* Generate range elements.
*
* @param first Forward iteartor of the first position.
* @param last Forward iterator of the last position.
* @param gen The generator function.
*/
export declare function generate<ForwardIterator extends Writeonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, gen: () => IPointer.ValueType<ForwardIterator>): void;
/**
* Generate *n* elements.
*
* @param first Forward iteartor of the first position.
* @param n Number of elements to generate.
* @param gen The generator function.
*
* @return Forward Iterator to the last position by advancing.
*/
export declare function generate_n<ForwardIterator extends Writeonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, n: number, gen: () => IPointer.ValueType<ForwardIterator>): ForwardIterator;
/**
* Test whether elements are unique in sorted range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @returns Whether unique or not.
*/
export declare function is_unique<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred?: BinaryPredicator<IPointer.ValueType<InputIterator>>): boolean;
/**
* Remove duplicated elements in sorted range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Input iterator to the last element not removed.
*/
export declare function unique<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred?: BinaryPredicator<IPointer.ValueType<InputIterator>>): InputIterator;
/**
* Copy elements in range without duplicates.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function unique_copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, pred?: BinaryPredicator<IPointer.ValueType<InputIterator>>): OutputIterator;
/**
* Remove specific value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The specific value to remove.
*
* @return Iterator tho the last element not removed.
*/
export declare function remove<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, val: IPointer.ValueType<InputIterator>): InputIterator;
/**
* Remove elements in range by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred An unary function predicates remove.
*
* @return Iterator tho the last element not removed.
*/
export declare function remove_if<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): InputIterator;
/**
* Copy range removing specific value.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param val The condition predicates remove.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function remove_copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, val: IPointer.ValueType<InputIterator>): OutputIterator;
/**
* Copy range removing elements by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param pred An unary function predicates remove.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function remove_copy_if<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): OutputIterator;
/**
* Replace specific value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param old_val Specific value to change
* @param new_val Specific value to be changed.
*/
export declare function replace<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, old_val: IPointer.ValueType<InputIterator>, new_val: IPointer.ValueType<InputIterator>): void;
/**
* Replace specific condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred An unary function predicates the change.
* @param new_val Specific value to be changed.
*/
export declare function replace_if<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>, new_val: IPointer.ValueType<InputIterator>): void;
/**
* Copy range replacing specific value.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param old_val Specific value to change
* @param new_val Specific value to be changed.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function replace_copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, old_val: IPointer.ValueType<InputIterator>, new_val: IPointer.ValueType<InputIterator>): OutputIterator;
/**
* Copy range replacing specfic condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param pred An unary function predicates the change.
* @param new_val Specific value to be changed.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function replace_copy_if<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, result: OutputIterator, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>, new_val: IPointer.ValueType<InputIterator>): OutputIterator;
/**
* Swap values of two iterators.
*
* @param x Forward iterator to swap its value.
* @param y Forward iterator to swap its value.
*/
export declare function iter_swap<ForwardIterator1 extends General<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator1>>, ForwardIterator2 extends General<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator2>>>(x: ForwardIterator1, y: ForwardIterator2): void;
/**
* Swap values of two ranges.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
*
* @return Forward Iterator of the last position of the 2nd range by advancing.
*/
export declare function swap_ranges<ForwardIterator1 extends General<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator1>>, ForwardIterator2 extends General<IForwardIterator<IPointer.ValueType<ForwardIterator1>, ForwardIterator2>>>(first1: ForwardIterator1, last1: ForwardIterator1, first2: ForwardIterator2): ForwardIterator2;
/**
* Reverse elements in range.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
*/
export declare function reverse<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator): void;
/**
* Copy reversed elements in range.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function reverse_copy<BidirectionalIterator extends Readonly<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<BidirectionalIterator>, OutputIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator, output: OutputIterator): OutputIterator;
export declare function shift_left<ForwardIterator extends General<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, n: number): ForwardIterator;
export declare function shift_right<ForwardIterator extends General<IBidirectionalIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, n: number): ForwardIterator;
/**
* Rotate elements in range.
*
* @param first Input iteartor of the first position.
* @param middle Input iteartor of the initial position of the right side.
* @param last Input iteartor of the last position.
*
* @return Input iterator of the final position in the left side; *middle*.
*/
export declare function rotate<InputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, middle: InputIterator, last: InputIterator): InputIterator;
/**
* Copy rotated elements in range.
*
* @param first Input iteartor of the first position.
* @param middle Input iteartor of the initial position of the right side.
* @param last Input iteartor of the last position.
* @param output Output iterator of the last position.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function rotate_copy<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, OutputIterator>>>(first: ForwardIterator, middle: ForwardIterator, last: ForwardIterator, output: OutputIterator): OutputIterator;
/**
* Shuffle elements in range.
*
* @param first Random access iteartor of the first position.
* @param last Random access iteartor of the last position.
*/
export declare function shuffle<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator): void;
export {};
+529
View File
@@ -0,0 +1,529 @@
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.shuffle = exports.rotate_copy = exports.rotate = exports.shift_right = exports.shift_left = exports.reverse_copy = exports.reverse = exports.swap_ranges = exports.iter_swap = exports.replace_copy_if = exports.replace_copy = exports.replace_if = exports.replace = exports.remove_copy_if = exports.remove_copy = exports.remove_if = exports.remove = exports.unique_copy = exports.unique = exports.is_unique = exports.generate_n = exports.generate = exports.transform = exports.fill_n = exports.fill = exports.copy_backward = exports.copy_if = exports.copy_n = exports.copy = void 0;
var comparators_1 = require("../functional/comparators");
var random_1 = require("./random");
var global_1 = require("../iterator/global");
/* =========================================================
MODIFIERS (MODIFYING SEQUENCE)
- FILL
- REMOVE
- REPLACE & SWAP
- RE-ARRANGEMENT
============================================================
FILL
--------------------------------------------------------- */
/**
* Copy elements in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
function copy(first, last, output) {
for (; !first.equals(last); first = first.next()) {
output.value = first.value;
output = output.next();
}
return output;
}
exports.copy = copy;
/**
* Copy *n* elements.
*
* @param first Input iteartor of the first position.
* @param n Number of elements to copy.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
function copy_n(first, n, output) {
for (var i = 0; i < n; ++i) {
output.value = first.value;
first = first.next();
output = output.next();
}
return output;
}
exports.copy_n = copy_n;
/**
* Copy specific elements by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param pred A function predicates the specific condition.
*
* @return Output Iterator of the last position by advancing.
*/
function copy_if(first, last, output, pred) {
for (; !first.equals(last); first = first.next()) {
if (!pred(first.value))
continue;
output.value = first.value;
output = output.next();
}
return output;
}
exports.copy_if = copy_if;
/**
* Copy elements reversely.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
function copy_backward(first, last, output) {
last = last.prev();
while (!last.equals(first)) {
last = last.prev();
output = output.prev();
output.value = last.value;
}
return output;
}
exports.copy_backward = copy_backward;
/**
* Fill range elements
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The value to fill.
*
* @return Output Iterator of the last position by advancing.
*/
function fill(first, last, val) {
for (; !first.equals(last); first = first.next())
first.value = val;
}
exports.fill = fill;
/**
* Fill *n* elements.
*
* @param first Input iteartor of the first position.
* @param n Number of elements to fill.
* @param val The value to fill.
*
* @return Output Iterator of the last position by advancing.
*/
function fill_n(first, n, val) {
for (var i = 0; i < n; ++i) {
first.value = val;
first = first.next();
}
return first;
}
exports.fill_n = fill_n;
function transform() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 4)
return _Unary_transform.apply(void 0, __spreadArray([], __read(args), false));
// args: #5
else
return _Binary_transform.apply(void 0, __spreadArray([], __read(args), false));
}
exports.transform = transform;
function _Unary_transform(first, last, result, op) {
for (; !first.equals(last); first = first.next()) {
result.value = op(first.value);
result = result.next();
}
return result;
}
function _Binary_transform(first1, last1, first2, result, binary_op) {
while (!first1.equals(last1)) {
result.value = binary_op(first1.value, first2.value);
first1 = first1.next();
first2 = first2.next();
result = result.next();
}
return result;
}
/**
* Generate range elements.
*
* @param first Forward iteartor of the first position.
* @param last Forward iterator of the last position.
* @param gen The generator function.
*/
function generate(first, last, gen) {
for (; !first.equals(last); first = first.next())
first.value = gen();
}
exports.generate = generate;
/**
* Generate *n* elements.
*
* @param first Forward iteartor of the first position.
* @param n Number of elements to generate.
* @param gen The generator function.
*
* @return Forward Iterator to the last position by advancing.
*/
function generate_n(first, n, gen) {
while (n-- > 0) {
first.value = gen();
first = first.next();
}
return first;
}
exports.generate_n = generate_n;
/* ---------------------------------------------------------
REMOVE
--------------------------------------------------------- */
/**
* Test whether elements are unique in sorted range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @returns Whether unique or not.
*/
function is_unique(first, last, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (first.equals(last))
return true;
var next = first.next();
for (; !next.equals(last); next = next.next()) {
if (pred(first.value, next.value) === true)
return false;
first = first.next();
}
return true;
}
exports.is_unique = is_unique;
/**
* Remove duplicated elements in sorted range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Input iterator to the last element not removed.
*/
function unique(first, last, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (first.equals(last))
return last;
var ret = first;
for (first = first.next(); !first.equals(last); first = first.next())
if (!pred(ret.value, first.value)) {
ret = ret.next();
ret.value = first.value;
}
return ret.next();
}
exports.unique = unique;
/**
* Copy elements in range without duplicates.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param pred A binary function predicates two arguments are equal. Default is {@link equal_to}.
*
* @return Output Iterator of the last position by advancing.
*/
function unique_copy(first, last, output, pred) {
if (pred === void 0) { pred = comparators_1.equal_to; }
if (first.equals(last))
return output;
output.value = first.value;
first = first.next();
for (; !first.equals(last); first = first.next())
if (!pred(first.value, output.value)) {
output = output.next();
output.value = first.value;
}
return output.next();
}
exports.unique_copy = unique_copy;
/**
* Remove specific value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param val The specific value to remove.
*
* @return Iterator tho the last element not removed.
*/
function remove(first, last, val) {
return remove_if(first, last, function (elem) { return (0, comparators_1.equal_to)(elem, val); });
}
exports.remove = remove;
/**
* Remove elements in range by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred An unary function predicates remove.
*
* @return Iterator tho the last element not removed.
*/
function remove_if(first, last, pred) {
var ret = first;
while (!first.equals(last)) {
if (!pred(first.value)) {
ret.value = first.value;
ret = ret.next();
}
first = first.next();
}
return ret;
}
exports.remove_if = remove_if;
/**
* Copy range removing specific value.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param val The condition predicates remove.
*
* @return Output Iterator of the last position by advancing.
*/
function remove_copy(first, last, output, val) {
return remove_copy_if(first, last, output, function (elem) { return (0, comparators_1.equal_to)(elem, val); });
}
exports.remove_copy = remove_copy;
/**
* Copy range removing elements by a condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the last position.
* @param pred An unary function predicates remove.
*
* @return Output Iterator of the last position by advancing.
*/
function remove_copy_if(first, last, output, pred) {
for (; !first.equals(last); first = first.next()) {
if (pred(first.value))
continue;
output.value = first.value;
output = output.next();
}
return output;
}
exports.remove_copy_if = remove_copy_if;
/* ---------------------------------------------------------
REPLACE & SWAP
--------------------------------------------------------- */
/**
* Replace specific value in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param old_val Specific value to change
* @param new_val Specific value to be changed.
*/
function replace(first, last, old_val, new_val) {
return replace_if(first, last, function (elem) { return (0, comparators_1.equal_to)(elem, old_val); }, new_val);
}
exports.replace = replace;
/**
* Replace specific condition in range.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param pred An unary function predicates the change.
* @param new_val Specific value to be changed.
*/
function replace_if(first, last, pred, new_val) {
for (var it = first; !it.equals(last); it = it.next())
if (pred(it.value) === true)
it.value = new_val;
}
exports.replace_if = replace_if;
/**
* Copy range replacing specific value.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param old_val Specific value to change
* @param new_val Specific value to be changed.
*
* @return Output Iterator of the last position by advancing.
*/
function replace_copy(first, last, output, old_val, new_val) {
return replace_copy_if(first, last, output, function (elem) { return (0, comparators_1.equal_to)(elem, old_val); }, new_val);
}
exports.replace_copy = replace_copy;
/**
* Copy range replacing specfic condition.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param pred An unary function predicates the change.
* @param new_val Specific value to be changed.
*
* @return Output Iterator of the last position by advancing.
*/
function replace_copy_if(first, last, result, pred, new_val) {
for (; !first.equals(last); first = first.next()) {
if (pred(first.value))
result.value = new_val;
else
result.value = first.value;
result = result.next();
}
return result;
}
exports.replace_copy_if = replace_copy_if;
/**
* Swap values of two iterators.
*
* @param x Forward iterator to swap its value.
* @param y Forward iterator to swap its value.
*/
function iter_swap(x, y) {
var _a;
_a = __read([y.value, x.value], 2), x.value = _a[0], y.value = _a[1];
}
exports.iter_swap = iter_swap;
/**
* Swap values of two ranges.
*
* @param first1 Forward iteartor of the first position of the 1st range.
* @param last1 Forward iterator of the last position of the 1st range.
* @param first2 Forward iterator of the first position of the 2nd range.
*
* @return Forward Iterator of the last position of the 2nd range by advancing.
*/
function swap_ranges(first1, last1, first2) {
for (; !first1.equals(last1); first1 = first1.next()) {
iter_swap(first1, first2);
first2 = first2.next();
}
return first2;
}
exports.swap_ranges = swap_ranges;
/* ---------------------------------------------------------
RE-ARRANGEMENT
--------------------------------------------------------- */
/**
* Reverse elements in range.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
*/
function reverse(first, last) {
// first !== last && first !== --last
while (first.equals(last) === false &&
first.equals((last = last.prev())) === false) {
iter_swap(first, last);
first = first.next();
}
}
exports.reverse = reverse;
/**
* Copy reversed elements in range.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param output Output iterator of the first position.
*
* @return Output Iterator of the last position by advancing.
*/
function reverse_copy(first, last, output) {
while (!last.equals(first)) {
last = last.prev();
output.value = last.value;
output = output.next();
}
return output;
}
exports.reverse_copy = reverse_copy;
function shift_left(first, last, n) {
var mid = (0, global_1.advance)(first, n);
return copy(mid, last, first);
}
exports.shift_left = shift_left;
function shift_right(first, last, n) {
var mid = (0, global_1.advance)(last, -n);
return copy_backward(first, mid, last);
}
exports.shift_right = shift_right;
/**
* Rotate elements in range.
*
* @param first Input iteartor of the first position.
* @param middle Input iteartor of the initial position of the right side.
* @param last Input iteartor of the last position.
*
* @return Input iterator of the final position in the left side; *middle*.
*/
function rotate(first, middle, last) {
while (!first.equals(middle) && !middle.equals(last)) {
iter_swap(first, middle);
first = first.next();
middle = middle.next();
}
return first;
}
exports.rotate = rotate;
/**
* Copy rotated elements in range.
*
* @param first Input iteartor of the first position.
* @param middle Input iteartor of the initial position of the right side.
* @param last Input iteartor of the last position.
* @param output Output iterator of the last position.
*
* @return Output Iterator of the last position by advancing.
*/
function rotate_copy(first, middle, last, output) {
output = copy(middle, last, output);
return copy(first, middle, output);
}
exports.rotate_copy = rotate_copy;
/**
* Shuffle elements in range.
*
* @param first Random access iteartor of the first position.
* @param last Random access iteartor of the last position.
*/
function shuffle(first, last) {
for (var it = first; !it.equals(last); it = it.next()) {
var rand_index = (0, random_1.randint)(first.index(), last.index() - 1);
if (it.index() !== rand_index)
iter_swap(it, first.advance(rand_index));
}
}
exports.shuffle = shuffle;
//# sourceMappingURL=modifiers.js.map
+63
View File
@@ -0,0 +1,63 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IBidirectionalIterator } from "../iterator/IBidirectionalIterator";
import { IPointer } from "../functional/IPointer";
import { General } from "../internal/functional/General";
import { Pair } from "../utility/Pair";
import { UnaryPredicator } from "../internal/functional/UnaryPredicator";
import { Writeonly } from "../internal/functional/Writeonly";
/**
* Test whether a range is partitioned.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Whether the range is partition or not.
*/
export declare function is_partitioned<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, pred: UnaryPredicator<IPointer.ValueType<ForwardIterator>>): boolean;
/**
* Get partition point.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
export declare function partition_point<ForwardIterator extends Readonly<IForwardIterator<IPointer.ValueType<ForwardIterator>, ForwardIterator>>>(first: ForwardIterator, last: ForwardIterator, pred: UnaryPredicator<IPointer.ValueType<ForwardIterator>>): ForwardIterator;
/**
* Partition a range into two sections.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
export declare function partition<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator, pred: UnaryPredicator<IPointer.ValueType<BidirectionalIterator>>): BidirectionalIterator;
/**
* Partition a range into two sections with stable ordering.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
export declare function stable_partition<BidirectionalIterator extends General<IBidirectionalIterator<IPointer.ValueType<BidirectionalIterator>, BidirectionalIterator>>>(first: BidirectionalIterator, last: BidirectionalIterator, pred: UnaryPredicator<IPointer.ValueType<BidirectionalIterator>>): BidirectionalIterator;
/**
* Partition a range into two outputs.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param output_true Output iterator to the first position for the first section.
* @param output_false Output iterator to the first position for the second section.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
export declare function partition_copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator1 extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator1>>, OutputIterator2 extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator2>>>(first: InputIterator, last: InputIterator, output_true: OutputIterator1, output_false: OutputIterator2, pred: UnaryPredicator<IPointer.ValueType<InputIterator>>): Pair<OutputIterator1, OutputIterator2>;
+116
View File
@@ -0,0 +1,116 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.partition_copy = exports.stable_partition = exports.partition = exports.partition_point = exports.is_partitioned = void 0;
var Pair_1 = require("../utility/Pair");
var modifiers_1 = require("./modifiers");
var global_1 = require("../iterator/global");
/* =========================================================
PARTITION
========================================================= */
/**
* Test whether a range is partitioned.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Whether the range is partition or not.
*/
function is_partitioned(first, last, pred) {
while (!first.equals(last) && pred(first.value))
first = first.next();
for (; !first.equals(last); first = first.next())
if (pred(first.value))
return false;
return true;
}
exports.is_partitioned = is_partitioned;
/**
* Get partition point.
*
* @param first Forward iterator of the first position.
* @param last Forward iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
function partition_point(first, last, pred) {
var n = (0, global_1.distance)(first, last);
while (n > 0) {
var step = Math.floor(n / 2);
var it = (0, global_1.advance)(first, step);
if (pred(it.value)) {
first = it.next();
n -= step + 1;
}
else
n = step;
}
return first;
}
exports.partition_point = partition_point;
/**
* Partition a range into two sections.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
function partition(first, last, pred) {
return stable_partition(first, last, pred);
}
exports.partition = partition;
/**
* Partition a range into two sections with stable ordering.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
function stable_partition(first, last, pred) {
while (!first.equals(last) && pred(first.value)) {
while (pred(first.value)) {
first = first.next();
if (first.equals(last))
return first;
}
do {
last = last.prev();
if (first.equals(last))
return first;
} while (!pred(last.value));
(0, modifiers_1.iter_swap)(first, last);
first = first.next();
}
return last;
}
exports.stable_partition = stable_partition;
/**
* Partition a range into two outputs.
*
* @param first Bidirectional iterator of the first position.
* @param last Bidirectional iterator of the last position.
* @param output_true Output iterator to the first position for the first section.
* @param output_false Output iterator to the first position for the second section.
* @param pred An unary function predicates partition. Returns `true`, if an element belongs to the first section, otherwise `false` which means the element belongs to the second section.
*
* @return Iterator to the first element of the second section.
*/
function partition_copy(first, last, output_true, output_false, pred) {
for (; !first.equals(last); first = first.next())
if (pred(first.value)) {
output_true.value = first.value;
output_true = output_true.next();
}
else {
output_false.value = first.value;
output_false = output_false.next();
}
return new Pair_1.Pair(output_true, output_false);
}
exports.partition_copy = partition_copy;
//# sourceMappingURL=partition.js.map
+27
View File
@@ -0,0 +1,27 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPointer } from "../functional/IPointer";
import { Writeonly } from "../internal/functional/Writeonly";
/**
* Generate random integer.
*
* @param x Minimum value.
* @param y Maximum value.
*
* @return A random integer between [x, y].
*/
export declare function randint(x: number, y: number): number;
/**
* Pick sample elements up.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param n Number of elements to pick up.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function sample<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output: OutputIterator, n: number): OutputIterator;
+83
View File
@@ -0,0 +1,83 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sample = exports.randint = void 0;
var Vector_1 = require("../container/Vector");
var global_1 = require("../iterator/global");
var sorting_1 = require("./sorting");
/**
* Generate random integer.
*
* @param x Minimum value.
* @param y Maximum value.
*
* @return A random integer between [x, y].
*/
function randint(x, y) {
var rand = Math.random() * (y - x + 1);
return Math.floor(rand) + x;
}
exports.randint = randint;
/**
* Pick sample elements up.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output Output iterator of the first position.
* @param n Number of elements to pick up.
*
* @return Output Iterator of the last position by advancing.
*/
function sample(first, last, output, n) {
var e_1, _a;
// GENERATE REMAINDERS
var step = (0, global_1.distance)(first, last);
var remainders = [];
for (var i = 0; i < step; ++i)
remainders.push(i);
//----
// CONSTRUCT INDEXES
//----
var advances = new Vector_1.Vector();
n = Math.min(n, step);
// PICK SAMPLE INDEXES
for (var i = 0; i < n; ++i) {
var idx = randint(0, remainders.length - 1);
advances.push(remainders.splice(idx, 1)[0]);
}
(0, sorting_1.sort)(advances.begin(), advances.end());
// CHANGE INDEXES TO ADVANCES
for (var i = n - 1; i >= 1; --i)
advances.set(i, advances.at(i) - advances.at(i - 1));
try {
//----
// FILL SAMPLES
//----
for (var advances_1 = __values(advances), advances_1_1 = advances_1.next(); !advances_1_1.done; advances_1_1 = advances_1.next()) {
var adv = advances_1_1.value;
first = (0, global_1.advance)(first, adv);
output.value = first.value;
output = output.next();
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (advances_1_1 && !advances_1_1.done && (_a = advances_1.return)) _a.call(advances_1);
}
finally { if (e_1) throw e_1.error; }
}
return output;
}
exports.sample = sample;
//# sourceMappingURL=random.js.map
+75
View File
@@ -0,0 +1,75 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IRandomAccessIterator } from "../iterator/IRandomAccessIterator";
import { IPointer } from "../functional/IPointer";
import { General } from "../internal/functional/General";
import { Comparator } from "../internal/functional/Comparator";
/**
* Sort elements in range.
*
* @param first Random access iterator of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function sort<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Sort elements in range stably.
*
* @param first Random access iterator of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function stable_sort<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Sort elements in range partially.
*
* @param first Random access iterator of the first position.
* @param middle Random access iterator of the middle position between [first, last). Elements only in [first, middle) are fully sorted.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function partial_sort<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Copy elements in range with partial sort.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output_first Output iterator of the first position.
* @param output_last Output iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
export declare function partial_sort_copy<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>, OutputIterator extends General<IForwardIterator<IPointer.ValueType<InputIterator>, OutputIterator>>>(first: InputIterator, last: InputIterator, output_first: OutputIterator, output_last: OutputIterator, comp?: Comparator<IPointer.ValueType<InputIterator>>): OutputIterator;
/**
* Rearrange for the n'th element.
*
* @param first Random access iterator of the first position.
* @param nth Random access iterator the n'th position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
export declare function nth_element<RandomAccessIterator extends General<IRandomAccessIterator<IPointer.ValueType<RandomAccessIterator>, RandomAccessIterator>>>(first: RandomAccessIterator, nth: RandomAccessIterator, last: RandomAccessIterator, comp?: Comparator<IPointer.ValueType<RandomAccessIterator>>): void;
/**
* Test whether a range is sorted.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether sorted or not.
*/
export declare function is_sorted<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, comp?: Comparator<IPointer.ValueType<InputIterator>>): boolean;
/**
* Find the first unsorted element in range.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element who violates the order.
*/
export declare function is_sorted_until<InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>>(first: InputIterator, last: InputIterator, comp?: Comparator<IPointer.ValueType<InputIterator>>): InputIterator;
+167
View File
@@ -0,0 +1,167 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.is_sorted_until = exports.is_sorted = exports.nth_element = exports.partial_sort_copy = exports.partial_sort = exports.stable_sort = exports.sort = void 0;
var Vector_1 = require("../container/Vector");
var comparators_1 = require("../functional/comparators");
var modifiers_1 = require("./modifiers");
var global_1 = require("../iterator/global");
/* =========================================================
SORTINGS
- SORT
- INSPECTOR
- BACKGROUND
============================================================
SORT
--------------------------------------------------------- */
/**
* Sort elements in range.
*
* @param first Random access iterator of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function sort(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var length = last.index() - first.index();
if (length <= 0)
return;
var pivot_it = first.advance(Math.floor(length / 2));
var pivot = pivot_it.value;
if (pivot_it.index() !== first.index())
(0, modifiers_1.iter_swap)(first, pivot_it);
var i = 1;
for (var j = 1; j < length; ++j) {
var j_it = first.advance(j);
if (comp(j_it.value, pivot)) {
(0, modifiers_1.iter_swap)(j_it, first.advance(i));
++i;
}
}
(0, modifiers_1.iter_swap)(first, first.advance(i - 1));
sort(first, first.advance(i - 1), comp);
sort(first.advance(i), last, comp);
}
exports.sort = sort;
/**
* Sort elements in range stably.
*
* @param first Random access iterator of the first position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function stable_sort(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var ramda = function (x, y) {
return comp(x, y) && !comp(y, x);
};
sort(first, last, ramda);
}
exports.stable_sort = stable_sort;
/**
* Sort elements in range partially.
*
* @param first Random access iterator of the first position.
* @param middle Random access iterator of the middle position between [first, last). Elements only in [first, middle) are fully sorted.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function partial_sort(first, middle, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
for (var i = first; !i.equals(middle); i = i.next()) {
var min = i;
for (var j = i.next(); !j.equals(last); j = j.next())
if (comp(j.value, min.value))
min = j;
if (!i.equals(min))
(0, modifiers_1.iter_swap)(i, min);
}
}
exports.partial_sort = partial_sort;
/**
* Copy elements in range with partial sort.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
* @param output_first Output iterator of the first position.
* @param output_last Output iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Output Iterator of the last position by advancing.
*/
function partial_sort_copy(first, last, output_first, output_last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var input_size = (0, global_1.distance)(first, last);
var result_size = (0, global_1.distance)(output_first, output_last);
var vector = new Vector_1.Vector(first, last);
sort(vector.begin(), vector.end(), comp);
if (input_size > result_size)
output_first = (0, modifiers_1.copy)(vector.begin(), vector.begin().advance(result_size), output_first);
else
output_first = (0, modifiers_1.copy)(vector.begin(), vector.end(), output_first);
return output_first;
}
exports.partial_sort_copy = partial_sort_copy;
/**
* Rearrange for the n'th element.
*
* @param first Random access iterator of the first position.
* @param nth Random access iterator the n'th position.
* @param last Random access iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*/
function nth_element(first, nth, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
var n = (0, global_1.distance)(first, nth);
for (var i = first; !i.equals(last); i = i.next()) {
var count = 0;
for (var j = first; !j.equals(last); j = j.next())
if (i.equals(j))
continue;
else if (comp(i.value, j.value) && ++count > n)
break;
if (count === n) {
(0, modifiers_1.iter_swap)(nth, i);
return;
}
}
}
exports.nth_element = nth_element;
/* ---------------------------------------------------------
INSPECTOR
--------------------------------------------------------- */
/**
* Test whether a range is sorted.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Whether sorted or not.
*/
function is_sorted(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
return is_sorted_until(first, last, comp).equals(last);
}
exports.is_sorted = is_sorted;
/**
* Find the first unsorted element in range.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Default is {@link less}.
*
* @return Iterator to the first element who violates the order.
*/
function is_sorted_until(first, last, comp) {
if (comp === void 0) { comp = comparators_1.less; }
if (first.equals(last))
return last;
for (var next = first.next(); !next.equals(last); next = next.next())
if (comp(next.value, first.value))
return next;
else
first = first.next();
return last;
}
exports.is_sorted_until = is_sorted_until;
//# sourceMappingURL=sorting.js.map
+75
View File
@@ -0,0 +1,75 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IContainer } from "./IContainer";
import { IForwardIterator } from "../../iterator/IForwardIterator";
/**
* Basic container.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link Container}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class Container<T extends PElem, SourceT extends Container<T, SourceT, IteratorT, ReverseT, PElem>, IteratorT extends IContainer.Iterator<T, SourceT, IteratorT, ReverseT, PElem>, ReverseT extends IContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, PElem>, PElem = T> implements IContainer<T, SourceT, IteratorT, ReverseT, PElem> {
/**
* @inheritDoc
*/
abstract assign<InputIterator extends Readonly<IForwardIterator<PElem, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
abstract clear(): void;
/**
* @inheritDoc
*/
abstract size(): number;
/**
* @inheritDoc
*/
empty(): boolean;
/**
* @inheritDoc
*/
abstract begin(): IteratorT;
/**
* @inheritDoc
*/
abstract end(): IteratorT;
/**
* @inheritDoc
*/
rbegin(): ReverseT;
/**
* @inheritDoc
*/
rend(): ReverseT;
/**
* @inheritDoc
*/
[Symbol.iterator](): IterableIterator<T>;
/**
* @inheritDoc
*/
abstract push(...items: PElem[]): number;
/**
* @inheritDoc
*/
abstract erase(pos: IteratorT): IteratorT;
/**
* @inheritDoc
*/
abstract erase(first: IteratorT, last: IteratorT): IteratorT;
/**
* @inheritDoc
*/
abstract swap(obj: SourceT): void;
/**
* @inheritDoc
*/
toJSON(): Array<T>;
}
+78
View File
@@ -0,0 +1,78 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Container = void 0;
var ForOfAdaptor_1 = require("../../internal/iterator/disposable/ForOfAdaptor");
/**
* Basic container.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link Container}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Container = /** @class */ (function () {
function Container() {
}
/**
* @inheritDoc
*/
Container.prototype.empty = function () {
return this.size() === 0;
};
/**
* @inheritDoc
*/
Container.prototype.rbegin = function () {
return this.end().reverse();
};
/**
* @inheritDoc
*/
Container.prototype.rend = function () {
return this.begin().reverse();
};
/**
* @inheritDoc
*/
Container.prototype[Symbol.iterator] = function () {
return new ForOfAdaptor_1.ForOfAdaptor(this.begin(), this.end());
};
/**
* @inheritDoc
*/
Container.prototype.toJSON = function () {
var e_1, _a;
var ret = [];
try {
for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
var elem = _c.value;
ret.push(elem);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return ret;
};
return Container;
}());
exports.Container = Container;
//# sourceMappingURL=Container.js.map
+54
View File
@@ -0,0 +1,54 @@
/**
* @packageDocumentation
* @module std.base
*/
import { ILinearContainer } from "./ILinearContainer";
import { IRandomAccessIterator } from "../../iterator/IRandomAccessIterator";
/**
* Common interface for array containers.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link IArrayContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IArrayContainer<T extends PElem, SourceT extends IArrayContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends IArrayContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends IArrayContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, PElem = T> extends ILinearContainer<T, SourceT, IteratorT, ReverseT, PElem> {
/**
* Get iterator at specific position.
*
* @param index Specific position.
* @return The iterator at the *index*.
*/
nth(index: number): IteratorT;
/**
* Get element at specific position.
*
* @param index Specific position.
* @return The element at the *index*.
*/
at(index: number): T;
/**
* Change element at specific position.
*
* @param index Specific position.
* @param val The new value to change.
*/
set(index: number, val: T): void;
}
export declare namespace IArrayContainer {
/**
* Iterator of {@link IArrayContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<T extends ElemT, SourceT extends IArrayContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends IArrayContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends IArrayContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = ILinearContainer.Iterator<T, SourceT, IteratorT, ReverseT, ElemT> & IRandomAccessIterator<T, IteratorT>;
/**
* Reverse iterator of {@link IArrayContainer}
*
* @author Jeongho Nam - https://github.com/samchon
*/
type ReverseIterator<T extends ElemT, SourceT extends IArrayContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends IArrayContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends IArrayContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = ILinearContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, ElemT> & IRandomAccessIterator<T, ReverseT>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IArrayContainer.js.map
+123
View File
@@ -0,0 +1,123 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IBidirectionalContainer } from "../../ranges/container/IBidirectionalContainer";
import { IEmpty } from "../../internal/container/partial/IEmpty";
import { ISize } from "../../internal/container/partial/ISize";
import { IPush } from "../../internal/container/partial/IPush";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { IReverseIterator } from "../../iterator/IReverseIterator";
import { IReversableIterator } from "../../iterator/IReversableIterator";
/**
* Common interface for containers.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link IContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IContainer<T extends PElem, SourceT extends IContainer<T, SourceT, IteratorT, ReverseT, PElem>, IteratorT extends IContainer.Iterator<T, SourceT, IteratorT, ReverseT, PElem>, ReverseT extends IContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, PElem>, PElem = T> extends IBidirectionalContainer<IContainer.Iterator<T, SourceT, IteratorT, ReverseT, PElem>, ReverseT>, Iterable<T>, IEmpty, ISize, IPush<PElem> {
/**
* Range Assigner.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
*/
assign<InputIterator extends Readonly<IForwardIterator<PElem, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
size(): number;
/**
* @inheritDoc
*/
empty(): boolean;
/**
* @inheritDoc
*/
begin(): IteratorT;
/**
* @inheritDoc
*/
end(): IteratorT;
/**
* @inheritDoc
*/
rbegin(): ReverseT;
/**
* @inheritDoc
*/
rend(): ReverseT;
/**
* @inheritDoc
*/
[Symbol.iterator](): IterableIterator<T>;
push(...items: PElem[]): number;
/**
* Erase an element.
*
* @param pos Position to erase.
* @return Iterator following the *pos*, strained by the erasing.
*/
erase(pos: IteratorT): IteratorT;
/**
* Erase elements in range.
*
* @param first Range of the first position to erase.
* @param last Rangee of the last position to erase.
* @return Iterator following the last removed element, strained by the erasing.
*/
erase(first: IteratorT, last: IteratorT): IteratorT;
/**
* Swap elements.
*
* @param obj Target container to swap.
*/
swap(obj: SourceT): void;
/**
* Native function for `JSON.stringify()`.
*
* @return An array containing children elements.
*/
toJSON(): Array<T>;
}
export declare namespace IContainer {
/**
* Iterator of {@link IContainer}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
interface Iterator<T extends Elem, SourceT extends IContainer<T, SourceT, IteratorT, ReverseIteratorT, Elem>, IteratorT extends Iterator<T, SourceT, IteratorT, ReverseIteratorT, Elem>, ReverseIteratorT extends ReverseIterator<T, SourceT, IteratorT, ReverseIteratorT, Elem>, Elem = T> extends Readonly<IReversableIterator<T, IteratorT, ReverseIteratorT>> {
/**
* Get source container.
*
* @return The source container.
*/
source(): SourceT;
/**
* @inheritDoc
*/
reverse(): ReverseIteratorT;
}
/**
* Reverse iterator of {@link IContainer}
*
* @author Jeongho Nam - https://github.com/samchon
*/
interface ReverseIterator<T extends Elem, Source extends IContainer<T, Source, IteratorT, ReverseT, Elem>, IteratorT extends Iterator<T, Source, IteratorT, ReverseT, Elem>, ReverseT extends ReverseIterator<T, Source, IteratorT, ReverseT, Elem>, Elem = T> extends Readonly<IReverseIterator<T, IteratorT, ReverseT>> {
/**
* Get source container.
*
* @return The source container.
*/
source(): Source;
}
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IContainer.js.map
+34
View File
@@ -0,0 +1,34 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IContainer } from "./IContainer";
import { IDeque } from "../../internal/container/partial/IDeque";
import { ILinearContainer } from "./ILinearContainer";
/**
* Common interface for deque containers.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link IDequeContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IDequeContainer<T extends PElem, SourceT extends IDequeContainer<T, SourceT, IteratorT, ReverseT, PElem>, IteratorT extends IContainer.Iterator<T, SourceT, IteratorT, ReverseT, PElem>, ReverseT extends IContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, PElem>, PElem = T> extends IDeque<T>, ILinearContainer<T, SourceT, IteratorT, ReverseT, PElem> {
}
export declare namespace IDequeContainer {
/**
* Iterator of {@link IDequeContainer}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
type Iterator<T extends ElemT, SourceT extends IDequeContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends IDequeContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends IDequeContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = ILinearContainer.Iterator<T, SourceT, IteratorT, ReverseT, ElemT>;
/**
* Reverse iterator of {@link IDequeContainer}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
type ReverseIterator<T extends ElemT, SourceT extends IDequeContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends IDequeContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends IDequeContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = ILinearContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, ElemT>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IDequeContainer.js.map
+57
View File
@@ -0,0 +1,57 @@
/**
* @packageDocumentation
* @module std.base
*/
import { MapContainer } from "./MapContainer";
import { IHashContainer } from "../../internal/container/associative/IHashContainer";
import { IPair } from "../../utility/IPair";
import { Entry } from "../../utility/Entry";
import { MapElementList } from "../../internal/container/associative/MapElementList";
/**
* Common interface for hash maps.
*
* @template Key Key type
* @template T Mapped type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link IHashMap}
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IHashMap<Key, T, Unique extends boolean, Source extends IHashMap<Key, T, Unique, Source>> extends MapContainer<Key, T, Unique, Source, IHashMap.Iterator<Key, T, Unique, Source>, IHashMap.ReverseIterator<Key, T, Unique, Source>>, IHashContainer<Key, Entry<Key, T>, Source, IHashMap.Iterator<Key, T, Unique, Source>, IHashMap.ReverseIterator<Key, T, Unique, Source>, IPair<Key, T>> {
/**
* @inheritDoc
*/
begin(): IHashMap.Iterator<Key, T, Unique, Source>;
/**
* Iterator to the first element in a specific bucket.
*
* @param index Index number of the specific bucket.
* @return Iterator from the specific bucket.
*/
begin(index: number): IHashMap.Iterator<Key, T, Unique, Source>;
/**
* @inheritDoc
*/
end(): IHashMap.Iterator<Key, T, Unique, Source>;
/**
* Iterator to the end in a specific bucket.
*
* @param index Index number of the specific bucket.
* @return Iterator from the specific bucket.
*/
end(index: number): IHashMap.Iterator<Key, T, Unique, Source>;
}
export declare namespace IHashMap {
/**
* Iterator of {@link IHashMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, T, Unique extends boolean, Source extends IHashMap<Key, T, Unique, Source>> = MapElementList.Iterator<Key, T, Unique, Source>;
/**
* Reverse iterator of {@link IHashMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, T, Unique extends boolean, Source extends IHashMap<Key, T, Unique, Source>> = MapElementList.ReverseIterator<Key, T, Unique, Source>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IHashMap.js.map
+54
View File
@@ -0,0 +1,54 @@
/**
* @packageDocumentation
* @module std.base
*/
import { SetContainer } from "./SetContainer";
import { IHashContainer } from "../../internal/container/associative/IHashContainer";
import { SetElementList } from "../../internal/container/associative/SetElementList";
/**
* Common interface for hash sets.
*
* @template Key Key type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link IHashSet}
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface IHashSet<Key, Unique extends boolean, Source extends IHashSet<Key, Unique, Source>> extends SetContainer<Key, Unique, Source, IHashSet.Iterator<Key, Unique, Source>, IHashSet.ReverseIterator<Key, Unique, Source>>, IHashContainer<Key, Key, Source, IHashSet.Iterator<Key, Unique, Source>, IHashSet.ReverseIterator<Key, Unique, Source>, Key> {
/**
* @inheritDoc
*/
begin(): IHashSet.Iterator<Key, Unique, Source>;
/**
* Iterator to the first element in a specific bucket.
*
* @param index Index number of the specific bucket.
* @return Iterator from the specific bucket.
*/
begin(index: number): IHashSet.Iterator<Key, Unique, Source>;
/**
* @inheritDoc
*/
end(): IHashSet.Iterator<Key, Unique, Source>;
/**
* Iterator to the end in a specific bucket.
*
* @param index Index number of the specific bucket.
* @return Iterator from the specific bucket.
*/
end(index: number): IHashSet.Iterator<Key, Unique, Source>;
}
export declare namespace IHashSet {
/**
* Iterator of {@link IHashSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, Unique extends boolean, Source extends IHashSet<Key, Unique, Source>> = SetElementList.Iterator<Key, Unique, Source>;
/**
* Reverse iterator of {@link IHashSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, Unique extends boolean, Source extends IHashSet<Key, Unique, Source>> = SetElementList.ReverseIterator<Key, Unique, Source>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IHashSet.js.map
+102
View File
@@ -0,0 +1,102 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IContainer } from "./IContainer";
import { ILinearContainerBase } from "../../internal/container/linear/ILinearContainerBase";
import { IFront } from "../../internal/container/partial/IFront";
import { IPushBack } from "../../internal/container/partial/IPushBack";
import { IForwardIterator } from "../../iterator/IForwardIterator";
/**
* Common interface for linear containers.
*
* @template T Stored elements' type
* @template SourceT Derived type extending this {@link ILinearContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
* @template PElem Parent type of *T*, used for inserting elements through {@link assign} and {@link insert}.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ILinearContainer<T extends PElem, SourceT extends ILinearContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends ILinearContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends ILinearContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, PElem = T> extends ILinearContainerBase<T, SourceT, IteratorT, ReverseT, PElem>, IFront<T>, IPushBack<T> {
/**
* Fill Assigner.
*
* @param n Initial size.
* @param val Value to fill.
*/
assign(n: number, val: T): void;
/**
* Range Assigner.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
*/
assign<InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* Resize this {@link Vector} forcibly.
*
* @param n New container size.
*/
resize(n: number): void;
/**
* Get the last element.
*
* @return The last element.
*/
back(): T;
/**
* Change the last element.
*
* @param val The value to change.
*/
back(val: T): void;
/**
* @inheritDoc
*/
push_back(val: T): void;
/**
* Erase the last element.
*/
pop_back(): void;
/**
* Insert a single element.
*
* @param pos Position to insert.
* @param val Value to insert.
* @return An iterator to the newly inserted element.
*/
insert(pos: IteratorT, val: T): IteratorT;
/**
* Insert repeated elements.
*
* @param pos Position to insert.
* @param n Number of elements to insert.
* @param val Value to insert repeatedly.
* @return An iterator to the first of the newly inserted elements.
*/
insert(pos: IteratorT, n: number, val: T): IteratorT;
/**
* Insert range elements.
*
* @param pos Position to insert.
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
* @return An iterator to the first of the newly inserted elements.
*/
insert<InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(pos: IteratorT, first: InputIterator, last: InputIterator): IteratorT;
}
export declare namespace ILinearContainer {
/**
* Iterator of {@link ILinearContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<T extends ElemT, SourceT extends ILinearContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends ILinearContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends ILinearContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = IContainer.Iterator<T, SourceT, IteratorT, ReverseT, ElemT>;
/**
* Reverse iterator of {@link ILinearContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<T extends ElemT, SourceT extends ILinearContainer<T, SourceT, IteratorT, ReverseT, T>, IteratorT extends ILinearContainer.Iterator<T, SourceT, IteratorT, ReverseT, T>, ReverseT extends ILinearContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, T>, ElemT = T> = IContainer.ReverseIterator<T, SourceT, IteratorT, ReverseT, ElemT>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ILinearContainer.js.map
+36
View File
@@ -0,0 +1,36 @@
/**
* @packageDocumentation
* @module std.base
*/
import { MapContainer } from "./MapContainer";
import { ITreeContainer } from "../../internal/container/associative/ITreeContainer";
import { IPair } from "../../utility/IPair";
import { Entry } from "../../utility/Entry";
/**
* Common interface for tree maps.
*
* @template Key Key type
* @template T Mapped type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link ITreeMap}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ITreeMap<Key, T, Unique extends boolean, Source extends ITreeMap<Key, T, Unique, Source, IteratorT, ReverseT>, IteratorT extends ITreeMap.Iterator<Key, T, Unique, Source, IteratorT, ReverseT>, ReverseT extends ITreeMap.ReverseIterator<Key, T, Unique, Source, IteratorT, ReverseT>> extends MapContainer<Key, T, Unique, Source, IteratorT, ReverseT>, ITreeContainer<Key, Entry<Key, T>, Source, IteratorT, ReverseT, IPair<Key, T>> {
}
export declare namespace ITreeMap {
/**
* Iterator of {@link ITreeMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, T, Unique extends boolean, Source extends ITreeMap<Key, T, Unique, Source, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, Unique, Source, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, Unique, Source, IteratorT, ReverseT>> = MapContainer.Iterator<Key, T, Unique, Source, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link ITreeMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, T, Unique extends boolean, Source extends ITreeMap<Key, T, Unique, Source, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, Unique, Source, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, Unique, Source, IteratorT, ReverseT>> = MapContainer.ReverseIterator<Key, T, Unique, Source, IteratorT, ReverseT>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ITreeMap.js.map
+33
View File
@@ -0,0 +1,33 @@
/**
* @packageDocumentation
* @module std.base
*/
import { SetContainer } from "./SetContainer";
import { ITreeContainer } from "../../internal/container/associative/ITreeContainer";
/**
* Common interface for tree sets.
*
* @template Key Key type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link ITreeSet}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ITreeSet<Key, Unique extends boolean, Source extends ITreeSet<Key, Unique, Source, IteratorT, ReverseT>, IteratorT extends ITreeSet.Iterator<Key, Unique, Source, IteratorT, ReverseT>, ReverseT extends ITreeSet.ReverseIterator<Key, Unique, Source, IteratorT, ReverseT>> extends SetContainer<Key, Unique, Source, IteratorT, ReverseT>, ITreeContainer<Key, Key, Source, IteratorT, ReverseT, Key> {
}
export declare namespace ITreeSet {
/**
* Iterator of {@link ITreeSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, Unique extends boolean, SourceT extends ITreeSet<Key, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>> = SetContainer.Iterator<Key, Unique, SourceT, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link ITreeSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, Unique extends boolean, SourceT extends ITreeSet<Key, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>> = SetContainer.ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ITreeSet.js.map
+131
View File
@@ -0,0 +1,131 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IAssociativeContainer } from "../../internal/container/associative/IAssociativeContainer";
import { IContainer } from "./IContainer";
import { Container } from "./Container";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { ILinearContainerBase } from "../../internal/container/linear/ILinearContainerBase";
import { IPair } from "../../utility/IPair";
import { Entry } from "../../utility/Entry";
import { Pair } from "../../utility/Pair";
/**
* Basic map container.
*
* @template Key Key type
* @template T Mapped type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link MapContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class MapContainer<Key, T, Unique extends boolean, Source extends MapContainer<Key, T, Unique, Source, IteratorT, ReverseT>, IteratorT extends MapContainer.Iterator<Key, T, Unique, Source, IteratorT, ReverseT>, ReverseT extends MapContainer.ReverseIterator<Key, T, Unique, Source, IteratorT, ReverseT>> extends Container<Entry<Key, T>, Source, IteratorT, ReverseT, IPair<Key, T>> implements IAssociativeContainer<Key, Entry<Key, T>, Source, IteratorT, ReverseT, IPair<Key, T>> {
protected data_: ILinearContainerBase<Entry<Key, T>, Source, IteratorT, ReverseT>;
/**
* Default Constructor.
*/
protected constructor(factory: (thisArg: Source) => ILinearContainerBase<Entry<Key, T>, Source, IteratorT, ReverseT>);
/**
* @inheritDoc
*/
assign<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
abstract find(key: Key): IteratorT;
/**
* @inheritDoc
*/
begin(): IteratorT;
/**
* @inheritDoc
*/
end(): IteratorT;
/**
* @inheritDoc
*/
has(key: Key): boolean;
/**
* @inheritDoc
*/
abstract count(key: Key): number;
/**
* @inheritDoc
*/
size(): number;
/**
* @inheritDoc
*/
push(...items: IPair<Key, T>[]): number;
abstract emplace(key: Key, val: T): MapContainer.InsertRet<Key, T, Unique, Source, IteratorT, ReverseT>;
abstract emplace_hint(hint: IteratorT, key: Key, val: T): IteratorT;
insert(pair: IPair<Key, T>): MapContainer.InsertRet<Key, T, Unique, Source, IteratorT, ReverseT>;
insert(hint: IteratorT, pair: IPair<Key, T>): IteratorT;
insert<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected abstract _Insert_by_range<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
erase(key: Key): number;
/**
* @inheritDoc
*/
erase(it: IteratorT): IteratorT;
/**
* @inheritDoc
*/
erase(begin: IteratorT, end: IteratorT): IteratorT;
protected abstract _Erase_by_key(key: Key): number;
protected _Erase_by_range(first: IteratorT, last?: IteratorT): IteratorT;
/**
* @inheritDoc
*/
abstract swap(obj: Source): void;
/**
* Merge two containers.
*
* @param source Source container to transfer.
*/
abstract merge(source: Source): void;
protected abstract _Handle_insert(first: IteratorT, last: IteratorT): void;
protected abstract _Handle_erase(first: IteratorT, last: IteratorT): void;
}
/**
*
*/
export declare namespace MapContainer {
/**
* Return type of {@link MapContainer.insert}
*/
export type InsertRet<Key, T, Unique extends boolean, SourceT extends MapContainer<Key, T, Unique, SourceT, IteratorT, Reverse>, IteratorT extends Iterator<Key, T, Unique, SourceT, IteratorT, Reverse>, Reverse extends ReverseIterator<Key, T, Unique, SourceT, IteratorT, Reverse>> = Unique extends true ? Pair<IteratorT, boolean> : IteratorT;
/**
* Iterator of {@link MapContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
export type Iterator<Key, T, Unique extends boolean, SourceT extends MapContainer<Key, T, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, Unique, SourceT, IteratorT, ReverseT>> = IteratorBase<Key, T> & Readonly<IContainer.Iterator<Entry<Key, T>, SourceT, IteratorT, ReverseT, IPair<Key, T>>>;
/**
* Reverse iterator of {@link MapContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
export type ReverseIterator<Key, T, Unique extends boolean, SourceT extends MapContainer<Key, T, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, Unique, SourceT, IteratorT, ReverseT>> = IteratorBase<Key, T> & Readonly<IContainer.ReverseIterator<Entry<Key, T>, SourceT, IteratorT, ReverseT, IPair<Key, T>>>;
interface IteratorBase<Key, T> {
/**
* The first, key element.
*/
readonly first: Key;
/**
* The second, stored element.
*/
second: T;
}
export {};
}
+150
View File
@@ -0,0 +1,150 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapContainer = void 0;
var Container_1 = require("./Container");
var NativeArrayIterator_1 = require("../../internal/iterator/disposable/NativeArrayIterator");
/**
* Basic map container.
*
* @template Key Key type
* @template T Mapped type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link MapContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var MapContainer = /** @class */ (function (_super) {
__extends(MapContainer, _super);
/* ---------------------------------------------------------
CONSTURCTORS
--------------------------------------------------------- */
/**
* Default Constructor.
*/
function MapContainer(factory) {
var _this = _super.call(this) || this;
_this.data_ = factory(_this);
return _this;
}
/**
* @inheritDoc
*/
MapContainer.prototype.assign = function (first, last) {
// INSERT
this.clear();
this.insert(first, last);
};
/**
* @inheritDoc
*/
MapContainer.prototype.clear = function () {
// TO BE ABSTRACT
this.data_.clear();
};
/**
* @inheritDoc
*/
MapContainer.prototype.begin = function () {
return this.data_.begin();
};
/**
* @inheritDoc
*/
MapContainer.prototype.end = function () {
return this.data_.end();
};
/* ---------------------------------------------------------
ELEMENTS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
MapContainer.prototype.has = function (key) {
return !this.find(key).equals(this.end());
};
/**
* @inheritDoc
*/
MapContainer.prototype.size = function () {
return this.data_.size();
};
/* =========================================================
ELEMENTS I/O
- INSERT
- ERASE
- UTILITY
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
/**
* @inheritDoc
*/
MapContainer.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
// INSERT BY RANGE
var first = new NativeArrayIterator_1.NativeArrayIterator(items, 0);
var last = new NativeArrayIterator_1.NativeArrayIterator(items, items.length);
this.insert(first, last);
// RETURN SIZE
return this.size();
};
MapContainer.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1)
return this.emplace(args[0].first, args[0].second);
else if (args[0].next instanceof Function &&
args[1].next instanceof Function)
return this._Insert_by_range(args[0], args[1]);
else
return this.emplace_hint(args[0], args[1].first, args[1].second);
};
MapContainer.prototype.erase = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1 &&
(args[0] instanceof this.end().constructor === false ||
args[0].source() !== this))
return this._Erase_by_key(args[0]);
else if (args.length === 1)
return this._Erase_by_range(args[0]);
else
return this._Erase_by_range(args[0], args[1]);
};
MapContainer.prototype._Erase_by_range = function (first, last) {
if (last === void 0) { last = first.next(); }
// ERASE
var it = this.data_.erase(first, last);
// POST-PROCESS
this._Handle_erase(first, last);
return it;
};
return MapContainer;
}(Container_1.Container));
exports.MapContainer = MapContainer;
//# sourceMappingURL=MapContainer.js.map
+82
View File
@@ -0,0 +1,82 @@
/**
* @packageDocumentation
* @module std.base
*/
import { MapContainer } from "./MapContainer";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { IPair } from "../../utility/IPair";
/**
* Basic map container allowing duplicated keys.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link MultiMap}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class MultiMap<Key, T, Source extends MultiMap<Key, T, Source, Iterator, Reverse>, Iterator extends MultiMap.Iterator<Key, T, Source, Iterator, Reverse>, Reverse extends MultiMap.ReverseIterator<Key, T, Source, Iterator, Reverse>> extends MapContainer<Key, T, false, Source, Iterator, Reverse> {
/**
* Construct and insert an element.
*
* @param key Key to be mapped.
* @param value Value to emplace.
* @return An iterator to the newly inserted element.
*/
abstract emplace(key: Key, value: T): Iterator;
/**
* Construct and insert element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param key Key of the new element.
* @param val Value of the new element.
* @return An iterator to the newly inserted element.
*/
abstract emplace_hint(hint: Iterator, key: Key, val: T): Iterator;
/**
* Insert an element.
*
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element.
*/
insert(pair: IPair<Key, T>): Iterator;
/**
* Insert an element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element.
*/
insert(hint: Iterator, pair: IPair<Key, T>): Iterator;
/**
* Insert range elements.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
insert<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected abstract _Key_eq(x: Key, y: Key): boolean;
protected _Erase_by_key(key: Key): number;
/**
* @inheritDoc
*/
merge(source: Source): void;
}
/**
*
*/
export declare namespace MultiMap {
/**
* Iterator of {@link MultiMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, T, SourceT extends MultiMap<Key, T, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, SourceT, IteratorT, ReverseT>> = MapContainer.Iterator<Key, T, false, SourceT, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link MultiMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, T, SourceT extends MultiMap<Key, T, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, SourceT, IteratorT, ReverseT>> = MapContainer.ReverseIterator<Key, T, false, SourceT, IteratorT, ReverseT>;
}
+100
View File
@@ -0,0 +1,100 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
var MapContainer_1 = require("./MapContainer");
/**
* Basic map container allowing duplicated keys.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link MultiMap}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var MultiMap = /** @class */ (function (_super) {
__extends(MultiMap, _super);
function MultiMap() {
return _super !== null && _super.apply(this, arguments) || this;
}
MultiMap.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return _super.prototype.insert.apply(this, __spreadArray([], __read(args), false));
};
MultiMap.prototype._Erase_by_key = function (key) {
var first = this.find(key);
if (first.equals(this.end()) === true)
return 0;
var last = first.next();
var ret = 1;
while (!last.equals(this.end()) && this._Key_eq(key, last.first)) {
last = last.next();
++ret;
}
this._Erase_by_range(first, last);
return ret;
};
/* ---------------------------------------------------------
UTILITY
--------------------------------------------------------- */
/**
* @inheritDoc
*/
MultiMap.prototype.merge = function (source) {
this.insert(source.begin(), source.end());
source.clear();
};
return MultiMap;
}(MapContainer_1.MapContainer));
exports.MultiMap = MultiMap;
//# sourceMappingURL=MultiMap.js.map
+64
View File
@@ -0,0 +1,64 @@
/**
* @packageDocumentation
* @module std.base
*/
import { SetContainer } from "./SetContainer";
import { IForwardIterator } from "../../iterator/IForwardIterator";
/**
* Basic set container allowing multiple keys.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link MultiSet}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class MultiSet<Key, Source extends MultiSet<Key, Source, IteratorT, ReverseT>, IteratorT extends MultiSet.Iterator<Key, Source, IteratorT, ReverseT>, ReverseT extends MultiSet.ReverseIterator<Key, Source, IteratorT, ReverseT>> extends SetContainer<Key, false, Source, IteratorT, ReverseT> {
/**
* Insert an element.
*
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element.
*/
insert(key: Key): IteratorT;
/**
* Insert an element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element.
*/
insert(hint: IteratorT, key: Key): IteratorT;
/**
* Insert range elements.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
insert<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(begin: InputIterator, end: InputIterator): void;
protected abstract _Key_eq(x: Key, y: Key): boolean;
protected _Erase_by_val(key: Key): number;
/**
* @inheritDoc
*/
merge(source: Source): void;
}
/**
*
*/
export declare namespace MultiSet {
/**
* Iterator of {@link MultiSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, SourceT extends MultiSet<Key, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, SourceT, IteratorT, ReverseT>> = SetContainer.Iterator<Key, false, SourceT, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link MultiSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, SourceT extends MultiSet<Key, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, SourceT, IteratorT, ReverseT>> = SetContainer.ReverseIterator<Key, false, SourceT, IteratorT, ReverseT>;
}
+100
View File
@@ -0,0 +1,100 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
var SetContainer_1 = require("./SetContainer");
/**
* Basic set container allowing multiple keys.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link MultiSet}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var MultiSet = /** @class */ (function (_super) {
__extends(MultiSet, _super);
function MultiSet() {
return _super !== null && _super.apply(this, arguments) || this;
}
MultiSet.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return _super.prototype.insert.apply(this, __spreadArray([], __read(args), false));
};
MultiSet.prototype._Erase_by_val = function (key) {
var first = this.find(key);
if (first.equals(this.end()) === true)
return 0;
var last = first.next();
var ret = 1;
while (!last.equals(this.end()) && this._Key_eq(key, last.value)) {
last = last.next();
++ret;
}
this._Erase_by_range(first, last);
return ret;
};
/* ---------------------------------------------------------
UTILITY
--------------------------------------------------------- */
/**
* @inheritDoc
*/
MultiSet.prototype.merge = function (source) {
this.insert(source.begin(), source.end());
source.clear();
};
return MultiSet;
}(SetContainer_1.SetContainer));
exports.MultiSet = MultiSet;
//# sourceMappingURL=MultiSet.js.map
+115
View File
@@ -0,0 +1,115 @@
/**
* @packageDocumentation
* @module std.base
*/
import { IAssociativeContainer } from "../../internal/container/associative/IAssociativeContainer";
import { IContainer } from "./IContainer";
import { Container } from "./Container";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { ILinearContainerBase } from "../../internal/container/linear/ILinearContainerBase";
import { Pair } from "../../utility/Pair";
/**
* Basic set container.
*
* @template Key Key type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link SetContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class SetContainer<Key, Unique extends boolean, SourceT extends SetContainer<Key, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends SetContainer.Iterator<Key, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends SetContainer.ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>> extends Container<Key, SourceT, IteratorT, ReverseT, Key> implements IAssociativeContainer<Key, Key, SourceT, IteratorT, ReverseT, Key> {
protected data_: ILinearContainerBase<Key, SourceT, IteratorT, ReverseT>;
/**
* Default Constructor.
*/
protected constructor(factory: (thisArg: SourceT) => ILinearContainerBase<Key, SourceT, IteratorT, ReverseT>);
/**
* @inheritDoc
*/
assign<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
abstract find(key: Key): IteratorT;
/**
* @inheritDoc
*/
begin(): IteratorT;
/**
* @inheritDoc
*/
end(): IteratorT;
/**
* @inheritDoc
*/
has(key: Key): boolean;
/**
* @inheritDoc
*/
abstract count(key: Key): number;
/**
* @inheritDoc
*/
size(): number;
/**
* @inheritDoc
*/
push(...items: Key[]): number;
insert(key: Key): SetContainer.InsertRet<Key, Unique, SourceT, IteratorT, ReverseT>;
insert(hint: IteratorT, key: Key): IteratorT;
insert<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected abstract _Insert_by_key(key: Key): SetContainer.InsertRet<Key, Unique, SourceT, IteratorT, ReverseT>;
protected abstract _Insert_by_hint(hint: IteratorT, key: Key): IteratorT;
protected abstract _Insert_by_range<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(begin: InputIterator, end: InputIterator): void;
/**
* @inheritDoc
*/
erase(key: Key): number;
/**
* @inheritDoc
*/
erase(pos: IteratorT): IteratorT;
/**
* @inheritDoc
*/
erase(first: IteratorT, last: IteratorT): IteratorT;
protected abstract _Erase_by_val(key: Key): number;
protected _Erase_by_range(first: IteratorT, last?: IteratorT): IteratorT;
/**
* @inheritDoc
*/
abstract swap(obj: SourceT): void;
/**
* @inheritDoc
*/
abstract merge(source: SourceT): void;
protected abstract _Handle_insert(first: IteratorT, last: IteratorT): void;
protected abstract _Handle_erase(first: IteratorT, last: IteratorT): void;
}
/**
*
*/
export declare namespace SetContainer {
/**
* Return type of {@link SetContainer.insert}
*/
type InsertRet<Key, Unique extends boolean, Source extends SetContainer<Key, Unique, Source, IteratorT, ReverseT>, IteratorT extends Iterator<Key, Unique, Source, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, Unique, Source, IteratorT, ReverseT>> = Unique extends true ? Pair<IteratorT, boolean> : IteratorT;
/**
* Iterator of {@link SetContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, Unique extends boolean, SourceT extends SetContainer<Key, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>> = Readonly<IContainer.Iterator<Key, SourceT, IteratorT, ReverseT, Key>>;
/**
* Reverse iterator of {@link SetContainer}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, Unique extends boolean, SourceT extends SetContainer<Key, Unique, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, Unique, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, Unique, SourceT, IteratorT, ReverseT>> = Readonly<IContainer.ReverseIterator<Key, SourceT, IteratorT, ReverseT, Key>>;
}
+151
View File
@@ -0,0 +1,151 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetContainer = void 0;
var Container_1 = require("./Container");
var NativeArrayIterator_1 = require("../../internal/iterator/disposable/NativeArrayIterator");
/**
* Basic set container.
*
* @template Key Key type
* @template Unique Whether duplicated key is blocked or not
* @template Source Derived type extending this {@link SetContainer}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var SetContainer = /** @class */ (function (_super) {
__extends(SetContainer, _super);
/* ---------------------------------------------------------
CONSTURCTORS
--------------------------------------------------------- */
/**
* Default Constructor.
*/
function SetContainer(factory) {
var _this = _super.call(this) || this;
_this.data_ = factory(_this);
return _this;
}
/**
* @inheritDoc
*/
SetContainer.prototype.assign = function (first, last) {
// INSERT
this.clear();
this.insert(first, last);
};
/**
* @inheritDoc
*/
SetContainer.prototype.clear = function () {
// TO BE ABSTRACT
this.data_.clear();
};
/**
* @inheritDoc
*/
SetContainer.prototype.begin = function () {
return this.data_.begin();
};
/**
* @inheritDoc
*/
SetContainer.prototype.end = function () {
return this.data_.end();
};
/* ---------------------------------------------------------
ELEMENTS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
SetContainer.prototype.has = function (key) {
return !this.find(key).equals(this.end());
};
/**
* @inheritDoc
*/
SetContainer.prototype.size = function () {
return this.data_.size();
};
/* =========================================================
ELEMENTS I/O
- INSERT
- ERASE
- UTILITY
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
/**
* @inheritDoc
*/
SetContainer.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
if (items.length === 0)
return this.size();
// INSERT BY RANGE
var first = new NativeArrayIterator_1.NativeArrayIterator(items, 0);
var last = new NativeArrayIterator_1.NativeArrayIterator(items, items.length);
this._Insert_by_range(first, last);
// RETURN SIZE
return this.size();
};
SetContainer.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1)
return this._Insert_by_key(args[0]);
else if (args[0].next instanceof Function &&
args[1].next instanceof Function)
return this._Insert_by_range(args[0], args[1]);
else
return this._Insert_by_hint(args[0], args[1]);
};
SetContainer.prototype.erase = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 1 &&
!(args[0] instanceof this.end().constructor &&
args[0].source() === this))
return this._Erase_by_val(args[0]);
else if (args.length === 1)
return this._Erase_by_range(args[0]);
else
return this._Erase_by_range(args[0], args[1]);
};
SetContainer.prototype._Erase_by_range = function (first, last) {
if (last === void 0) { last = first.next(); }
// ERASE
var it = this.data_.erase(first, last);
// POST-PROCESS
this._Handle_erase(first, last);
return it;
};
return SetContainer;
}(Container_1.Container));
exports.SetContainer = SetContainer;
//# sourceMappingURL=SetContainer.js.map
+147
View File
@@ -0,0 +1,147 @@
/**
* @packageDocumentation
* @module std.base
*/
import { MapContainer } from "./MapContainer";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { IPair } from "../../utility/IPair";
import { Entry } from "../../utility/Entry";
import { Pair } from "../../utility/Pair";
/**
* Basic map container blocking duplicated key.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link UniqueMap}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class UniqueMap<Key, T, Source extends UniqueMap<Key, T, Source, Iterator, Reverse>, Iterator extends UniqueMap.Iterator<Key, T, Source, Iterator, Reverse>, Reverse extends UniqueMap.ReverseIterator<Key, T, Source, Iterator, Reverse>> extends MapContainer<Key, T, true, Source, Iterator, Reverse> {
/**
* @inheritDoc
*/
count(key: Key): number;
/**
* Get a value.
*
* @param key Key to search for.
* @return The value mapped by the key.
*/
get(key: Key): T;
/**
* Take a value.
*
* Get a value, or set the value and returns it.
*
* @param key Key to search for.
* @param generator Value generator when the matched key not found
* @returns Value, anyway
*/
take(key: Key, generator: () => T): T;
/**
* Set a value with key.
*
* @param key Key to be mapped or search for.
* @param val Value to insert or assign.
*/
set(key: Key, val: T): void;
/**
* Construct and insert element.
*
* @param key Key to be mapped or search for.
* @param value Value to emplace.
* @return {@link Pair} of an iterator to the newly inserted element and `true`, if the specified *key* doesn't exist, otherwise {@link Pair} of iterator to the ordinary element and `false`.
*/
abstract emplace(key: Key, value: T): Pair<Iterator, boolean>;
/**
* Construct and insert element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param key Key of the new element.
* @param val Value of the new element.
* @return An iterator to the newly inserted element, if the specified key doesn't exist, otherwise an iterator to the ordinary element.
*/
abstract emplace_hint(hint: Iterator, key: Key, val: T): Iterator;
/**
* Insert an element.
*
* @param pair A tuple to be referenced for the insert.
* @return {@link Pair} of an iterator to the newly inserted element and `true`, if the specified *key* doesn't exist, otherwise {@link Pair} of iterator to the ordinary element and `false`.
*/
insert(pair: IPair<Key, T>): Pair<Iterator, boolean>;
/**
* Insert an element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element, if the specified key doesn't exist, otherwise an iterator to the ordinary element.
*/
insert(hint: Iterator, pair: IPair<Key, T>): Iterator;
/**
* Insert range elements.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
insert<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected _Insert_by_range<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* Insert or assign an element.
*
* @param key Key to be mapped or search for.
* @param value Value to insert or assign.
* @return {@link Pair} of an iterator to the newly inserted element and `true`, if the specified *key* doesn't exist, otherwise {@link Pair} of iterator to the ordinary element and `false`.
*/
insert_or_assign(key: Key, value: T): Pair<Iterator, boolean>;
/**
* Insert or assign an element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param key Key to be mapped or search for.
* @param value Value to insert or assign.
* @return An iterator to the newly inserted element, if the specified key doesn't exist, otherwise an iterator to the ordinary element.
*/
insert_or_assign(hint: Iterator, key: Key, value: T): Iterator;
private _Insert_or_assign_with_key_value;
private _Insert_or_assign_with_hint;
/**
* Extract an element by key.
*
* @param key Key to search for.
* @return The extracted element.
*/
extract(key: Key): Entry<Key, T>;
/**
* Extract an element by iterator.
*
* @param pos The iterator to the element for extraction.
* @return Iterator following the *pos*, strained by the extraction.
*/
extract(pos: Iterator): Iterator;
private _Extract_by_key;
private _Extract_by_iterator;
protected _Erase_by_key(key: Key): number;
/**
* @inheritDoc
*/
merge(source: Source): void;
}
/**
*
*/
export declare namespace UniqueMap {
/**
* Iterator of {@link UniqueMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, T, SourceT extends UniqueMap<Key, T, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, SourceT, IteratorT, ReverseT>> = MapContainer.Iterator<Key, T, true, SourceT, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link UniqueMap}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, T, SourceT extends UniqueMap<Key, T, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, T, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, T, SourceT, IteratorT, ReverseT>> = MapContainer.ReverseIterator<Key, T, true, SourceT, IteratorT, ReverseT>;
}
+194
View File
@@ -0,0 +1,194 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UniqueMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
var MapContainer_1 = require("./MapContainer");
var ErrorGenerator_1 = require("../../internal/exception/ErrorGenerator");
/**
* Basic map container blocking duplicated key.
*
* @template Key Key type
* @template T Mapped type
* @template Source Derived type extending this {@link UniqueMap}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var UniqueMap = /** @class */ (function (_super) {
__extends(UniqueMap, _super);
function UniqueMap() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
UniqueMap.prototype.count = function (key) {
return this.find(key).equals(this.end()) ? 0 : 1;
};
/**
* Get a value.
*
* @param key Key to search for.
* @return The value mapped by the key.
*/
UniqueMap.prototype.get = function (key) {
var it = this.find(key);
if (it.equals(this.end()) === true)
throw ErrorGenerator_1.ErrorGenerator.key_nout_found(this, "get", key);
return it.second;
};
/**
* Take a value.
*
* Get a value, or set the value and returns it.
*
* @param key Key to search for.
* @param generator Value generator when the matched key not found
* @returns Value, anyway
*/
UniqueMap.prototype.take = function (key, generator) {
var it = this.find(key);
return it.equals(this.end())
? this.emplace(key, generator()).first.second
: it.second;
};
/**
* Set a value with key.
*
* @param key Key to be mapped or search for.
* @param val Value to insert or assign.
*/
UniqueMap.prototype.set = function (key, val) {
this.insert_or_assign(key, val);
};
UniqueMap.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return _super.prototype.insert.apply(this, __spreadArray([], __read(args), false));
};
UniqueMap.prototype._Insert_by_range = function (first, last) {
for (var it = first; !it.equals(last); it = it.next())
this.emplace(it.value.first, it.value.second);
};
UniqueMap.prototype.insert_or_assign = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 2) {
return this._Insert_or_assign_with_key_value(args[0], args[1]);
}
else if (args.length === 3) {
// INSERT OR ASSIGN AN ELEMENT
return this._Insert_or_assign_with_hint(args[0], args[1], args[2]);
}
};
UniqueMap.prototype._Insert_or_assign_with_key_value = function (key, value) {
var ret = this.emplace(key, value);
if (ret.second === false)
ret.first.second = value;
return ret;
};
UniqueMap.prototype._Insert_or_assign_with_hint = function (hint, key, value) {
var ret = this.emplace_hint(hint, key, value);
if (ret.second !== value)
ret.second = value;
return ret;
};
UniqueMap.prototype.extract = function (param) {
if (param instanceof this.end().constructor)
return this._Extract_by_iterator(param);
else
return this._Extract_by_key(param);
};
UniqueMap.prototype._Extract_by_key = function (key) {
var it = this.find(key);
if (it.equals(this.end()) === true)
throw ErrorGenerator_1.ErrorGenerator.key_nout_found(this, "extract", key);
var ret = it.value;
this._Erase_by_range(it);
return ret;
};
UniqueMap.prototype._Extract_by_iterator = function (it) {
if (it.equals(this.end()) === true)
return this.end();
this._Erase_by_range(it);
return it;
};
UniqueMap.prototype._Erase_by_key = function (key) {
var it = this.find(key);
if (it.equals(this.end()) === true)
return 0;
this._Erase_by_range(it);
return 1;
};
/* ---------------------------------------------------------
UTILITY
--------------------------------------------------------- */
/**
* @inheritDoc
*/
UniqueMap.prototype.merge = function (source) {
for (var it = source.begin(); !it.equals(source.end());)
if (this.has(it.first) === false) {
this.insert(it.value);
it = source.erase(it);
}
else
it = it.next();
};
return UniqueMap;
}(MapContainer_1.MapContainer));
exports.UniqueMap = UniqueMap;
//# sourceMappingURL=UniqueMap.js.map
+84
View File
@@ -0,0 +1,84 @@
/**
* @packageDocumentation
* @module std.base
*/
import { SetContainer } from "./SetContainer";
import { IForwardIterator } from "../../iterator/IForwardIterator";
import { Pair } from "../../utility/Pair";
/**
* Basic set container blocking duplicated key.
*
* @template Key Key type
* @template Source Derived type extending this {@link UniqueSet}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare abstract class UniqueSet<Key, Source extends UniqueSet<Key, Source, IteratorT, ReverseT>, IteratorT extends UniqueSet.Iterator<Key, Source, IteratorT, ReverseT>, ReverseT extends UniqueSet.ReverseIterator<Key, Source, IteratorT, ReverseT>> extends SetContainer<Key, true, Source, IteratorT, ReverseT> {
/**
* @inheritDoc
*/
count(key: Key): number;
/**
* Insert an element.
*
* @param key Key to insert.
* @return {@link Pair} of an iterator to the newly inserted element and `true`, if the specified *key* doesn't exist, otherwise {@link Pair} of iterator to ordinary element and `false`.
*/
insert(key: Key): Pair<IteratorT, boolean>;
/**
* Insert an element with hint.
*
* @param hint Hint for the position where the element can be inserted.
* @param pair A tuple to be referenced for the insert.
* @return An iterator to the newly inserted element, if the specified key doesn't exist, otherwise an iterator to the ordinary element.
*/
insert(hint: IteratorT, key: Key): IteratorT;
/**
* Insert range elements.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
insert<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected _Insert_by_range<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* Extract an element by key.
*
* @param key Key to search for.
* @return The extracted element.
*/
extract(key: Key): Key;
/**
* Extract an element by iterator.
*
* @param pos The iterator to the element for extraction.
* @return Iterator following the *pos*, strained by the extraction.
*/
extract(it: IteratorT): IteratorT;
private _Extract_by_val;
private _Extract_by_iterator;
protected _Erase_by_val(key: Key): number;
/**
* @inheritDoc
*/
merge(source: Source): void;
}
/**
*
*/
export declare namespace UniqueSet {
/**
* Iterator of {@link UniqueSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type Iterator<Key, SourceT extends UniqueSet<Key, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, SourceT, IteratorT, ReverseT>> = SetContainer.Iterator<Key, true, SourceT, IteratorT, ReverseT>;
/**
* Reverse iterator of {@link UniqueSet}
*
* @author Jenogho Nam <http://samchon.org>
*/
type ReverseIterator<Key, SourceT extends UniqueSet<Key, SourceT, IteratorT, ReverseT>, IteratorT extends Iterator<Key, SourceT, IteratorT, ReverseT>, ReverseT extends ReverseIterator<Key, SourceT, IteratorT, ReverseT>> = SetContainer.ReverseIterator<Key, true, SourceT, IteratorT, ReverseT>;
}
+132
View File
@@ -0,0 +1,132 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UniqueSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
var SetContainer_1 = require("./SetContainer");
var ErrorGenerator_1 = require("../../internal/exception/ErrorGenerator");
/**
* Basic set container blocking duplicated key.
*
* @template Key Key type
* @template Source Derived type extending this {@link UniqueSet}
* @template IteratorT Iterator type
* @template ReverseT Reverse iterator type
*
* @author Jeongho Nam - https://github.com/samchon
*/
var UniqueSet = /** @class */ (function (_super) {
__extends(UniqueSet, _super);
function UniqueSet() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* ---------------------------------------------------------
ACCESSOR
--------------------------------------------------------- */
/**
* @inheritDoc
*/
UniqueSet.prototype.count = function (key) {
return this.find(key).equals(this.end()) ? 0 : 1;
};
UniqueSet.prototype.insert = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return _super.prototype.insert.apply(this, __spreadArray([], __read(args), false));
};
UniqueSet.prototype._Insert_by_range = function (first, last) {
for (; !first.equals(last); first = first.next())
this._Insert_by_key(first.value);
};
UniqueSet.prototype.extract = function (param) {
if (param instanceof this.end().constructor)
return this._Extract_by_iterator(param);
else
return this._Extract_by_val(param);
};
UniqueSet.prototype._Extract_by_val = function (key) {
var it = this.find(key);
if (it.equals(this.end()) === true)
throw ErrorGenerator_1.ErrorGenerator.key_nout_found(this, "extract", key);
this._Erase_by_range(it);
return key;
};
UniqueSet.prototype._Extract_by_iterator = function (it) {
if (it.equals(this.end()) === true || this.has(it.value) === false)
return this.end();
this._Erase_by_range(it);
return it;
};
UniqueSet.prototype._Erase_by_val = function (key) {
var it = this.find(key);
if (it.equals(this.end()) === true)
return 0;
this._Erase_by_range(it);
return 1;
};
/* ---------------------------------------------------------
UTILITY
--------------------------------------------------------- */
/**
* @inheritDoc
*/
UniqueSet.prototype.merge = function (source) {
for (var it = source.begin(); !it.equals(source.end());) {
if (this.has(it.value) === false) {
this.insert(it.value);
it = source.erase(it);
}
else
it = it.next();
}
};
return UniqueSet;
}(SetContainer_1.SetContainer));
exports.UniqueSet = UniqueSet;
//# sourceMappingURL=UniqueSet.js.map
+19
View File
@@ -0,0 +1,19 @@
/**
* @packageDocumentation
* @module std.base
*/
export * from "./IContainer";
export * from "./ILinearContainer";
export * from "./IDequeContainer";
export * from "./IArrayContainer";
export * from "./Container";
export * from "./SetContainer";
export * from "./UniqueSet";
export * from "./MultiSet";
export * from "./ITreeSet";
export * from "./IHashSet";
export * from "./MapContainer";
export * from "./UniqueMap";
export * from "./MultiMap";
export * from "./ITreeMap";
export * from "./IHashMap";
+41
View File
@@ -0,0 +1,41 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
// LINEAR
__exportStar(require("./IContainer"), exports);
__exportStar(require("./ILinearContainer"), exports);
__exportStar(require("./IDequeContainer"), exports);
__exportStar(require("./IArrayContainer"), exports);
__exportStar(require("./Container"), exports);
// SETS
__exportStar(require("./SetContainer"), exports);
__exportStar(require("./UniqueSet"), exports);
__exportStar(require("./MultiSet"), exports);
__exportStar(require("./ITreeSet"), exports);
__exportStar(require("./IHashSet"), exports);
// MAPS
__exportStar(require("./MapContainer"), exports);
__exportStar(require("./UniqueMap"), exports);
__exportStar(require("./MultiMap"), exports);
__exportStar(require("./ITreeMap"), exports);
__exportStar(require("./IHashMap"), exports);
//# sourceMappingURL=index.js.map
+10
View File
@@ -0,0 +1,10 @@
/**
* Basic Features
*
* @packageDocumentation
* @module std.base
* @preferred
*/
import * as base from "./module";
export default base;
export * from "./module";
+41
View File
@@ -0,0 +1,41 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
//================================================================
/**
* Basic Features
*
* @packageDocumentation
* @module std.base
* @preferred
*/
//================================================================
var base = __importStar(require("./module"));
exports.default = base;
__exportStar(require("./module"), exports);
//# sourceMappingURL=index.js.map
+6
View File
@@ -0,0 +1,6 @@
/**
* @packageDocumentation
* @module std.base
*/
export * from "./container/index";
export * from "./thread/index";
+25
View File
@@ -0,0 +1,25 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
//================================================================
/**
* @packageDocumentation
* @module std.base
*/
//================================================================
__exportStar(require("./container/index"), exports);
__exportStar(require("./thread/index"), exports);
//# sourceMappingURL=module.js.map
+63
View File
@@ -0,0 +1,63 @@
/**
* @packageDocumentation
* @module std.base
*/
/**
* Common interface for lockable mutex.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ILockable {
/**
* Locks the mutex.
*
* Monopolies a mutex until be {@link unlock unlocked}. If there're someone who have already
* {@link lock monopolied} the mutex, the function call would be blocked until all of them to
* return their acquistions by calling the {@link unlock} method.
*
* In same reason, if you don't call the {@link unlock} function after your business, the
* others who want to {@link lock monopoly} the mutex would be fall into the forever sleep.
* Therefore, never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.lock} function instead to ensure the safety.
*/
lock(): Promise<void>;
/**
* Tries to lock the mutex.
*
* Attempts to monopoly a mutex without blocking. If succeeded to monopoly the mutex
* immediately, it returns `true` directly. Otherwise there's someone who has already
* {@link lock monopolied} the mutex, the function gives up the trial immediately and returns
* `false` directly.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* the mutex would be fall into the forever sleep. Therefore, never forget to calling the
* {@link unlock} function or utilize the {@link UniqueLock.try_lock} function instead to
* ensure the safety.
*
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock(): Promise<boolean>;
/**
* Unlocks the mutex.
*
* When you call this {@link unlock} method and there're someone who are currently blocked by
* attempting to {@link lock} this mutex, one of them (FIFO; first-in-first-out) would acquire
* the lock and continues its execution.
*
* Otherwise, there's not anyone who is acquiring the {@link lock} of this mutex, the
* {@link DomainError} exception would be thrown.
*
* > As you know, when you succeeded to acquire the `lock`, you don't have to forget to
* > calling this {@link unlock} method after your business. If you forget it, it would be a
* > terrible situation for the others who're attempting to lock this mutex.
* >
* > However, if you utilize the {@link UniqueLock}, you don't need to consider about this
* > {@link unlock} method. Just define your business into a callback function as a parameter
* > of methods of the {@link UniqueLock}, then this {@link unlock} method would be
* > automatically called by the {@link UniqueLock} after the business.
*
* @throw {@link DomainError} when no one is acquiring the {@link lock write lock}.
*/
unlock(): Promise<void>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ILockable.js.map
+114
View File
@@ -0,0 +1,114 @@
/**
* @packageDocumentation
* @module std.base
*/
import { ILockable } from "./ILockable";
/**
* Common interface for shared lockable mutex.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ISharedLockable extends ILockable {
/**
* Write locks the mutex.
*
* Monopolies a mutex until be {@link unlock unlocked}. If there're someone who have already
* {@link lock monopolied} or {@link lock_shared shared} the mutex, the function call would
* be blocked until all of them to return their acquistions by calling {@link unlock} or
* {@link unlock_shared} methods.
*
* In same reason, if you don't call the {@link unlock} function after your business, the
* others who want to {@link lock monopoly} or {@link lock_shared share} the mutex would be
* fall into the forever sleep. Therefore, never forget to calling the {@link unlock} function
* or utilize the {@link UniqueLock.lock} function instead to ensure the safety.
*/
lock(): Promise<void>;
/**
* Tries to write lock the mutex.
*
* Attempts to monopoly a mutex without blocking. If succeeded to monopoly the mutex
* immediately, it returns `true` directly. Otherwise there's someone who has already
* {@link lock monopolied} or {@link lock_shared shared} the mutex, the function gives up the
* trial immediately and returns `false` directly.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* or {@link lock_shared share} the mutex would be fall into the forever sleep. Therefore,
* never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.try_lock} function instead to ensure the safety.
*
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock(): Promise<boolean>;
/**
* Write unlocks the mutex.
*
* When you call this {@link unlock} method and there're someone who are currently blocked by
* attempting to {@link lock write} or {@link lock_shared read} lock this mutex, one of them
* (FIFO; first-in-first-out) would acquire the lock and continues its execution.
*
* Otherwise, there's not anyone who is acquiring the {@link lock write lock} of this mutex,
* the {@link DomainError} exception would be thrown.
*
* > As you know, when you succeeded to acquire the `write lock`, you don't have to forget to
* > calling this {@link unlock} method after your business. If you forget it, it would be a
* > terrible situation for the others who're attempting to lock this mutex.
* >
* > However, if you utilize the {@link UniqueLock}, you don't need to consider about this
* > {@link unlock} method. Just define your business into a callback function as a parameter
* > of methods of the {@link UniqueLock}, then this {@link unlock} method would be
* > automatically called by the {@link UniqueLock} after the business.
*
* @throw {@link DomainError} when no one is acquiring the {@link lock write lock}.
*/
unlock(): Promise<void>;
/**
* Read locks the mutex.
*
* Shares a mutex until be {@link unlock_shared unlocked}. If there're someone who have
* already {@link lock monopolied} the mutex, the function call would be blocked until all of
* them to {@link unlock return} their acquisitions.
*
* In same reason, if you don't call the {@link unlock_shared} function after your business,
* the others who want to {@link lock monopoly} the mutex would be fall into the forever
* sleep. Therefore, never forget to calling the {@link unlock_shared} or utilize the
* {@link SharedLock.lock} function instead to ensure the safety.
*/
lock_shared(): Promise<void>;
/**
* Tries to read lock the mutex.
*
* Attemps to share a mutex without blocking. If succeeded to share the mutex immediately, it
* returns `true` directly. Otherwise there's someone who has already {@link lock monopolied}
* the mutex, the function gives up the trial immediately and returns `false` directly.
*
* Note that, if you succeeded to share the mutex (returns `true`) but do not call the
* {@link unlock_shared} function after your buinsess, the others who want to
* {@link lock monopoly} the mutex would be fall into the forever sleep. Therefore, never
* forget to calling the {@link unlock_shared} function or utilize the
* {@link SharedLock.try_lock} function instead to ensure the safety.
*
* @return Whether succeeded to share the mutex or not.
*/
try_lock_shared(): Promise<boolean>;
/**
* Read unlocks the mutex.
*
* When you call this {@link unlock_shared} method and there're someone who are currently
* blocked by attempting to {@link lock monopoly} this mutex, one of them
* (FIFO; first-in-first-out) would acquire the lock and continues its execution.
*
* Otherwise, there's not anyone who is acquiring the {@link lock_shared read lock} of this
* mutex, the {@link DomainError} exception would be thrown.
*
* > As you know, when you succeeded to acquire the `read lock`, you don't have to forget to
* > calling this {@link unlock_shared} method after your business. If you forget it, it would
* > be a terrible situation for the others who're attempting to lock this mutex.
* >
* > However, if you utilize the {@link SharedLock}, you don't need to consider about this
* > {@link unlock_shared} method. Just define your business into a callback function as a
* > parameter of methods of the {@link SharedLock}, then this {@link unlock_shared} method
* > would be automatically called by the {@link SharedLock} after the business.
*/
unlock_shared(): Promise<void>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ISharedLockable.js.map
+96
View File
@@ -0,0 +1,96 @@
/**
* @packageDocumentation
* @module std.base
*/
import { ISharedLockable } from "./ISharedLockable";
/**
* Common interface for shared & timed lockable mutex.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ISharedTimedLockable extends ISharedLockable {
/**
* Tries to write lock the mutex until timeout.
*
* Attempts to monopoly a mutex until timeout. If succeeded to monopoly the mutex until the
* timeout, it returns `true`. Otherwise failed to acquiring the lock in the given time, the
* function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} or {@link lock_shared shared} the mutex and
* does not return it over the timeout.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* or {@link lock_shared share} the mutex would be fall into the forever sleep. Therefore,
* never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.try_lock_for} function instead to ensure the safety.
*
* @param ms The maximum miliseconds for waiting.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_for(ms: number): Promise<boolean>;
/**
* Tries to write lock the mutex until time expiration.
*
* Attemps to monopoly a mutex until time expiration. If succeeded to monopoly the mutex
* until the time expiration, it returns `true`. Otherwise failed to acquiring the lock in the
* given time, the function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} or {@link lock_shared shared} the mutex and
* does not return it over the time expiration.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* or {@link lock_shared share} the mutex would be fall into the forever sleep. Therefore,
* never forget to calling the {@link unlock} function or utilize the
* {@link UniqueLock.try_lock_until} function instead to ensure the safety.
*
* @param at The maximum time point to wait.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_until(at: Date): Promise<boolean>;
/**
* Tries to read lock the mutex until timeout.
*
* Attemps to share a mutex until timeout. If succeeded to share the mutex until timeout, it
* returns `true`. Otherwise failed to acquiring the shared lock in the given time, the
* function gives up the trial and returns `false`.
*
* Failed to acquring the shared lock in the given time (returns `false`), it means that
* there's someone who has already {@link lock monopolied} the mutex and does not return it
* over the timeout.
*
* Note that, if you succeeded to share the mutex (returns `true`) but do not call the
* {@link unlock_shared} function after your buinsess, the others who want to
* {@link lock monopoly} the mutex would be fall into the forever sleep. Therefore, never
* forget to calling the {@link unlock_shared} function or utilize the
* {@link SharedLock.try_lock_for} function instead to ensure the safety.
*
* @param ms The maximum miliseconds for waiting.
* @return Whether succeeded to share the mutex or not.
*/
try_lock_shared_for(ms: number): Promise<boolean>;
/**
* Tries to read lock the mutex until time expiration.
*
* Attemps to share a mutex until time expiration. If succeeded to share the mutex until time
* expiration, it returns `true`. Otherwise failed to acquiring the shared lock in the given
* time, the function gives up the trial and returns `false`.
*
* Failed to acquring the shared lock in the given time (returns `false`), it means that
* there's someone who has already {@link lock monopolied} the mutex and does not return it
* over the time expiration.
*
* Note that, if you succeeded to share the mutex (returns `true`) but do not call the
* {@link unlock_shared} function after your buinsess, the others who want to
* {@link lock monopoly} the mutex would be fall into the forever sleep. Therefore, never
* forget to calling the {@link unlock_shared} function or utilize the
* {@link SharedLock.try_lock_until} function instead to ensure the safety.
*
* @param at The maximum time point to wait.
* @return Whether succeeded to share the mutex or not.
*/
try_lock_shared_until(at: Date): Promise<boolean>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ISharedTimedLockable.js.map
+54
View File
@@ -0,0 +1,54 @@
/**
* @packageDocumentation
* @module std.base
*/
import { ILockable } from "./ILockable";
/**
* Common interface for timed lockable mutex.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export interface ITimedLockable extends ILockable {
/**
* Tries to lock the mutex until timeout.
*
* Attempts to monopoly a mutex until timeout. If succeeded to monopoly the mutex until the
* timeout, it returns `true`. Otherwise failed to acquiring the lock in the given time, the
* function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} the mutex and does not return it over the
* timeout.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* the mutex would be fall into the forever sleep. Therefore, never forget to calling the
* {@link unlock} function or utilize the {@link UniqueLock.try_lock_for} function instead to
* ensure the safety.
*
* @param ms The maximum miliseconds for waiting.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_for(ms: number): Promise<boolean>;
/**
* Tries to write lock the mutex until time expiration.
*
* Attemps to monopoly a mutex until time expiration. If succeeded to monopoly the mutex
* until the time expiration, it returns `true`. Otherwise failed to acquiring the lock in the
* given time, the function gives up the trial and returns `false`.
*
* Failed to acquiring the lock in the given time (returns `false`), it means that there's
* someone who has already {@link lock monopolied} the mutex and does not return it over the
* time expiration.
*
* Note that, if you succeeded to monopoly the mutex (returns `true`) but do not call the
* {@link unlock} function after your business, the others who want to {@link lock monopoly}
* the mutex would be fall into the forever sleep. Therefore, never forget to calling the
* {@link unlock} function or utilize the {@link UniqueLock.try_lock_until} function instead
* to ensure the safety.
*
* @param at The maximum time point to wait.
* @return Whether succeeded to monopoly the mutex or not.
*/
try_lock_until(at: Date): Promise<boolean>;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ITimedLockable.js.map
+4
View File
@@ -0,0 +1,4 @@
export * from "./ILockable";
export * from "./ITimedLockable";
export * from "./ISharedLockable";
export * from "./ISharedTimedLockable";
+21
View File
@@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ILockable"), exports);
__exportStar(require("./ITimedLockable"), exports);
__exportStar(require("./ISharedLockable"), exports);
__exportStar(require("./ISharedTimedLockable"), exports);
//# sourceMappingURL=index.js.map
+167
View File
@@ -0,0 +1,167 @@
/**
* @packageDocumentation
* @module std
*/
import { IArrayContainer } from "../base/container/IArrayContainer";
import { ArrayContainer } from "../internal/container/linear/ArrayContainer";
import { ArrayIterator } from "../internal/iterator/ArrayIterator";
import { ArrayReverseIterator } from "../internal/iterator/ArrayReverseIterator";
import { IForwardIterator } from "../iterator/IForwardIterator";
/**
* Double ended queue.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class Deque<T> extends ArrayContainer<T, Deque<T>, Deque<T>, Deque.Iterator<T>, Deque.ReverseIterator<T>, T> implements IArrayContainer<T, Deque<T>, Deque.Iterator<T>, Deque.ReverseIterator<T>> {
private matrix_;
private size_;
private capacity_;
/**
* Default Constructor.
*/
constructor();
/**
* Initializer Constructor.
*
* @param items Items to assign.
*/
constructor(items: T[]);
/**
* Copy Constructor
*
* @param obj Object to copy.
*/
constructor(obj: Deque<T>);
/**
* Fill Constructor.
*
* @param size Initial size.
* @param val Value to fill.
*/
constructor(size: number, val: T);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
*/
constructor(first: Readonly<IForwardIterator<T>>, last: Readonly<IForwardIterator<T>>);
/**
* @inheritDoc
*/
assign(n: number, val: T): void;
/**
* @inheritDoc
*/
assign<InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
resize(n: number): void;
/**
* Reserve {@link capacity} enable to store *n* elements.
*
* @param n The capacity to reserve.
*/
reserve(n: number): void;
private _Reserve;
/**
* Shrink {@link capacity} to actual {@link size}.
*/
shrink_to_fit(): void;
/**
* @inheritDoc
*/
swap(obj: Deque<T>): void;
private _Swap;
private static _Emend;
/**
* @inheritDoc
*/
size(): number;
/**
* The capacity to store elements.
*
* @return The capacity.
*/
capacity(): number;
/**
* @inheritDoc
*/
nth(index: number): Deque.Iterator<T>;
/**
* @inheritDoc
*/
[Symbol.iterator](): IterableIterator<T>;
protected source(): Deque<T>;
protected _At(index: number): T;
protected _Set(index: number, val: T): void;
private _Fetch_index;
private _Compute_col_size;
/**
* @inheritDoc
*/
push(...items: T[]): number;
/**
* @inheritDoc
*/
push_front(val: T): void;
/**
* @inheritDoc
*/
push_back(val: T): void;
/**
* @inheritDoc
*/
pop_front(): void;
protected _Pop_back(): void;
protected _Insert_by_range<InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(pos: Deque.Iterator<T>, first: InputIterator, last: InputIterator): Deque.Iterator<T>;
private _Insert_to_middle;
private _Insert_to_end;
private _Try_expand_capacity;
private _Try_add_row_at_front;
private _Try_add_row_at_back;
protected _Erase_by_range(first: Deque.Iterator<T>, last: Deque.Iterator<T>): Deque.Iterator<T>;
}
/**
*
*/
export declare namespace Deque {
/**
* Iterator of {@link Deque}
*/
type Iterator<T> = ArrayIterator<T, Deque<T>>;
/**
* Reverse iterator of {@link Deque}
*/
type ReverseIterator<T> = ArrayReverseIterator<T, Deque<T>>;
const Iterator: typeof ArrayIterator;
const ReverseIterator: typeof ArrayReverseIterator;
/**
* Row size of the {@link Deque.matrix_ matrix} which contains elements.
*
* Note that the {@link ROW_SIZE} affects on time complexity of accessing and inserting element.
* Accessing element is {@link ROW_SIZE} times slower than ordinary {@link Vector} and inserting element
* in middle position is {@link ROW_SIZE} times faster than ordinary {@link Vector}.
*
* When the {@link ROW_SIZE} returns 8, time complexity of accessing element is O(8) and inserting
* element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1)
* and inserting element is O(N)).
*/
const ROW_SIZE = 8;
/**
* Minimum {@link Deque.capacity}.
*
* Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque}
* keeps the minimum {@link Deque.capacity} at least.
*/
const MIN_CAPACITY = 36;
/**
* Expansion ratio.
*/
const MAGNIFIER = 1.5;
}
+529
View File
@@ -0,0 +1,529 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Deque = void 0;
var ArrayContainer_1 = require("../internal/container/linear/ArrayContainer");
var ArrayIterator_1 = require("../internal/iterator/ArrayIterator");
var ArrayReverseIterator_1 = require("../internal/iterator/ArrayReverseIterator");
var NativeArrayIterator_1 = require("../internal/iterator/disposable/NativeArrayIterator");
var Pair_1 = require("../utility/Pair");
var InvalidArgument_1 = require("../exception/InvalidArgument");
var global_1 = require("../iterator/global");
var ErrorGenerator_1 = require("../internal/exception/ErrorGenerator");
/**
* Double ended queue.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Deque = /** @class */ (function (_super) {
__extends(Deque, _super);
function Deque() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this) || this;
// CONSTRUCTORS BRANCH
if (args.length === 0) {
_this.clear();
}
if (args.length === 1 && args[0] instanceof Array) {
// INITIALIZER CONSTRUCTOR
var array = args[0];
var first = new NativeArrayIterator_1.NativeArrayIterator(array, 0);
var last = new NativeArrayIterator_1.NativeArrayIterator(array, array.length);
_this.assign(first, last);
}
else if (args.length === 1 && args[0] instanceof Deque) {
// COPY CONSTRUCTOR
var container = args[0];
_this.assign(container.begin(), container.end());
}
else if (args.length === 2) {
// ASSIGN CONSTRUCTOR
_this.assign(args[0], args[1]);
}
return _this;
}
Deque.prototype.assign = function (first, second) {
// CLEAR PREVIOUS CONTENTS
this.clear();
// INSERT ITEMS
this.insert(this.end(), first, second);
};
/**
* @inheritDoc
*/
Deque.prototype.clear = function () {
// CLEAR CONTENTS
this.matrix_ = [[]];
// RE-INDEX
this.size_ = 0;
this.capacity_ = Deque.MIN_CAPACITY;
};
/**
* @inheritDoc
*/
Deque.prototype.resize = function (n) {
n = Deque._Emend(n, "resize");
var expansion = n - this.size();
if (expansion > 0)
this.insert(this.end(), expansion, undefined);
else if (expansion < 0)
this.erase(this.end().advance(-expansion), this.end());
};
/**
* Reserve {@link capacity} enable to store *n* elements.
*
* @param n The capacity to reserve.
*/
Deque.prototype.reserve = function (n) {
this._Reserve(Deque._Emend(n, "reserve"));
};
Deque.prototype._Reserve = function (n) {
// NEW MEMBERS TO BE ASSSIGNED
var matrix = [[]];
var length = this._Compute_col_size(n);
//--------
// RE-FILL
//--------
for (var r = 0; r < this.matrix_.length; ++r) {
var row = this.matrix_[r];
for (var c = 0; c < row.length; ++c) {
var new_row = matrix[matrix.length - 1];
if (matrix.length < Deque.ROW_SIZE &&
new_row.length === length) {
new_row = [];
matrix.push(new_row);
}
new_row.push(row[c]);
}
}
// ASSIGN MEMBERS
this.matrix_ = matrix;
this.capacity_ = n;
};
/**
* Shrink {@link capacity} to actual {@link size}.
*/
Deque.prototype.shrink_to_fit = function () {
this._Reserve(this.size());
};
/**
* @inheritDoc
*/
Deque.prototype.swap = function (obj) {
this._Swap(obj);
};
Deque.prototype._Swap = function (obj) {
var _a, _b, _c;
// SWAP CONTENTS
_a = __read([obj.matrix_, this.matrix_], 2), this.matrix_ = _a[0], obj.matrix_ = _a[1];
_b = __read([obj.size_, this.size_], 2), this.size_ = _b[0], obj.size_ = _b[1];
_c = __read([obj.capacity_, this.capacity_], 2), this.capacity_ = _c[0], obj.capacity_ = _c[1];
};
Deque._Emend = function (n, method) {
n = Math.floor(n);
if (n <= 0)
throw new InvalidArgument_1.InvalidArgument("Error on Deque.".concat(method, "(): n must be positive integer -> (n = ").concat(n, ")"));
return n;
};
/* =========================================================
ACCESSORS
- BASIC ELEMENTS
- INDEX ACCESSORS
============================================================
BASIC ELEMENTS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
Deque.prototype.size = function () {
return this.size_;
};
/**
* The capacity to store elements.
*
* @return The capacity.
*/
Deque.prototype.capacity = function () {
return this.capacity_;
};
/**
* @inheritDoc
*/
Deque.prototype.nth = function (index) {
return new Deque.Iterator(this, index);
};
/**
* @inheritDoc
*/
Deque.prototype[Symbol.iterator] = function () {
return new Deque.ForOfAdaptor(this.matrix_);
};
Deque.prototype.source = function () {
return this;
};
/* ---------------------------------------------------------
INDEX ACCESSORS
--------------------------------------------------------- */
Deque.prototype._At = function (index) {
var indexPair = this._Fetch_index(index);
return this.matrix_[indexPair.first][indexPair.second];
};
Deque.prototype._Set = function (index, val) {
var indexPair = this._Fetch_index(index);
this.matrix_[indexPair.first][indexPair.second] = val;
};
Deque.prototype._Fetch_index = function (index) {
// Fetch row and column's index.
var row;
for (row = 0; row < this.matrix_.length; row++) {
var array = this.matrix_[row];
if (index < array.length)
break;
index -= array.length;
}
if (row === this.matrix_.length)
row--;
return new Pair_1.Pair(row, index);
};
Deque.prototype._Compute_col_size = function (capacity) {
if (capacity === void 0) { capacity = this.capacity_; }
// Get column size; {@link capacity_ capacity} / {@link ROW_SIZE row}.
return Math.floor(capacity / Deque.ROW_SIZE);
};
/* =========================================================
ELEMENTS I/O
- PUSH & POP
- INSERT
- ERASE
============================================================
PUSH & POP
--------------------------------------------------------- */
/**
* @inheritDoc
*/
Deque.prototype.push = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
if (items.length === 0)
return this.size();
// INSERT BY RANGE
var first = new NativeArrayIterator_1.NativeArrayIterator(items, 0);
var last = new NativeArrayIterator_1.NativeArrayIterator(items, items.length);
this._Insert_by_range(this.end(), first, last);
// RETURN SIZE
return this.size();
};
/**
* @inheritDoc
*/
Deque.prototype.push_front = function (val) {
// ADD CAPACITY & ROW
this._Try_expand_capacity(this.size_ + 1);
this._Try_add_row_at_front();
// INSERT VALUE
this.matrix_[0].unshift(val);
++this.size_;
};
/**
* @inheritDoc
*/
Deque.prototype.push_back = function (val) {
// ADD CAPACITY & ROW
this._Try_expand_capacity(this.size_ + 1);
this._Try_add_row_at_back();
// INSERT VALUE
this.matrix_[this.matrix_.length - 1].push(val);
++this.size_;
};
/**
* @inheritDoc
*/
Deque.prototype.pop_front = function () {
if (this.empty() === true)
throw ErrorGenerator_1.ErrorGenerator.empty(this.constructor, "pop_front");
// EREASE FIRST ELEMENT
this.matrix_[0].shift();
if (this.matrix_[0].length === 0 && this.matrix_.length > 1)
this.matrix_.shift();
// SHRINK SIZE
this.size_--;
};
Deque.prototype._Pop_back = function () {
// ERASE LAST ELEMENT
var lastArray = this.matrix_[this.matrix_.length - 1];
lastArray.pop();
if (lastArray.length === 0 && this.matrix_.length > 1)
this.matrix_.pop();
// SHRINK SIZE
this.size_--;
};
/* ---------------------------------------------------------
INSERT
--------------------------------------------------------- */
Deque.prototype._Insert_by_range = function (pos, first, last) {
var size = this.size_ + (0, global_1.distance)(first, last);
if (size === this.size_)
// FIRST === LAST
return pos;
if (pos.equals(this.end()) === true) {
// EXPAND CAPACITY IF REQUIRED
this._Try_expand_capacity(size);
// INSERT TO END
this._Insert_to_end(first, last);
// CHANGE POS TO RETURN
pos = this.nth(this.size_);
}
else {
// INSERT ITEMS IN THE MIDDLE
if (size > this.capacity_) {
// A TEMPORARY DEQUE
var deque = new Deque();
deque._Reserve(Math.max(size, Math.floor(this.capacity_ * Deque.MAGNIFIER)));
// INSERT ITEM SEQUENTIALLY
deque._Insert_to_end(this.begin(), pos);
deque._Insert_to_end(first, last);
deque._Insert_to_end(pos, this.end());
// AND SWAP THIS WITH THE TEMP
this._Swap(deque);
}
else
this._Insert_to_middle(pos, first, last);
}
this.size_ = size;
return pos;
};
Deque.prototype._Insert_to_middle = function (pos, first, last) {
var _a, _b;
var col_size = this._Compute_col_size();
// POSITION OF MATRIX
var indexes = this._Fetch_index(pos.index());
var row = this.matrix_[indexes.first];
var col = indexes.second;
// MOVE BACK SIDE TO TEMPORARY ARRAY
var back_items = row.splice(col);
// INSERT ITEMS
for (; !first.equals(last); first = first.next()) {
if (row.length === col_size &&
this.matrix_.length < Deque.ROW_SIZE) {
row = new Array();
var spliced_array = this.matrix_.splice(++indexes.first);
this.matrix_.push(row);
(_a = this.matrix_).push.apply(_a, __spreadArray([], __read(spliced_array), false));
}
row.push(first.value);
}
// INSERT ITEMS IN THE BACK SIDE
for (var i = 0; i < back_items.length; ++i) {
if (row.length === col_size &&
this.matrix_.length < Deque.ROW_SIZE) {
row = new Array();
var spliced_array = this.matrix_.splice(++indexes.first);
this.matrix_.push(row);
(_b = this.matrix_).push.apply(_b, __spreadArray([], __read(spliced_array), false));
}
row.push(back_items[i]);
}
};
Deque.prototype._Insert_to_end = function (first, last) {
// INSERT ITEMS IN THE BACK
for (; !first.equals(last); first = first.next()) {
// ADD ROW IF REQUIRED
this._Try_add_row_at_back();
// INSERT VALUE
this.matrix_[this.matrix_.length - 1].push(first.value);
}
};
Deque.prototype._Try_expand_capacity = function (size) {
if (size <= this.capacity_)
return false;
// MAX (CAPACITY * 1.5, TARGET SIZE)
size = Math.max(size, Math.floor(this.capacity_ * Deque.MAGNIFIER));
this._Reserve(size);
return true;
};
Deque.prototype._Try_add_row_at_front = function () {
var _a;
var col_size = this._Compute_col_size();
if (this.matrix_[0].length >= col_size &&
this.matrix_.length < Deque.ROW_SIZE) {
this.matrix_ = (_a = [[]]).concat.apply(_a, __spreadArray([], __read(this.matrix_), false));
return true;
}
else
return false;
};
Deque.prototype._Try_add_row_at_back = function () {
var col_size = this._Compute_col_size();
if (this.matrix_[this.matrix_.length - 1].length >= col_size &&
this.matrix_.length < Deque.ROW_SIZE) {
this.matrix_.push([]);
return true;
}
else
return false;
};
/* ---------------------------------------------------------
ERASE
--------------------------------------------------------- */
Deque.prototype._Erase_by_range = function (first, last) {
if (first.index() >= this.size())
return first;
// INDEXING
var size;
if (last.index() >= this.size())
// LAST IS END()
size = this.size() - first.index();
// LAST IS NOT END()
else
size = last.index() - first.index();
this.size_ -= size;
// ERASING
var first_row = null;
var second_row = null;
var i = 0;
while (size !== 0) {
// FIND MATCHED ROW AND COLUMN
var indexes = this._Fetch_index(first.index());
var row = this.matrix_[indexes.first];
var col = indexes.second;
// EARSE FROM THE ROW
var my_delete_size = Math.min(size, row.length - col);
row.splice(col, my_delete_size);
// TO MERGE
if (row.length !== 0)
if (i === 0)
first_row = row;
else
second_row = row;
// ERASE THE ENTIRE ROW IF REQUIRED
if (row.length === 0 && this.matrix_.length > 1)
this.matrix_.splice(indexes.first, 1);
// TO THE NEXT STEP
size -= my_delete_size;
++i;
}
// MERGE FIRST AND SECOND ROW
if (first_row !== null &&
second_row !== null &&
first_row.length + second_row.length <= this._Compute_col_size()) {
first_row.push.apply(first_row, __spreadArray([], __read(second_row), false));
this.matrix_.splice(this.matrix_.indexOf(second_row), 1);
}
return first;
};
return Deque;
}(ArrayContainer_1.ArrayContainer));
exports.Deque = Deque;
/**
*
*/
(function (Deque) {
// BODY
Deque.Iterator = ArrayIterator_1.ArrayIterator;
Deque.ReverseIterator = ArrayReverseIterator_1.ArrayReverseIterator;
//----
// CONSTANTS
//----
/**
* Row size of the {@link Deque.matrix_ matrix} which contains elements.
*
* Note that the {@link ROW_SIZE} affects on time complexity of accessing and inserting element.
* Accessing element is {@link ROW_SIZE} times slower than ordinary {@link Vector} and inserting element
* in middle position is {@link ROW_SIZE} times faster than ordinary {@link Vector}.
*
* When the {@link ROW_SIZE} returns 8, time complexity of accessing element is O(8) and inserting
* element in middle position is O(N/8). ({@link Vector}'s time complexity of accessement is O(1)
* and inserting element is O(N)).
*/
Deque.ROW_SIZE = 8;
/**
* Minimum {@link Deque.capacity}.
*
* Although a {@link Deque} has few elements, even no element is belonged to, the {@link Deque}
* keeps the minimum {@link Deque.capacity} at least.
*/
Deque.MIN_CAPACITY = 36;
/**
* Expansion ratio.
*/
Deque.MAGNIFIER = 1.5;
/**
* @internal
*/
var ForOfAdaptor = /** @class */ (function () {
function ForOfAdaptor(matrix) {
this.matrix_ = matrix;
this.row_ = 0;
this.col_ = 0;
}
ForOfAdaptor.prototype.next = function () {
if (this.row_ === this.matrix_.length)
return {
done: true,
value: undefined,
};
else {
var val = this.matrix_[this.row_][this.col_];
if (++this.col_ === this.matrix_[this.row_].length) {
++this.row_;
this.col_ = 0;
}
return {
done: false,
value: val,
};
}
};
ForOfAdaptor.prototype[Symbol.iterator] = function () {
return this;
};
return ForOfAdaptor;
}());
Deque.ForOfAdaptor = ForOfAdaptor;
})(Deque = exports.Deque || (exports.Deque = {}));
exports.Deque = Deque;
//# sourceMappingURL=Deque.js.map
+256
View File
@@ -0,0 +1,256 @@
/**
* @packageDocumentation
* @module std
*/
import { IForwardContainer } from "../ranges/container/IForwardContainer";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IClear } from "../internal/container/partial/IClear";
import { IEmpty } from "../internal/container/partial/IEmpty";
import { ISize } from "../internal/container/partial/ISize";
import { IDeque } from "../internal/container/partial/IDeque";
import { IFront } from "../internal/container/partial/IFront";
import { IListAlgorithm } from "../internal/container/linear/IListAlgorithm";
import { Comparator } from "../internal/functional/Comparator";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { UnaryPredicator } from "../internal/functional/UnaryPredicator";
/**
* Singly Linked List.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class ForwardList<T> implements IForwardContainer<ForwardList.Iterator<T>>, IClear, IEmpty, ISize, IDeque<T>, IFront<T>, Iterable<T>, IListAlgorithm<T, ForwardList<T>> {
private ptr_;
private size_;
private before_begin_;
private end_;
/**
* Default Constructor.
*/
constructor();
/**
* Initializer Constructor.
*
* @param items Items to assign.
*/
constructor(items: T[]);
/**
* Copy Constructor
*
* @param obj Object to copy.
*/
constructor(obj: ForwardList<T>);
/**
* Fill Constructor.
*
* @param size Initial size.
* @param val Value to fill.
*/
constructor(n: number, val: T);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
*/
constructor(first: Readonly<IForwardIterator<T>>, last: Readonly<IForwardIterator<T>>);
/**
* Fill Assigner.
*
* @param n Initial size.
* @param val Value to fill.
*/
assign(n: number, val: T): void;
/**
* Range Assigner.
*
* @param first Input iteartor of the first position.
* @param last Input iterator of the last position.
*/
assign<T, InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(first: InputIterator, last: InputIterator): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
size(): number;
/**
* @inheritDoc
*/
empty(): boolean;
/**
* @inheritDoc
*/
front(): T;
/**
* @inheritDoc
*/
front(val: T): void;
/**
* Iterator to before beginning.
*
* @return Iterator to the before beginning.
*/
before_begin(): ForwardList.Iterator<T>;
/**
* @inheritDoc
*/
begin(): ForwardList.Iterator<T>;
/**
* @inheritDoc
*/
end(): ForwardList.Iterator<T>;
/**
* @inheritDoc
*/
[Symbol.iterator](): IterableIterator<T>;
/**
* @inheritDoc
*/
push_front(val: T): void;
/**
* Insert an element.
*
* @param pos Position to insert after.
* @param val Value to insert.
* @return An iterator to the newly inserted element.
*/
insert_after(pos: ForwardList.Iterator<T>, val: T): ForwardList.Iterator<T>;
/**
* Inserted repeated elements.
*
* @param pos Position to insert after.
* @param n Number of elements to insert.
* @param val Value to insert repeatedly.
* @return An iterator to the last of the newly inserted elements.
*/
insert_after(pos: ForwardList.Iterator<T>, n: number, val: T): ForwardList.Iterator<T>;
/**
* Insert range elements.
*
* @param pos Position to insert after.
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
* @return An iterator to the last of the newly inserted elements.
*/
insert_after<T, InputIterator extends Readonly<IForwardIterator<T, InputIterator>>>(pos: ForwardList.Iterator<T>, first: InputIterator, last: InputIterator): ForwardList.Iterator<T>;
private _Insert_by_repeating_val;
private _Insert_by_range;
/**
* @inheritDoc
*/
pop_front(): void;
/**
* Erase an element.
*
* @param it Position to erase after.
* @return Iterator to the erased element.
*/
erase_after(it: ForwardList.Iterator<T>): ForwardList.Iterator<T>;
/**
* Erase elements.
*
* @param first Range of the first position to erase after.
* @param last Rangee of the last position to erase.
* @return Iterator to the last removed element.
*/
erase_after(first: ForwardList.Iterator<T>, last: ForwardList.Iterator<T>): ForwardList.Iterator<T>;
/**
* @inheritDoc
*/
unique(binary_pred?: BinaryPredicator<T>): void;
/**
* @inheritDoc
*/
remove(val: T): void;
/**
* @inheritDoc
*/
remove_if(pred: UnaryPredicator<T>): void;
/**
* @inheritDoc
*/
merge(from: ForwardList<T>, comp?: Comparator<T>): void;
/**
* Transfer elements.
*
* @param pos Position to insert after.
* @param from Target container to transfer.
*/
splice_after(pos: ForwardList.Iterator<T>, from: ForwardList<T>): void;
/**
* Transfer a single element.
*
* @param pos Position to insert after.
* @param from Target container to transfer.
* @param before Previous position of the single element to transfer.
*/
splice_after(pos: ForwardList.Iterator<T>, from: ForwardList<T>, before: ForwardList.Iterator<T>): void;
/**
* Transfer range elements.
*
* @param pos Position to insert after.
* @param from Target container to transfer.
* @param first Range of previous of the first position to transfer.
* @param last Rangee of the last position to transfer.
*/
splice_after(pos: ForwardList.Iterator<T>, from: ForwardList<T>, first_before: ForwardList.Iterator<T>, last: ForwardList.Iterator<T>): void;
/**
* @inheritDoc
*/
sort(comp?: Comparator<T>): void;
/**
* @inheritDoc
*/
reverse(): void;
/**
* @inheritDoc
*/
swap(obj: ForwardList<T>): void;
/**
* Native function for `JSON.stringify()`.
*
* @return An array containing children elements.
*/
toJSON(): Array<T>;
}
/**
*
*/
export declare namespace ForwardList {
/**
* Iterator of {@link ForwardList}
*
* @author Jeongho Nam - https://github.com/samchon
*/
class Iterator<T> implements IForwardIterator<T, Iterator<T>> {
private source_ptr_;
private next_;
private value_;
private constructor();
/**
* Get source container.
*
* @return The source container.
*/
source(): ForwardList<T>;
/**
* @inheritDoc
*/
get value(): T;
/**
* @inheritDoc
*/
set value(val: T);
private _Try_value;
/**
* @inheritDoc
*/
next(): Iterator<T>;
/**
* @inheritDoc
*/
equals(obj: Iterator<T>): boolean;
}
}
+424
View File
@@ -0,0 +1,424 @@
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForwardList = void 0;
var Repeater_1 = require("../internal/iterator/disposable/Repeater");
var ForOfAdaptor_1 = require("../internal/iterator/disposable/ForOfAdaptor");
var Vector_1 = require("./Vector");
var ErrorGenerator_1 = require("../internal/exception/ErrorGenerator");
var global_1 = require("../iterator/global");
var comparators_1 = require("../functional/comparators");
var sorting_1 = require("../algorithm/sorting");
/**
* Singly Linked List.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var ForwardList = /** @class */ (function () {
function ForwardList() {
var e_1, _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this.ptr_ = { value: this };
this.end_ = ForwardList.Iterator.create(this.ptr_, null);
this.before_begin_ = ForwardList.Iterator.create(this.ptr_, this.end_);
this.size_ = 0;
if (args.length === 1 && args[0] instanceof Array) {
var array = args[0];
var it = this.before_begin();
try {
for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
var val = array_1_1.value;
it = this.insert_after(it, val);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
}
finally { if (e_1) throw e_1.error; }
}
}
else if (args.length === 1 && args[0] instanceof ForwardList) {
this.assign(args[0].begin(), args[0].end());
}
else if (args.length === 2)
this.assign(args[0], args[1]);
}
ForwardList.prototype.assign = function (first, last) {
this.clear();
this.insert_after(this.before_begin_, first, last);
};
/**
* @inheritDoc
*/
ForwardList.prototype.clear = function () {
ForwardList.Iterator._Set_next(this.before_begin_, this.end_);
this.size_ = 0;
};
/* ===============================================================
ACCESSORS
=============================================================== */
/**
* @inheritDoc
*/
ForwardList.prototype.size = function () {
return this.size_;
};
/**
* @inheritDoc
*/
ForwardList.prototype.empty = function () {
return this.size_ === 0;
};
ForwardList.prototype.front = function (val) {
var it = this.begin();
if (arguments.length === 0)
return it.value;
else
it.value = val;
};
/**
* Iterator to before beginning.
*
* @return Iterator to the before beginning.
*/
ForwardList.prototype.before_begin = function () {
return this.before_begin_;
};
/**
* @inheritDoc
*/
ForwardList.prototype.begin = function () {
return this.before_begin_.next();
};
/**
* @inheritDoc
*/
ForwardList.prototype.end = function () {
return this.end_;
};
/**
* @inheritDoc
*/
ForwardList.prototype[Symbol.iterator] = function () {
return new ForOfAdaptor_1.ForOfAdaptor(this.begin(), this.end());
};
/* ===============================================================
ELEMENTS I/O
- INSERT
- ERASE
==================================================================
INSERT
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.push_front = function (val) {
this.insert_after(this.before_begin_, val);
};
ForwardList.prototype.insert_after = function (pos) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var ret;
// BRANCHES
if (args.length === 1)
ret = this._Insert_by_repeating_val(pos, 1, args[0]);
else if (typeof args[0] === "number")
ret = this._Insert_by_repeating_val(pos, args[0], args[1]);
else
ret = this._Insert_by_range(pos, args[0], args[1]);
// RETURNS
return ret;
};
ForwardList.prototype._Insert_by_repeating_val = function (pos, n, val) {
var first = new Repeater_1.Repeater(0, val);
var last = new Repeater_1.Repeater(n);
return this._Insert_by_range(pos, first, last);
};
ForwardList.prototype._Insert_by_range = function (pos, first, last) {
var nodes = [];
var count = 0;
for (; !first.equals(last); first = first.next()) {
var node = ForwardList.Iterator.create(this.ptr_, null, first.value);
nodes.push(node);
++count;
}
if (count === 0)
return pos;
for (var i = 0; i < count - 1; ++i)
ForwardList.Iterator._Set_next(nodes[i], nodes[i + 1]);
ForwardList.Iterator._Set_next(nodes[nodes.length - 1], pos.next());
ForwardList.Iterator._Set_next(pos, nodes[0]);
this.size_ += count;
return nodes[nodes.length - 1];
};
/* ---------------------------------------------------------------
ERASE
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.pop_front = function () {
this.erase_after(this.before_begin());
};
ForwardList.prototype.erase_after = function (first, last) {
if (last === void 0) { last = (0, global_1.advance)(first, 2); }
// SHRINK SIZE
this.size_ -= Math.max(0, (0, global_1.distance)(first, last) - 1);
// RE-CONNECT
ForwardList.Iterator._Set_next(first, last);
return last;
};
/* ===============================================================
ALGORITHMS
- UNIQUE & REMOVE(_IF)
- MERGE & SPLICE
- SORT
==================================================================
UNIQUE & REMOVE(_IF)
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.unique = function (binary_pred) {
if (binary_pred === void 0) { binary_pred = comparators_1.equal_to; }
for (var it = this.begin().next(); !it.equals(this.end()); it = it.next()) {
var next_it = it.next();
if (next_it.equals(this.end()))
break;
if (binary_pred(it.value, next_it.value))
this.erase_after(it);
}
};
/**
* @inheritDoc
*/
ForwardList.prototype.remove = function (val) {
return this.remove_if(function (elem) { return (0, comparators_1.equal_to)(elem, val); });
};
/**
* @inheritDoc
*/
ForwardList.prototype.remove_if = function (pred) {
var count = 0;
for (var it = this.before_begin(); !it.next().equals(this.end()); it = it.next())
if (pred(it.next().value) === true) {
ForwardList.Iterator._Set_next(it, it.next().next());
++count;
}
this.size_ -= count;
};
/* ---------------------------------------------------------------
MERGE & SPLICE
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.merge = function (from, comp) {
if (comp === void 0) { comp = comparators_1.less; }
if (this === from)
return;
var it = this.before_begin();
while (from.empty() === false) {
var value = from.begin().value;
while (!it.next().equals(this.end()) &&
comp(it.next().value, value))
it = it.next();
this.splice_after(it, from, from.before_begin());
}
};
ForwardList.prototype.splice_after = function (pos, from, first_before, last) {
if (first_before === void 0) { first_before = from.before_begin(); }
if (last === void 0) { last = first_before.next().next(); }
// DEFAULT PARAMETERS
if (last === null)
last = from.end();
// INSERT & ERASE
this.insert_after(pos, first_before.next(), last);
from.erase_after(first_before, last);
};
/* ---------------------------------------------------------------
SORT
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.sort = function (comp) {
if (comp === void 0) { comp = comparators_1.less; }
var vec = new Vector_1.Vector(this.begin(), this.end());
(0, sorting_1.sort)(vec.begin(), vec.end(), comp);
this.assign(vec.begin(), vec.end());
};
/**
* @inheritDoc
*/
ForwardList.prototype.reverse = function () {
var vec = new Vector_1.Vector(this.begin(), this.end());
this.assign(vec.rbegin(), vec.rend());
};
/* ---------------------------------------------------------------
UTILITIES
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
ForwardList.prototype.swap = function (obj) {
var _a, _b, _c, _d, _e;
// SIZE AND NODES
_a = __read([obj.size_, this.size_], 2), this.size_ = _a[0], obj.size_ = _a[1];
_b = __read([
obj.before_begin_,
this.before_begin_,
], 2), this.before_begin_ = _b[0], obj.before_begin_ = _b[1];
_c = __read([obj.end_, this.end_], 2), this.end_ = _c[0], obj.end_ = _c[1];
// POINTER OF THE SOURCE
_d = __read([obj.ptr_, this.ptr_], 2), this.ptr_ = _d[0], obj.ptr_ = _d[1];
_e = __read([obj.ptr_.value, this.ptr_.value], 2), this.ptr_.value = _e[0], obj.ptr_.value = _e[1];
};
/**
* Native function for `JSON.stringify()`.
*
* @return An array containing children elements.
*/
ForwardList.prototype.toJSON = function () {
var e_2, _a;
var ret = [];
try {
for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
var elem = _c.value;
ret.push(elem);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
return ret;
};
return ForwardList;
}());
exports.ForwardList = ForwardList;
/**
*
*/
(function (ForwardList) {
/**
* Iterator of {@link ForwardList}
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Iterator = /** @class */ (function () {
/* ---------------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------------- */
function Iterator(source, next, value) {
this.source_ptr_ = source;
this.next_ = next;
this.value_ = value;
}
/**
* @internal
*/
Iterator.create = function (source, next, value) {
return new Iterator(source, next, value);
};
/* ---------------------------------------------------------------
ACCESSORS
--------------------------------------------------------------- */
/**
* Get source container.
*
* @return The source container.
*/
Iterator.prototype.source = function () {
return this.source_ptr_.value;
};
Object.defineProperty(Iterator.prototype, "value", {
/**
* @inheritDoc
*/
get: function () {
this._Try_value();
return this.value_;
},
/**
* @inheritDoc
*/
set: function (val) {
this._Try_value();
this.value_ = val;
},
enumerable: false,
configurable: true
});
Iterator.prototype._Try_value = function () {
if (this.value_ === undefined) {
var source = this.source();
if (this.equals(source.end()) === true)
throw ErrorGenerator_1.ErrorGenerator.iterator_end_value(source);
else if (this.equals(source.before_begin()) === true)
throw ErrorGenerator_1.ErrorGenerator.iterator_end_value(source, "before_begin");
}
};
/* ---------------------------------------------------------
MOVERS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
Iterator.prototype.next = function () {
return this.next_;
};
/**
* @inheritDoc
*/
Iterator.prototype.equals = function (obj) {
return this === obj;
};
/**
* @internal
*/
Iterator._Set_next = function (it, next) {
it.next_ = next;
};
return Iterator;
}());
ForwardList.Iterator = Iterator;
})(ForwardList = exports.ForwardList || (exports.ForwardList = {}));
exports.ForwardList = ForwardList;
//# sourceMappingURL=ForwardList.js.map
+159
View File
@@ -0,0 +1,159 @@
/**
* @packageDocumentation
* @module std
*/
import { UniqueMap } from "../base/container/UniqueMap";
import { IHashMap } from "../base/container/IHashMap";
import { MapElementList } from "../internal/container/associative/MapElementList";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPair } from "../utility/IPair";
import { Pair } from "../utility/Pair";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { Hasher } from "../internal/functional/Hasher";
/**
* Unique-key Map based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class HashMap<Key, T> extends UniqueMap<Key, T, HashMap<Key, T>, HashMap.Iterator<Key, T>, HashMap.ReverseIterator<Key, T>> implements IHashMap<Key, T, true, HashMap<Key, T>> {
private buckets_;
/**
* Default Constructor.
*
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(items: IPair<Key, T>[], hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: HashMap<Key, T>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(first: Readonly<IForwardIterator<IPair<Key, T>>>, last: Readonly<IForwardIterator<IPair<Key, T>>>, hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: HashMap<Key, T>): void;
/**
* @inheritDoc
*/
find(key: Key): HashMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
begin(): HashMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
begin(index: number): HashMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
end(): HashMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
end(index: number): HashMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
rbegin(): HashMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rbegin(index: number): HashMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rend(): HashMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rend(index: number): HashMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
bucket_count(): number;
/**
* @inheritDoc
*/
bucket_size(index: number): number;
/**
* @inheritDoc
*/
load_factor(): number;
/**
* @inheritDoc
*/
hash_function(): Hasher<Key>;
/**
* @inheritDoc
*/
key_eq(): BinaryPredicator<Key>;
/**
* @inheritDoc
*/
bucket(key: Key): number;
/**
* @inheritDoc
*/
max_load_factor(): number;
/**
* @inheritDoc
*/
max_load_factor(z: number): void;
/**
* @inheritDoc
*/
reserve(n: number): void;
/**
* @inheritDoc
*/
rehash(n: number): void;
/**
* @inheritDoc
*/
emplace(key: Key, val: T): Pair<HashMap.Iterator<Key, T>, boolean>;
/**
* @inheritDoc
*/
emplace_hint(hint: HashMap.Iterator<Key, T>, key: Key, val: T): HashMap.Iterator<Key, T>;
protected _Handle_insert(first: HashMap.Iterator<Key, T>, last: HashMap.Iterator<Key, T>): void;
protected _Handle_erase(first: HashMap.Iterator<Key, T>, last: HashMap.Iterator<Key, T>): void;
}
/**
*
*/
export declare namespace HashMap {
/**
* Iterator of {@link HashMap}
*/
type Iterator<Key, T> = MapElementList.Iterator<Key, T, true, HashMap<Key, T>>;
/**
* Reverse iterator of {@link HashMap}
*/
type ReverseIterator<Key, T> = MapElementList.ReverseIterator<Key, T, true, HashMap<Key, T>>;
const Iterator: typeof MapElementList.Iterator;
const ReverseIterator: typeof MapElementList.ReverseIterator;
}
+249
View File
@@ -0,0 +1,249 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var UniqueMap_1 = require("../base/container/UniqueMap");
var IHashContainer_1 = require("../internal/container/associative/IHashContainer");
var MapElementList_1 = require("../internal/container/associative/MapElementList");
var MapHashBuckets_1 = require("../internal/hash/MapHashBuckets");
var Entry_1 = require("../utility/Entry");
var Pair_1 = require("../utility/Pair");
/**
* Unique-key Map based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var HashMap = /** @class */ (function (_super) {
__extends(HashMap, _super);
function HashMap() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new MapElementList_1.MapElementList(thisArg); }) || this;
IHashContainer_1.IHashContainer.construct.apply(IHashContainer_1.IHashContainer, __spreadArray([_this,
HashMap,
function (hash, pred) {
_this.buckets_ = new MapHashBuckets_1.MapHashBuckets(_this, hash, pred);
}], __read(args), false));
return _this;
}
/* ---------------------------------------------------------
ASSIGN & CLEAR
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMap.prototype.clear = function () {
this.buckets_.clear();
_super.prototype.clear.call(this);
};
/**
* @inheritDoc
*/
HashMap.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
MapElementList_1.MapElementList._Swap_associative(this.data_, obj.data_);
// SWAP BUCKETS
MapHashBuckets_1.MapHashBuckets._Swap_source(this.buckets_, obj.buckets_);
_b = __read([obj.buckets_, this.buckets_], 2), this.buckets_ = _b[0], obj.buckets_ = _b[1];
};
/* =========================================================
ACCESSORS
- MEMBER
- HASH
============================================================
MEMBER
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMap.prototype.find = function (key) {
return this.buckets_.find(key);
};
HashMap.prototype.begin = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.begin.call(this);
else
return this.buckets_.at(index)[0];
};
HashMap.prototype.end = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.end.call(this);
else {
var bucket = this.buckets_.at(index);
return bucket[bucket.length - 1].next();
}
};
HashMap.prototype.rbegin = function (index) {
if (index === void 0) { index = null; }
return this.end(index).reverse();
};
HashMap.prototype.rend = function (index) {
if (index === void 0) { index = null; }
return this.begin(index).reverse();
};
/* ---------------------------------------------------------
HASH
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMap.prototype.bucket_count = function () {
return this.buckets_.length();
};
/**
* @inheritDoc
*/
HashMap.prototype.bucket_size = function (index) {
return this.buckets_.at(index).length;
};
/**
* @inheritDoc
*/
HashMap.prototype.load_factor = function () {
return this.buckets_.load_factor();
};
/**
* @inheritDoc
*/
HashMap.prototype.hash_function = function () {
return this.buckets_.hash_function();
};
/**
* @inheritDoc
*/
HashMap.prototype.key_eq = function () {
return this.buckets_.key_eq();
};
/**
* @inheritDoc
*/
HashMap.prototype.bucket = function (key) {
return this.hash_function()(key) % this.buckets_.length();
};
HashMap.prototype.max_load_factor = function (z) {
if (z === void 0) { z = null; }
return this.buckets_.max_load_factor(z);
};
/**
* @inheritDoc
*/
HashMap.prototype.reserve = function (n) {
this.buckets_.reserve(n);
};
/**
* @inheritDoc
*/
HashMap.prototype.rehash = function (n) {
this.buckets_.rehash(n);
};
/* =========================================================
ELEMENTS I/O
- INSERT
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMap.prototype.emplace = function (key, val) {
// TEST WHETHER EXIST
var it = this.find(key);
if (it.equals(this.end()) === false)
return new Pair_1.Pair(it, false);
// INSERT
this.data_.push(new Entry_1.Entry(key, val));
it = it.prev();
// POST-PROCESS
this._Handle_insert(it, it.next());
return new Pair_1.Pair(it, true);
};
/**
* @inheritDoc
*/
HashMap.prototype.emplace_hint = function (hint, key, val) {
// FIND DUPLICATED KEY
var it = this.find(key);
if (it.equals(this.end()) === true) {
// INSERT
it = this.data_.insert(hint, new Entry_1.Entry(key, val));
// POST-PROCESS
this._Handle_insert(it, it.next());
}
return it;
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
HashMap.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.insert(first);
};
HashMap.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.erase(first);
};
return HashMap;
}(UniqueMap_1.UniqueMap));
exports.HashMap = HashMap;
/**
*
*/
(function (HashMap) {
// BODY
HashMap.Iterator = MapElementList_1.MapElementList.Iterator;
HashMap.ReverseIterator = MapElementList_1.MapElementList.ReverseIterator;
})(HashMap = exports.HashMap || (exports.HashMap = {}));
exports.HashMap = HashMap;
//# sourceMappingURL=HashMap.js.map
+164
View File
@@ -0,0 +1,164 @@
/**
* @packageDocumentation
* @module std
*/
import { MultiMap } from "../base/container/MultiMap";
import { IHashMap } from "../base/container/IHashMap";
import { MapElementList } from "../internal/container/associative/MapElementList";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPair } from "../utility/IPair";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { Hasher } from "../internal/functional/Hasher";
/**
* Multiple-key Map based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class HashMultiMap<Key, T> extends MultiMap<Key, T, HashMultiMap<Key, T>, HashMultiMap.Iterator<Key, T>, HashMultiMap.ReverseIterator<Key, T>> implements IHashMap<Key, T, false, HashMultiMap<Key, T>> {
private buckets_;
/**
* Default Constructor.
*
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(items: IPair<Key, T>[], hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: HashMultiMap<Key, T>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(first: Readonly<IForwardIterator<IPair<Key, T>>>, last: Readonly<IForwardIterator<IPair<Key, T>>>, hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: HashMultiMap<Key, T>): void;
/**
* @inheritDoc
*/
find(key: Key): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
count(key: Key): number;
/**
* @inheritDoc
*/
begin(): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
begin(index: number): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
end(): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
end(index: number): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
rbegin(): HashMultiMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rbegin(index: number): HashMultiMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rend(): HashMultiMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
rend(index: number): HashMultiMap.ReverseIterator<Key, T>;
/**
* @inheritDoc
*/
bucket_count(): number;
/**
* @inheritDoc
*/
bucket_size(index: number): number;
/**
* @inheritDoc
*/
load_factor(): number;
/**
* @inheritDoc
*/
hash_function(): Hasher<Key>;
/**
* @inheritDoc
*/
key_eq(): BinaryPredicator<Key>;
/**
* @inheritDoc
*/
bucket(key: Key): number;
/**
* @inheritDoc
*/
max_load_factor(): number;
/**
* @inheritDoc
*/
max_load_factor(z: number): void;
/**
* @inheritDoc
*/
reserve(n: number): void;
/**
* @inheritDoc
*/
rehash(n: number): void;
protected _Key_eq(x: Key, y: Key): boolean;
/**
* @inheritDoc
*/
emplace(key: Key, val: T): HashMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
emplace_hint(hint: HashMultiMap.Iterator<Key, T>, key: Key, val: T): HashMultiMap.Iterator<Key, T>;
protected _Insert_by_range<InputIterator extends Readonly<IForwardIterator<IPair<Key, T>, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected _Handle_insert(first: HashMultiMap.Iterator<Key, T>, last: HashMultiMap.Iterator<Key, T>): void;
protected _Handle_erase(first: HashMultiMap.Iterator<Key, T>, last: HashMultiMap.Iterator<Key, T>): void;
}
/**
*
*/
export declare namespace HashMultiMap {
/**
* Iterator of {@link HashMultiMap}
*/
type Iterator<Key, T> = MapElementList.Iterator<Key, T, false, HashMultiMap<Key, T>>;
/**
* Reverse iterator of {@link HashMultiMap}
*/
type ReverseIterator<Key, T> = MapElementList.ReverseIterator<Key, T, false, HashMultiMap<Key, T>>;
const Iterator: typeof MapElementList.Iterator;
const ReverseIterator: typeof MapElementList.ReverseIterator;
}
+300
View File
@@ -0,0 +1,300 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashMultiMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var MultiMap_1 = require("../base/container/MultiMap");
var IHashContainer_1 = require("../internal/container/associative/IHashContainer");
var MapElementList_1 = require("../internal/container/associative/MapElementList");
var MapHashBuckets_1 = require("../internal/hash/MapHashBuckets");
var NativeArrayIterator_1 = require("../internal/iterator/disposable/NativeArrayIterator");
var Entry_1 = require("../utility/Entry");
/**
* Multiple-key Map based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var HashMultiMap = /** @class */ (function (_super) {
__extends(HashMultiMap, _super);
function HashMultiMap() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new MapElementList_1.MapElementList(thisArg); }) || this;
IHashContainer_1.IHashContainer.construct.apply(IHashContainer_1.IHashContainer, __spreadArray([_this,
HashMultiMap,
function (hash, pred) {
_this.buckets_ = new MapHashBuckets_1.MapHashBuckets(_this, hash, pred);
}], __read(args), false));
return _this;
}
/* ---------------------------------------------------------
ASSIGN & CLEAR
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiMap.prototype.clear = function () {
this.buckets_.clear();
_super.prototype.clear.call(this);
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
MapElementList_1.MapElementList._Swap_associative(this.data_, obj.data_);
// SWAP BUCKETS
MapHashBuckets_1.MapHashBuckets._Swap_source(this.buckets_, obj.buckets_);
_b = __read([obj.buckets_, this.buckets_], 2), this.buckets_ = _b[0], obj.buckets_ = _b[1];
};
/* =========================================================
ACCESSORS
- MEMBER
- HASH
============================================================
MEMBER
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiMap.prototype.find = function (key) {
return this.buckets_.find(key);
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.count = function (key) {
var e_1, _a;
// FIND MATCHED BUCKET
var index = this.bucket(key);
var bucket = this.buckets_.at(index);
// ITERATE THE BUCKET
var cnt = 0;
try {
for (var bucket_1 = __values(bucket), bucket_1_1 = bucket_1.next(); !bucket_1_1.done; bucket_1_1 = bucket_1.next()) {
var it = bucket_1_1.value;
if (this.buckets_.key_eq()(it.first, key))
++cnt;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (bucket_1_1 && !bucket_1_1.done && (_a = bucket_1.return)) _a.call(bucket_1);
}
finally { if (e_1) throw e_1.error; }
}
return cnt;
};
HashMultiMap.prototype.begin = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.begin.call(this);
else
return this.buckets_.at(index)[0];
};
HashMultiMap.prototype.end = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.end.call(this);
else {
var bucket = this.buckets_.at(index);
return bucket[bucket.length - 1].next();
}
};
HashMultiMap.prototype.rbegin = function (index) {
if (index === void 0) { index = null; }
return this.end(index).reverse();
};
HashMultiMap.prototype.rend = function (index) {
if (index === void 0) { index = null; }
return this.begin(index).reverse();
};
/* ---------------------------------------------------------
HASH
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiMap.prototype.bucket_count = function () {
return this.buckets_.length();
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.bucket_size = function (index) {
return this.buckets_.at(index).length;
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.load_factor = function () {
return this.buckets_.load_factor();
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.hash_function = function () {
return this.buckets_.hash_function();
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.key_eq = function () {
return this.buckets_.key_eq();
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.bucket = function (key) {
return this.hash_function()(key) % this.buckets_.length();
};
HashMultiMap.prototype.max_load_factor = function (z) {
if (z === void 0) { z = null; }
return this.buckets_.max_load_factor(z);
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.reserve = function (n) {
this.buckets_.reserve(n);
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.rehash = function (n) {
if (n <= this.bucket_count())
return;
this.buckets_.rehash(n);
};
HashMultiMap.prototype._Key_eq = function (x, y) {
return this.key_eq()(x, y);
};
/* =========================================================
ELEMENTS I/O
- INSERT
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiMap.prototype.emplace = function (key, val) {
// INSERT
var it = this.data_.insert(this.data_.end(), new Entry_1.Entry(key, val));
this._Handle_insert(it, it.next()); // POST-PROCESS
return it;
};
/**
* @inheritDoc
*/
HashMultiMap.prototype.emplace_hint = function (hint, key, val) {
// INSERT
var it = this.data_.insert(hint, new Entry_1.Entry(key, val));
// POST-PROCESS
this._Handle_insert(it, it.next());
return it;
};
HashMultiMap.prototype._Insert_by_range = function (first, last) {
//--------
// INSERTIONS
//--------
// PRELIMINARIES
var entries = [];
for (var it = first; !it.equals(last); it = it.next())
entries.push(new Entry_1.Entry(it.value.first, it.value.second));
// INSERT ELEMENTS
var my_first = this.data_.insert(this.data_.end(), new NativeArrayIterator_1.NativeArrayIterator(entries, 0), new NativeArrayIterator_1.NativeArrayIterator(entries, entries.length));
//--------
// HASHING INSERTED ITEMS
//--------
// IF NEEDED, HASH_BUCKET TO HAVE SUITABLE SIZE
if (this.size() > this.buckets_.capacity())
this.reserve(Math.max(this.size(), this.buckets_.capacity() * 2));
// POST-PROCESS
this._Handle_insert(my_first, this.end());
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
HashMultiMap.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.insert(first);
};
HashMultiMap.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.erase(first);
};
return HashMultiMap;
}(MultiMap_1.MultiMap));
exports.HashMultiMap = HashMultiMap;
/**
*
*/
(function (HashMultiMap) {
// BODY
HashMultiMap.Iterator = MapElementList_1.MapElementList.Iterator;
HashMultiMap.ReverseIterator = MapElementList_1.MapElementList.ReverseIterator;
})(HashMultiMap = exports.HashMultiMap || (exports.HashMultiMap = {}));
exports.HashMultiMap = HashMultiMap;
//# sourceMappingURL=HashMultiMap.js.map
+157
View File
@@ -0,0 +1,157 @@
/**
* @packageDocumentation
* @module std
*/
import { MultiSet } from "../base/container/MultiSet";
import { IHashSet } from "../base/container/IHashSet";
import { SetElementList } from "../internal/container/associative/SetElementList";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { Hasher } from "../internal/functional/Hasher";
/**
* Multiple-key Set based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class HashMultiSet<Key> extends MultiSet<Key, HashMultiSet<Key>, HashMultiSet.Iterator<Key>, HashMultiSet.ReverseIterator<Key>> implements IHashSet<Key, false, HashMultiSet<Key>> {
private buckets_;
/**
* Default Constructor.
*
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(items: Key[], hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: HashMultiSet<Key>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(first: Readonly<IForwardIterator<Key>>, last: Readonly<IForwardIterator<Key>>, hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: HashMultiSet<Key>): void;
/**
* @inheritDoc
*/
find(key: Key): HashMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
count(key: Key): number;
/**
* @inheritDoc
*/
begin(): HashMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
begin(index: number): HashMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
end(): HashMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
end(index: number): HashMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
rbegin(): HashMultiSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rbegin(index: number): HashMultiSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rend(): HashMultiSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rend(index: number): HashMultiSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
bucket_count(): number;
/**
* @inheritDoc
*/
bucket_size(n: number): number;
/**
* @inheritDoc
*/
load_factor(): number;
/**
* @inheritDoc
*/
hash_function(): Hasher<Key>;
/**
* @inheritDoc
*/
key_eq(): BinaryPredicator<Key>;
/**
* @inheritDoc
*/
bucket(key: Key): number;
/**
* @inheritDoc
*/
max_load_factor(): number;
/**
* @inheritDoc
*/
max_load_factor(z: number): void;
/**
* @inheritDoc
*/
reserve(n: number): void;
/**
* @inheritDoc
*/
rehash(n: number): void;
protected _Key_eq(x: Key, y: Key): boolean;
protected _Insert_by_key(key: Key): HashMultiSet.Iterator<Key>;
protected _Insert_by_hint(hint: HashMultiSet.Iterator<Key>, key: Key): HashMultiSet.Iterator<Key>;
protected _Insert_by_range<InputIterator extends Readonly<IForwardIterator<Key, InputIterator>>>(first: InputIterator, last: InputIterator): void;
protected _Handle_insert(first: HashMultiSet.Iterator<Key>, last: HashMultiSet.Iterator<Key>): void;
protected _Handle_erase(first: HashMultiSet.Iterator<Key>, last: HashMultiSet.Iterator<Key>): void;
}
/**
*
*/
export declare namespace HashMultiSet {
/**
* Iterator of {@link HashMultiSet}
*/
type Iterator<Key> = SetElementList.Iterator<Key, false, HashMultiSet<Key>>;
/**
* Reverse iterator of {@link HashMultiSet}
*/
type ReverseIterator<Key> = SetElementList.ReverseIterator<Key, false, HashMultiSet<Key>>;
const Iterator: typeof SetElementList.Iterator;
const ReverseIterator: typeof SetElementList.ReverseIterator;
}
+282
View File
@@ -0,0 +1,282 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashMultiSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var MultiSet_1 = require("../base/container/MultiSet");
var IHashContainer_1 = require("../internal/container/associative/IHashContainer");
var SetElementList_1 = require("../internal/container/associative/SetElementList");
var SetHashBuckets_1 = require("../internal/hash/SetHashBuckets");
/**
* Multiple-key Set based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var HashMultiSet = /** @class */ (function (_super) {
__extends(HashMultiSet, _super);
function HashMultiSet() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new SetElementList_1.SetElementList(thisArg); }) || this;
IHashContainer_1.IHashContainer.construct.apply(IHashContainer_1.IHashContainer, __spreadArray([_this,
HashMultiSet,
function (hash, pred) {
_this.buckets_ = new SetHashBuckets_1.SetHashBuckets(_this, hash, pred);
}], __read(args), false));
return _this;
}
/* ---------------------------------------------------------
ASSIGN & CLEAR
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiSet.prototype.clear = function () {
this.buckets_.clear();
_super.prototype.clear.call(this);
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
SetElementList_1.SetElementList._Swap_associative(this.data_, obj.data_);
// SWAP BUCKETS
SetHashBuckets_1.SetHashBuckets._Swap_source(this.buckets_, obj.buckets_);
_b = __read([obj.buckets_, this.buckets_], 2), this.buckets_ = _b[0], obj.buckets_ = _b[1];
};
/* =========================================================
ACCESSORS
- MEMBER
- HASH
============================================================
MEMBER
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiSet.prototype.find = function (key) {
return this.buckets_.find(key);
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.count = function (key) {
var e_1, _a;
// FIND MATCHED BUCKET
var index = this.bucket(key);
var bucket = this.buckets_.at(index);
// ITERATE THE BUCKET
var cnt = 0;
try {
for (var bucket_1 = __values(bucket), bucket_1_1 = bucket_1.next(); !bucket_1_1.done; bucket_1_1 = bucket_1.next()) {
var it = bucket_1_1.value;
if (this.buckets_.key_eq()(it.value, key))
++cnt;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (bucket_1_1 && !bucket_1_1.done && (_a = bucket_1.return)) _a.call(bucket_1);
}
finally { if (e_1) throw e_1.error; }
}
return cnt;
};
HashMultiSet.prototype.begin = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.begin.call(this);
else
return this.buckets_.at(index)[0];
};
HashMultiSet.prototype.end = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.end.call(this);
else {
var bucket = this.buckets_.at(index);
return bucket[bucket.length - 1].next();
}
};
HashMultiSet.prototype.rbegin = function (index) {
if (index === void 0) { index = null; }
return this.end(index).reverse();
};
HashMultiSet.prototype.rend = function (index) {
if (index === void 0) { index = null; }
return this.begin(index).reverse();
};
/* ---------------------------------------------------------
HASH
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashMultiSet.prototype.bucket_count = function () {
return this.buckets_.length();
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.bucket_size = function (n) {
return this.buckets_.at(n).length;
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.load_factor = function () {
return this.buckets_.load_factor();
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.hash_function = function () {
return this.buckets_.hash_function();
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.key_eq = function () {
return this.buckets_.key_eq();
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.bucket = function (key) {
return this.hash_function()(key) % this.buckets_.length();
};
HashMultiSet.prototype.max_load_factor = function (z) {
if (z === void 0) { z = null; }
return this.buckets_.max_load_factor(z);
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.reserve = function (n) {
this.buckets_.rehash(Math.ceil(n * this.max_load_factor()));
};
/**
* @inheritDoc
*/
HashMultiSet.prototype.rehash = function (n) {
if (n <= this.bucket_count())
return;
this.buckets_.rehash(n);
};
HashMultiSet.prototype._Key_eq = function (x, y) {
return this.key_eq()(x, y);
};
/* =========================================================
ELEMENTS I/O
- INSERT
- POST-PROCESS
============================================================
INSERT
--------------------------------------------------------- */
HashMultiSet.prototype._Insert_by_key = function (key) {
// INSERT
var it = this.data_.insert(this.data_.end(), key);
this._Handle_insert(it, it.next()); // POST-PROCESS
return it;
};
HashMultiSet.prototype._Insert_by_hint = function (hint, key) {
// INSERT
var it = this.data_.insert(hint, key);
// POST-PROCESS
this._Handle_insert(it, it.next());
return it;
};
HashMultiSet.prototype._Insert_by_range = function (first, last) {
// INSERT ELEMENTS
var my_first = this.data_.insert(this.data_.end(), first, last);
// IF NEEDED, HASH_BUCKET TO HAVE SUITABLE SIZE
if (this.size() > this.buckets_.capacity())
this.reserve(Math.max(this.size(), this.buckets_.capacity() * 2));
// POST-PROCESS
this._Handle_insert(my_first, this.end());
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
HashMultiSet.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.insert(first);
};
HashMultiSet.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.erase(first);
};
return HashMultiSet;
}(MultiSet_1.MultiSet));
exports.HashMultiSet = HashMultiSet;
/**
*
*/
(function (HashMultiSet) {
// BODY
HashMultiSet.Iterator = SetElementList_1.SetElementList.Iterator;
HashMultiSet.ReverseIterator = SetElementList_1.SetElementList.ReverseIterator;
})(HashMultiSet = exports.HashMultiSet || (exports.HashMultiSet = {}));
exports.HashMultiSet = HashMultiSet;
//# sourceMappingURL=HashMultiSet.js.map
+152
View File
@@ -0,0 +1,152 @@
/**
* @packageDocumentation
* @module std
*/
import { UniqueSet } from "../base/container/UniqueSet";
import { IHashSet } from "../base/container/IHashSet";
import { SetElementList } from "../internal/container/associative/SetElementList";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { Pair } from "../utility/Pair";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { Hasher } from "../internal/functional/Hasher";
/**
* Unique-key Set based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class HashSet<Key> extends UniqueSet<Key, HashSet<Key>, HashSet.Iterator<Key>, HashSet.ReverseIterator<Key>> implements IHashSet<Key, true, HashSet<Key>> {
private buckets_;
/**
* Default Constructor.
*
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(items: Key[], hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: HashSet<Key>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param hash An unary function returns hash code. Default is {hash}.
* @param equal A binary function predicates two arguments are equal. Default is {@link equal_to}.
*/
constructor(first: Readonly<IForwardIterator<Key>>, last: Readonly<IForwardIterator<Key>>, hash?: Hasher<Key>, equal?: BinaryPredicator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: HashSet<Key>): void;
/**
* @inheritDoc
*/
find(key: Key): HashSet.Iterator<Key>;
/**
* @inheritDoc
*/
begin(): HashSet.Iterator<Key>;
/**
* @inheritDoc
*/
begin(index: number): HashSet.Iterator<Key>;
/**
* @inheritDoc
*/
end(): HashSet.Iterator<Key>;
/**
* @inheritDoc
*/
end(index: number): HashSet.Iterator<Key>;
/**
* @inheritDoc
*/
rbegin(): HashSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rbegin(index: number): HashSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rend(): HashSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
rend(index: number): HashSet.ReverseIterator<Key>;
/**
* @inheritDoc
*/
bucket_count(): number;
/**
* @inheritDoc
*/
bucket_size(n: number): number;
/**
* @inheritDoc
*/
load_factor(): number;
/**
* @inheritDoc
*/
hash_function(): Hasher<Key>;
/**
* @inheritDoc
*/
key_eq(): BinaryPredicator<Key>;
/**
* @inheritDoc
*/
bucket(key: Key): number;
/**
* @inheritDoc
*/
max_load_factor(): number;
/**
* @inheritDoc
*/
max_load_factor(z: number): void;
/**
* @inheritDoc
*/
reserve(n: number): void;
/**
* @inheritDoc
*/
rehash(n: number): void;
protected _Insert_by_key(key: Key): Pair<HashSet.Iterator<Key>, boolean>;
protected _Insert_by_hint(hint: HashSet.Iterator<Key>, key: Key): HashSet.Iterator<Key>;
protected _Handle_insert(first: HashSet.Iterator<Key>, last: HashSet.Iterator<Key>): void;
protected _Handle_erase(first: HashSet.Iterator<Key>, last: HashSet.Iterator<Key>): void;
}
/**
*
*/
export declare namespace HashSet {
/**
* Iterator of {@link HashSet}
*/
type Iterator<Key> = SetElementList.Iterator<Key, true, HashSet<Key>>;
/**
* Reverse iterator of {@link HashSet}
*/
type ReverseIterator<Key> = SetElementList.ReverseIterator<Key, true, HashSet<Key>>;
const Iterator: typeof SetElementList.Iterator;
const ReverseIterator: typeof SetElementList.ReverseIterator;
}
+243
View File
@@ -0,0 +1,243 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var UniqueSet_1 = require("../base/container/UniqueSet");
var IHashContainer_1 = require("../internal/container/associative/IHashContainer");
var SetElementList_1 = require("../internal/container/associative/SetElementList");
var SetHashBuckets_1 = require("../internal/hash/SetHashBuckets");
var Pair_1 = require("../utility/Pair");
/**
* Unique-key Set based on Hash buckets.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var HashSet = /** @class */ (function (_super) {
__extends(HashSet, _super);
function HashSet() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new SetElementList_1.SetElementList(thisArg); }) || this;
IHashContainer_1.IHashContainer.construct.apply(IHashContainer_1.IHashContainer, __spreadArray([_this,
HashSet,
function (hash, pred) {
_this.buckets_ = new SetHashBuckets_1.SetHashBuckets(_this, hash, pred);
}], __read(args), false));
return _this;
}
/* ---------------------------------------------------------
ASSIGN & CLEAR
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashSet.prototype.clear = function () {
this.buckets_.clear();
_super.prototype.clear.call(this);
};
/**
* @inheritDoc
*/
HashSet.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
SetElementList_1.SetElementList._Swap_associative(this.data_, obj.data_);
// SWAP BUCKETS
SetHashBuckets_1.SetHashBuckets._Swap_source(this.buckets_, obj.buckets_);
_b = __read([obj.buckets_, this.buckets_], 2), this.buckets_ = _b[0], obj.buckets_ = _b[1];
};
/* =========================================================
ACCESSORS
- MEMBER
- HASH
============================================================
MEMBER
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashSet.prototype.find = function (key) {
return this.buckets_.find(key);
};
HashSet.prototype.begin = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.begin.call(this);
else
return this.buckets_.at(index)[0];
};
HashSet.prototype.end = function (index) {
if (index === void 0) { index = null; }
if (index === null)
return _super.prototype.end.call(this);
else {
var bucket = this.buckets_.at(index);
return bucket[bucket.length - 1].next();
}
};
HashSet.prototype.rbegin = function (index) {
if (index === void 0) { index = null; }
return this.end(index).reverse();
};
HashSet.prototype.rend = function (index) {
if (index === void 0) { index = null; }
return this.begin(index).reverse();
};
/* ---------------------------------------------------------
HASH
--------------------------------------------------------- */
/**
* @inheritDoc
*/
HashSet.prototype.bucket_count = function () {
return this.buckets_.length();
};
/**
* @inheritDoc
*/
HashSet.prototype.bucket_size = function (n) {
return this.buckets_.at(n).length;
};
/**
* @inheritDoc
*/
HashSet.prototype.load_factor = function () {
return this.buckets_.load_factor();
};
/**
* @inheritDoc
*/
HashSet.prototype.hash_function = function () {
return this.buckets_.hash_function();
};
/**
* @inheritDoc
*/
HashSet.prototype.key_eq = function () {
return this.buckets_.key_eq();
};
/**
* @inheritDoc
*/
HashSet.prototype.bucket = function (key) {
return this.hash_function()(key) % this.buckets_.length();
};
HashSet.prototype.max_load_factor = function (z) {
if (z === void 0) { z = null; }
return this.buckets_.max_load_factor(z);
};
/**
* @inheritDoc
*/
HashSet.prototype.reserve = function (n) {
this.buckets_.reserve(n);
};
/**
* @inheritDoc
*/
HashSet.prototype.rehash = function (n) {
this.buckets_.rehash(n);
};
/* =========================================================
ELEMENTS I/O
- INSERT
- POST-PROCESS
- SWAP
============================================================
INSERT
--------------------------------------------------------- */
HashSet.prototype._Insert_by_key = function (key) {
// TEST WHETHER EXIST
var it = this.find(key);
if (it.equals(this.end()) === false)
return new Pair_1.Pair(it, false);
// INSERT
this.data_.push(key);
it = it.prev();
// POST-PROCESS
this._Handle_insert(it, it.next());
return new Pair_1.Pair(it, true);
};
HashSet.prototype._Insert_by_hint = function (hint, key) {
// FIND DUPLICATED KEY
var it = this.find(key);
if (it.equals(this.end()) === true) {
// INSERT
it = this.data_.insert(hint, key);
// POST-PROCESS
this._Handle_insert(it, it.next());
}
return it;
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
HashSet.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.insert(first);
};
HashSet.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.buckets_.erase(first);
};
return HashSet;
}(UniqueSet_1.UniqueSet));
exports.HashSet = HashSet;
/**
*
*/
(function (HashSet) {
// BODY
HashSet.Iterator = SetElementList_1.SetElementList.Iterator;
HashSet.ReverseIterator = SetElementList_1.SetElementList.ReverseIterator;
})(HashSet = exports.HashSet || (exports.HashSet = {}));
exports.HashSet = HashSet;
//# sourceMappingURL=HashSet.js.map
+169
View File
@@ -0,0 +1,169 @@
/**
* @packageDocumentation
* @module std
*/
import { ListContainer } from "../internal/container/linear/ListContainer";
import { IDequeContainer } from "../base/container/IDequeContainer";
import { IListAlgorithm } from "../internal/container/linear/IListAlgorithm";
import { ListIterator } from "../internal/iterator/ListIterator";
import { ReverseIterator as ReverseIteratorBase } from "../internal/iterator/ReverseIterator";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { BinaryPredicator } from "../internal/functional/BinaryPredicator";
import { Comparator } from "../internal/functional/Comparator";
import { UnaryPredicator } from "../internal/functional/UnaryPredicator";
/**
* Doubly Linked List.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class List<T> extends ListContainer<T, List<T>, List.Iterator<T>, List.ReverseIterator<T>> implements IDequeContainer<T, List<T>, List.Iterator<T>, List.ReverseIterator<T>>, IListAlgorithm<T, List<T>> {
private ptr_;
/**
* Default Constructor.
*/
constructor();
/**
* Initializer Constructor.
*
* @param items Items to assign.
*/
constructor(items: Array<T>);
/**
* Copy Constructor
*
* @param obj Object to copy.
*/
constructor(obj: List<T>);
/**
* Fill Constructor.
*
* @param size Initial size.
* @param val Value to fill.
*/
constructor(size: number, val: T);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
constructor(first: Readonly<IForwardIterator<T>>, last: Readonly<IForwardIterator<T>>);
protected _Create_iterator(prev: List.Iterator<T>, next: List.Iterator<T>, val: T): List.Iterator<T>;
/**
* @inheritDoc
*/
front(): T;
/**
* @inheritDoc
*/
front(val: T): void;
/**
* @inheritDoc
*/
back(): T;
/**
* @inheritDoc
*/
back(val: T): void;
/**
* @inheritDoc
*/
unique(binary_pred?: BinaryPredicator<T>): void;
/**
* @inheritDoc
*/
remove(val: T): void;
/**
* @inheritDoc
*/
remove_if(pred: UnaryPredicator<T>): void;
/**
* @inheritDoc
*/
merge(source: List<T>, comp?: Comparator<T>): void;
/**
* Transfer elements.
*
* @param pos Position to insert.
* @param from Target container to transfer.
*/
splice(pos: List.Iterator<T>, from: List<T>): void;
/**
* Transfer a single element.
*
* @param pos Position to insert.
* @param from Target container to transfer.
* @param it Position of the single element to transfer.
*/
splice(pos: List.Iterator<T>, from: List<T>, it: List.Iterator<T>): void;
/**
* Transfer range elements.
*
* @param pos Position to insert.
* @param from Target container to transfer.
* @param first Range of the first position to transfer.
* @param last Rangee of the last position to transfer.
*/
splice(pos: List.Iterator<T>, from: List<T>, first: List.Iterator<T>, last: List.Iterator<T>): void;
/**
* @inheritDoc
*/
sort(comp?: Comparator<T>): void;
private _Quick_sort;
private _Quick_sort_partition;
/**
* @inheritDoc
*/
reverse(): void;
/**
* @inheritDoc
*/
swap(obj: List<T>): void;
}
/**
*
*/
export declare namespace List {
/**
* Iterator of {@link List}
*
* @author Jeongho Nam - https://github.com/samchon
*/
class Iterator<T> extends ListIterator<T, List<T>, Iterator<T>, ReverseIterator<T>, T> {
private source_ptr_;
private constructor();
/**
* @inheritDoc
*/
reverse(): ReverseIterator<T>;
/**
* @inheritDoc
*/
source(): List<T>;
/**
* @inheritDoc
*/
get value(): T;
/**
* @inheritDoc
*/
set value(val: T);
equals(obj: Iterator<T>): boolean;
}
/**
* Reverse iterator of {@link List}
*
* @author Jeongho Nam - https://github.com/samchon
*/
class ReverseIterator<T> extends ReverseIteratorBase<T, List<T>, Iterator<T>, ReverseIterator<T>, T> {
protected _Create_neighbor(base: Iterator<T>): ReverseIterator<T>;
/**
* @inheritDoc
*/
get value(): T;
/**
* @inheritDoc
*/
set value(val: T);
}
}
+359
View File
@@ -0,0 +1,359 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.List = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var ListContainer_1 = require("../internal/container/linear/ListContainer");
var ListIterator_1 = require("../internal/iterator/ListIterator");
var ReverseIterator_1 = require("../internal/iterator/ReverseIterator");
var comparators_1 = require("../functional/comparators");
/**
* Doubly Linked List.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var List = /** @class */ (function (_super) {
__extends(List, _super);
function List() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this =
//----
// DEFAULT CONFIGURATIONS
//----
// INHERITS
_super.call(this) || this;
// DECLARE SOURCE POINTER
_this.ptr_ = { value: _this };
List.Iterator._Set_source_ptr(_this.end_, _this.ptr_);
//----
// BRANCHES
//----
if (args.length === 0) {
// DEFAULT CONSTRUCTOR
}
else if (args.length === 1 && args[0] instanceof Array) {
// INITIALIZER CONSTRUCTOR
var array = args[0];
_this.push.apply(_this, __spreadArray([], __read(array), false));
}
else if (args.length === 1 && args[0] instanceof List) {
// COPY CONSTRUCTOR
var container = args[0];
_this.assign(container.begin(), container.end());
}
else if (args.length === 2) {
// ASSIGN CONTRUCTOR
_this.assign(args[0], args[1]);
}
return _this;
}
List.prototype._Create_iterator = function (prev, next, val) {
return List.Iterator.create(this.ptr_, prev, next, val);
};
List.prototype.front = function (val) {
if (arguments.length === 0)
return this.begin_.value;
else
this.begin_.value = val;
};
List.prototype.back = function (val) {
var it = this.end().prev();
if (arguments.length === 0)
return it.value;
else
it.value = val;
};
/* ===============================================================
ALGORITHMS
- UNIQUE & REMOVE(_IF)
- MERGE & SPLICE
- SORT & SWAP
==================================================================
UNIQUE & REMOVE(_IF)
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
List.prototype.unique = function (binary_pred) {
if (binary_pred === void 0) { binary_pred = comparators_1.equal_to; }
var it = this.begin().next();
while (!it.equals(this.end())) {
if (binary_pred(it.value, it.prev().value) === true)
it = this.erase(it);
else
it = it.next();
}
};
/**
* @inheritDoc
*/
List.prototype.remove = function (val) {
return this.remove_if(function (elem) { return (0, comparators_1.equal_to)(elem, val); });
};
/**
* @inheritDoc
*/
List.prototype.remove_if = function (pred) {
var it = this.begin();
while (!it.equals(this.end())) {
if (pred(it.value) === true)
it = this.erase(it);
else
it = it.next();
}
};
/* ---------------------------------------------------------
MERGE & SPLICE
--------------------------------------------------------- */
/**
* @inheritDoc
*/
List.prototype.merge = function (source, comp) {
if (comp === void 0) { comp = comparators_1.less; }
if (this === source)
return;
var it = this.begin();
while (source.empty() === false) {
var first = source.begin();
while (!it.equals(this.end()) &&
comp(it.value, first.value) === true)
it = it.next();
this.splice(it, source, first);
}
};
List.prototype.splice = function (pos, obj, first, last) {
if (first === undefined) {
first = obj.begin();
last = obj.end();
}
else if (last === undefined)
last = first.next();
this.insert(pos, first, last);
obj.erase(first, last);
};
/* ---------------------------------------------------------
SORT & SWAP
--------------------------------------------------------- */
/**
* @inheritDoc
*/
List.prototype.sort = function (comp) {
if (comp === void 0) { comp = comparators_1.less; }
this._Quick_sort(this.begin(), this.end().prev(), comp);
};
List.prototype._Quick_sort = function (first, last, comp) {
if (!first.equals(last) &&
!last.equals(this.end()) &&
!first.equals(last.next())) {
var temp = this._Quick_sort_partition(first, last, comp);
this._Quick_sort(first, temp.prev(), comp);
this._Quick_sort(temp.next(), last, comp);
}
};
List.prototype._Quick_sort_partition = function (first, last, comp) {
var _a, _b;
var standard = last.value; // TO BE COMPARED
var prev = first.prev(); // TO BE SMALLEST
var it = first;
for (; !it.equals(last); it = it.next())
if (comp(it.value, standard)) {
prev = prev.equals(this.end()) ? first : prev.next();
_a = __read([it.value, prev.value], 2), prev.value = _a[0], it.value = _a[1];
}
prev = prev.equals(this.end()) ? first : prev.next();
_b = __read([it.value, prev.value], 2), prev.value = _b[0], it.value = _b[1];
return prev;
};
/**
* @inheritDoc
*/
List.prototype.reverse = function () {
var begin = this.end_.prev();
var prev_of_end = this.begin();
for (var it = this.begin(); !it.equals(this.end());) {
var prev = it.prev();
var next = it.next();
List.Iterator._Set_prev(it, next);
List.Iterator._Set_next(it, prev);
it = next;
}
// ADJUST THE BEGIN AND END
this.begin_ = begin; // THE NEW BEGIN
List.Iterator._Set_prev(this.end_, prev_of_end);
List.Iterator._Set_next(this.end_, begin);
};
/**
* @inheritDoc
*/
List.prototype.swap = function (obj) {
var _a, _b;
// CHANGE CONTENTS
_super.prototype.swap.call(this, obj);
// CHANGE ITERATORS' SOURCES
_a = __read([obj.ptr_, this.ptr_], 2), this.ptr_ = _a[0], obj.ptr_ = _a[1];
_b = __read([obj.ptr_.value, this.ptr_.value], 2), this.ptr_.value = _b[0], obj.ptr_.value = _b[1];
};
return List;
}(ListContainer_1.ListContainer));
exports.List = List;
/**
*
*/
(function (List) {
/**
* Iterator of {@link List}
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Iterator = /** @class */ (function (_super) {
__extends(Iterator, _super);
/* ---------------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------------- */
function Iterator(sourcePtr, prev, next, value) {
var _this = _super.call(this, prev, next, value) || this;
_this.source_ptr_ = sourcePtr;
return _this;
}
/**
* @internal
*/
Iterator.create = function (sourcePtr, prev, next, value) {
return new Iterator(sourcePtr, prev, next, value);
};
/**
* @inheritDoc
*/
Iterator.prototype.reverse = function () {
return new ReverseIterator(this);
};
/**
* @internal
*/
Iterator._Set_source_ptr = function (it, ptr) {
it.source_ptr_ = ptr;
};
/* ---------------------------------------------------------------
ACCESSORS
--------------------------------------------------------------- */
/**
* @inheritDoc
*/
Iterator.prototype.source = function () {
return this.source_ptr_.value;
};
Object.defineProperty(Iterator.prototype, "value", {
/**
* @inheritDoc
*/
get: function () {
this._Try_value();
return this.value_;
},
/**
* @inheritDoc
*/
set: function (val) {
this._Try_value();
this.value_ = val;
},
enumerable: false,
configurable: true
});
/* ---------------------------------------------------------------
COMPARISON
--------------------------------------------------------------- */
Iterator.prototype.equals = function (obj) {
return this === obj;
};
return Iterator;
}(ListIterator_1.ListIterator));
List.Iterator = Iterator;
/**
* Reverse iterator of {@link List}
*
* @author Jeongho Nam - https://github.com/samchon
*/
var ReverseIterator = /** @class */ (function (_super) {
__extends(ReverseIterator, _super);
function ReverseIterator() {
return _super !== null && _super.apply(this, arguments) || this;
}
/* ---------------------------------------------------------------
CONSTRUCTORS
--------------------------------------------------------------- */
ReverseIterator.prototype._Create_neighbor = function (base) {
return new ReverseIterator(base);
};
Object.defineProperty(ReverseIterator.prototype, "value", {
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
get: function () {
return this.base_.value;
},
/**
* @inheritDoc
*/
set: function (val) {
this.base_.value = val;
},
enumerable: false,
configurable: true
});
return ReverseIterator;
}(ReverseIterator_1.ReverseIterator));
List.ReverseIterator = ReverseIterator;
})(List = exports.List || (exports.List = {}));
exports.List = List;
//# sourceMappingURL=List.js.map
+56
View File
@@ -0,0 +1,56 @@
/**
* @packageDocumentation
* @module std
*/
import { AdaptorContainer } from "../internal/container/linear/AdaptorContainer";
import { Vector } from "./Vector";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { Comparator } from "../internal/functional/Comparator";
/**
* Priority Queue; Greater Out First.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class PriorityQueue<T> extends AdaptorContainer<T, Vector<T>, PriorityQueue<T>> {
private comp_;
/**
* Default Constructor.
*
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(comp?: Comparator<T>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: PriorityQueue<T>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(first: Readonly<IForwardIterator<T>>, last: Readonly<IForwardIterator<T>>, comp?: Comparator<T>);
/**
* Get value comparison function.
*/
value_comp(): Comparator<T>;
/**
* Get top element.
*/
top(): T;
/**
* @inheritDoc
*/
push(...elems: T[]): number;
/**
* @inheritDoc
*/
pop(): void;
/**
* @inheritDoc
*/
swap(obj: PriorityQueue<T>): void;
}
+169
View File
@@ -0,0 +1,169 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PriorityQueue = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var AdaptorContainer_1 = require("../internal/container/linear/AdaptorContainer");
var Vector_1 = require("./Vector");
var heap_1 = require("../algorithm/heap");
var comparators_1 = require("../functional/comparators");
/**
* Priority Queue; Greater Out First.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var PriorityQueue = /** @class */ (function (_super) {
__extends(PriorityQueue, _super);
function PriorityQueue() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, new Vector_1.Vector()) || this;
// DECLARE MEMBERS
var comp = comparators_1.less;
var post_process = null;
//----
// INITIALIZE MEMBERS AND POST-PROCESS
//----
// BRANCH - METHOD OVERLOADINGS
if (args.length === 1 && args[0] instanceof PriorityQueue) {
var obj_1 = args[0];
comp = obj_1.comp_;
post_process = function () {
var first = obj_1.source_.begin();
var last = obj_1.source_.end();
_this.source_.assign(first, last);
};
}
else if (args.length >= 2 &&
args[0].next instanceof Function &&
args[1].next instanceof Function) {
// FUNCTION TEMPLATE
if (args.length === 3)
comp = args[2];
post_process = function () {
// RANGE CONSTRUCTOR
var first = args[0]; // PARAMETER 1
var last = args[1]; // PARAMETER 2
_this.source_.assign(first, last);
};
}
else if (args.length === 1)
comp = args[0];
//----
// DO PROCESS
//----
_this.comp_ = comp;
if (post_process !== null)
post_process();
return _this;
}
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* Get value comparison function.
*/
PriorityQueue.prototype.value_comp = function () {
return this.comp_;
};
/**
* Get top element.
*/
PriorityQueue.prototype.top = function () {
return this.source_.front();
};
/* ---------------------------------------------------------
ELEMENTS I/O
--------------------------------------------------------- */
/**
* @inheritDoc
*/
PriorityQueue.prototype.push = function () {
var e_1, _a;
var elems = [];
for (var _i = 0; _i < arguments.length; _i++) {
elems[_i] = arguments[_i];
}
try {
for (var elems_1 = __values(elems), elems_1_1 = elems_1.next(); !elems_1_1.done; elems_1_1 = elems_1.next()) {
var elem = elems_1_1.value;
this.source_.push_back(elem);
(0, heap_1.push_heap)(this.source_.begin(), this.source_.end(), this.comp_);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (elems_1_1 && !elems_1_1.done && (_a = elems_1.return)) _a.call(elems_1);
}
finally { if (e_1) throw e_1.error; }
}
return this.size();
};
/**
* @inheritDoc
*/
PriorityQueue.prototype.pop = function () {
(0, heap_1.pop_heap)(this.source_.begin(), this.source_.end(), this.comp_);
this.source_.pop_back();
};
/**
* @inheritDoc
*/
PriorityQueue.prototype.swap = function (obj) {
var _a;
_super.prototype.swap.call(this, obj);
_a = __read([obj.comp_, this.comp_], 2), this.comp_ = _a[0], obj.comp_ = _a[1];
};
return PriorityQueue;
}(AdaptorContainer_1.AdaptorContainer));
exports.PriorityQueue = PriorityQueue;
//# sourceMappingURL=PriorityQueue.js.map
+39
View File
@@ -0,0 +1,39 @@
/**
* @packageDocumentation
* @module std
*/
import { AdaptorContainer } from "../internal/container/linear/AdaptorContainer";
import { List } from "./List";
/**
* Queue; FIFO (First In First Out).
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class Queue<T> extends AdaptorContainer<T, List<T>, Queue<T>> {
/**
* Default Constructor.
*/
constructor();
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: Queue<T>);
/**
* Get the first element.
*
* @return The first element.
*/
front(): T;
/**
* Get the last element.
*
* @return The last element.
*/
back(): T;
/**
* @inheritDoc
*/
pop(): void;
}
+68
View File
@@ -0,0 +1,68 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var AdaptorContainer_1 = require("../internal/container/linear/AdaptorContainer");
var List_1 = require("./List");
/**
* Queue; FIFO (First In First Out).
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Queue = /** @class */ (function (_super) {
__extends(Queue, _super);
function Queue(obj) {
var _this = _super.call(this, new List_1.List()) || this;
if (obj !== undefined)
_this.source_.assign(obj.source_.begin(), obj.source_.end());
return _this;
}
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* Get the first element.
*
* @return The first element.
*/
Queue.prototype.front = function () {
return this.source_.front();
};
/**
* Get the last element.
*
* @return The last element.
*/
Queue.prototype.back = function () {
return this.source_.back();
};
/**
* @inheritDoc
*/
Queue.prototype.pop = function () {
this.source_.pop_front();
};
return Queue;
}(AdaptorContainer_1.AdaptorContainer));
exports.Queue = Queue;
//# sourceMappingURL=Queue.js.map
+33
View File
@@ -0,0 +1,33 @@
/**
* @packageDocumentation
* @module std
*/
import { AdaptorContainer } from "../internal/container/linear/AdaptorContainer";
import { Vector } from "./Vector";
/**
* Stack; LIFO (Last In First Out).
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class Stack<T> extends AdaptorContainer<T, Vector<T>, Stack<T>> {
/**
* Default Constructor.
*/
constructor();
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: Stack<T>);
/**
* Get the last element.
*
* @return The last element.
*/
top(): T;
/**
* @inheritDoc
*/
pop(): void;
}
+60
View File
@@ -0,0 +1,60 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stack = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var AdaptorContainer_1 = require("../internal/container/linear/AdaptorContainer");
var Vector_1 = require("./Vector");
/**
* Stack; LIFO (Last In First Out).
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Stack = /** @class */ (function (_super) {
__extends(Stack, _super);
function Stack(obj) {
var _this = _super.call(this, new Vector_1.Vector()) || this;
if (obj !== undefined)
_this.source_.assign(obj.source_.begin(), obj.source_.end());
return _this;
}
/* ---------------------------------------------------------
ACCESSOR
--------------------------------------------------------- */
/**
* Get the last element.
*
* @return The last element.
*/
Stack.prototype.top = function () {
return this.source_.back();
};
/**
* @inheritDoc
*/
Stack.prototype.pop = function () {
this.source_.pop_back();
};
return Stack;
}(AdaptorContainer_1.AdaptorContainer));
exports.Stack = Stack;
//# sourceMappingURL=Stack.js.map
+81
View File
@@ -0,0 +1,81 @@
/**
* @packageDocumentation
* @module std
*/
import { UniqueTreeMap } from "../internal/container/associative/UniqueTreeMap";
import { MapElementList } from "../internal/container/associative/MapElementList";
import { Comparator } from "../internal/functional/Comparator";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { IPair } from "../utility/IPair";
/**
* Unique-key Map based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class TreeMap<Key, T> extends UniqueTreeMap<Key, T, TreeMap<Key, T>, TreeMap.Iterator<Key, T>, TreeMap.ReverseIterator<Key, T>> {
private tree_;
/**
* Default Constructor.
*
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(comp?: Comparator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(items: IPair<Key, T>[], comp?: Comparator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: TreeMap<Key, T>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(first: Readonly<IForwardIterator<IPair<Key, T>>>, last: Readonly<IForwardIterator<IPair<Key, T>>>, comp?: Comparator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: TreeMap<Key, T>): void;
/**
* @inheritDoc
*/
key_comp(): Comparator<Key>;
/**
* @inheritDoc
*/
lower_bound(key: Key): TreeMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
upper_bound(key: Key): TreeMap.Iterator<Key, T>;
protected _Handle_insert(first: TreeMap.Iterator<Key, T>, last: TreeMap.Iterator<Key, T>): void;
protected _Handle_erase(first: TreeMap.Iterator<Key, T>, last: TreeMap.Iterator<Key, T>): void;
}
/**
*
*/
export declare namespace TreeMap {
/**
* Iterator of {@link TreeMap}
*/
type Iterator<Key, T> = MapElementList.Iterator<Key, T, true, TreeMap<Key, T>>;
/**
* Reverse iterator of {@link TreeMap}
*/
type ReverseIterator<Key, T> = MapElementList.ReverseIterator<Key, T, true, TreeMap<Key, T>>;
const Iterator: typeof MapElementList.Iterator;
const ReverseIterator: typeof MapElementList.ReverseIterator;
}
+140
View File
@@ -0,0 +1,140 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var UniqueTreeMap_1 = require("../internal/container/associative/UniqueTreeMap");
var ITreeContainer_1 = require("../internal/container/associative/ITreeContainer");
var MapElementList_1 = require("../internal/container/associative/MapElementList");
var UniqueMapTree_1 = require("../internal/tree/UniqueMapTree");
/**
* Unique-key Map based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var TreeMap = /** @class */ (function (_super) {
__extends(TreeMap, _super);
function TreeMap() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this =
// INITIALIZATION
_super.call(this, function (thisArg) { return new MapElementList_1.MapElementList(thisArg); }) || this;
// OVERLOADINGS
ITreeContainer_1.ITreeContainer.construct.apply(ITreeContainer_1.ITreeContainer, __spreadArray([_this,
TreeMap,
function (comp) {
_this.tree_ = new UniqueMapTree_1.UniqueMapTree(_this, comp);
}], __read(args), false));
return _this;
}
/**
* @inheritDoc
*/
TreeMap.prototype.clear = function () {
_super.prototype.clear.call(this);
this.tree_.clear();
};
/**
* @inheritDoc
*/
TreeMap.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
MapElementList_1.MapElementList._Swap_associative(this.data_, obj.data_);
// SWAP RB-TREE
UniqueMapTree_1.UniqueMapTree._Swap_source(this.tree_, obj.tree_);
_b = __read([obj.tree_, this.tree_], 2), this.tree_ = _b[0], obj.tree_ = _b[1];
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
TreeMap.prototype.key_comp = function () {
return this.tree_.key_comp();
};
/**
* @inheritDoc
*/
TreeMap.prototype.lower_bound = function (key) {
return this.tree_.lower_bound(key);
};
/**
* @inheritDoc
*/
TreeMap.prototype.upper_bound = function (key) {
return this.tree_.upper_bound(key);
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
TreeMap.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.insert(first);
};
TreeMap.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.erase(first);
};
return TreeMap;
}(UniqueTreeMap_1.UniqueTreeMap));
exports.TreeMap = TreeMap;
/**
*
*/
(function (TreeMap) {
// BODY
TreeMap.Iterator = MapElementList_1.MapElementList.Iterator;
TreeMap.ReverseIterator = MapElementList_1.MapElementList.ReverseIterator;
})(TreeMap = exports.TreeMap || (exports.TreeMap = {}));
exports.TreeMap = TreeMap;
//# sourceMappingURL=TreeMap.js.map
+81
View File
@@ -0,0 +1,81 @@
/**
* @packageDocumentation
* @module std
*/
import { MultiTreeMap } from "../internal/container/associative/MultiTreeMap";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { MapElementList } from "../internal/container/associative/MapElementList";
import { Comparator } from "../internal/functional/Comparator";
import { IPair } from "../utility/IPair";
/**
* Multiple-key Map based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class TreeMultiMap<Key, T> extends MultiTreeMap<Key, T, TreeMultiMap<Key, T>, TreeMultiMap.Iterator<Key, T>, TreeMultiMap.ReverseIterator<Key, T>> {
private tree_;
/**
* Default Constructor.
*
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(comp?: Comparator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(items: IPair<Key, T>[], comp?: Comparator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: TreeMultiMap<Key, T>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(first: Readonly<IForwardIterator<IPair<Key, T>>>, last: Readonly<IForwardIterator<IPair<Key, T>>>, comp?: Comparator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: TreeMultiMap<Key, T>): void;
/**
* @inheritDoc
*/
key_comp(): Comparator<Key>;
/**
* @inheritDoc
*/
lower_bound(key: Key): TreeMultiMap.Iterator<Key, T>;
/**
* @inheritDoc
*/
upper_bound(key: Key): TreeMultiMap.Iterator<Key, T>;
protected _Handle_insert(first: TreeMultiMap.Iterator<Key, T>, last: TreeMultiMap.Iterator<Key, T>): void;
protected _Handle_erase(first: TreeMultiMap.Iterator<Key, T>, last: TreeMultiMap.Iterator<Key, T>): void;
}
/**
*
*/
export declare namespace TreeMultiMap {
/**
* Iterator of {@link TreeMultiMap}
*/
type Iterator<Key, T> = MapElementList.Iterator<Key, T, false, TreeMultiMap<Key, T>>;
/**
* Iterator of {@link TreeMultiMap}
*/
type ReverseIterator<Key, T> = MapElementList.ReverseIterator<Key, T, false, TreeMultiMap<Key, T>>;
const Iterator: typeof MapElementList.Iterator;
const ReverseIterator: typeof MapElementList.ReverseIterator;
}
+137
View File
@@ -0,0 +1,137 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeMultiMap = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var MultiTreeMap_1 = require("../internal/container/associative/MultiTreeMap");
var ITreeContainer_1 = require("../internal/container/associative/ITreeContainer");
var MapElementList_1 = require("../internal/container/associative/MapElementList");
var MultiMapTree_1 = require("../internal/tree/MultiMapTree");
/**
* Multiple-key Map based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var TreeMultiMap = /** @class */ (function (_super) {
__extends(TreeMultiMap, _super);
function TreeMultiMap() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new MapElementList_1.MapElementList(thisArg); }) || this;
ITreeContainer_1.ITreeContainer.construct.apply(ITreeContainer_1.ITreeContainer, __spreadArray([_this,
TreeMultiMap,
function (comp) {
_this.tree_ = new MultiMapTree_1.MultiMapTree(_this, comp);
}], __read(args), false));
return _this;
}
/**
* @inheritDoc
*/
TreeMultiMap.prototype.clear = function () {
_super.prototype.clear.call(this);
this.tree_.clear();
};
/**
* @inheritDoc
*/
TreeMultiMap.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
MapElementList_1.MapElementList._Swap_associative(this.data_, obj.data_);
// SWAP RB-TREE
MultiMapTree_1.MultiMapTree._Swap_source(this.tree_, obj.tree_);
_b = __read([obj.tree_, this.tree_], 2), this.tree_ = _b[0], obj.tree_ = _b[1];
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
TreeMultiMap.prototype.key_comp = function () {
return this.tree_.key_comp();
};
/**
* @inheritDoc
*/
TreeMultiMap.prototype.lower_bound = function (key) {
return this.tree_.lower_bound(key);
};
/**
* @inheritDoc
*/
TreeMultiMap.prototype.upper_bound = function (key) {
return this.tree_.upper_bound(key);
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
TreeMultiMap.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.insert(first);
};
TreeMultiMap.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.erase(first);
};
return TreeMultiMap;
}(MultiTreeMap_1.MultiTreeMap));
exports.TreeMultiMap = TreeMultiMap;
/**
*
*/
(function (TreeMultiMap) {
// BODY
TreeMultiMap.Iterator = MapElementList_1.MapElementList.Iterator;
TreeMultiMap.ReverseIterator = MapElementList_1.MapElementList.ReverseIterator;
})(TreeMultiMap = exports.TreeMultiMap || (exports.TreeMultiMap = {}));
exports.TreeMultiMap = TreeMultiMap;
//# sourceMappingURL=TreeMultiMap.js.map
+80
View File
@@ -0,0 +1,80 @@
/**
* @packageDocumentation
* @module std
*/
import { MultiTreeSet } from "../internal/container/associative/MultiTreeSet";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { SetElementList } from "../internal/container/associative/SetElementList";
import { Comparator } from "../internal/functional/Comparator";
/**
* Multiple-key Set based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class TreeMultiSet<Key> extends MultiTreeSet<Key, TreeMultiSet<Key>, TreeMultiSet.Iterator<Key>, TreeMultiSet.ReverseIterator<Key>> {
private tree_;
/**
* Default Constructor.
*
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(comp?: Comparator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(items: Key[], comp?: Comparator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(obj: TreeMultiSet<Key>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(first: Readonly<IForwardIterator<Key>>, last: Readonly<IForwardIterator<Key>>, comp?: Comparator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: TreeMultiSet<Key>): void;
/**
* @inheritDoc
*/
key_comp(): Comparator<Key>;
/**
* @inheritDoc
*/
lower_bound(key: Key): TreeMultiSet.Iterator<Key>;
/**
* @inheritDoc
*/
upper_bound(key: Key): TreeMultiSet.Iterator<Key>;
protected _Handle_insert(first: TreeMultiSet.Iterator<Key>, last: TreeMultiSet.Iterator<Key>): void;
protected _Handle_erase(first: TreeMultiSet.Iterator<Key>, last: TreeMultiSet.Iterator<Key>): void;
}
/**
*
*/
export declare namespace TreeMultiSet {
/**
* Iterator of {@link TreeMultiSet}
*/
type Iterator<Key> = SetElementList.Iterator<Key, false, TreeMultiSet<Key>>;
/**
* Reverse iterator of {@link TreeMultiSet}
*/
type ReverseIterator<Key> = SetElementList.ReverseIterator<Key, false, TreeMultiSet<Key>>;
const Iterator: typeof SetElementList.Iterator;
const ReverseIterator: typeof SetElementList.ReverseIterator;
}
+137
View File
@@ -0,0 +1,137 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeMultiSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var MultiTreeSet_1 = require("../internal/container/associative/MultiTreeSet");
var ITreeContainer_1 = require("../internal/container/associative/ITreeContainer");
var SetElementList_1 = require("../internal/container/associative/SetElementList");
var MultiSetTree_1 = require("../internal/tree/MultiSetTree");
/**
* Multiple-key Set based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var TreeMultiSet = /** @class */ (function (_super) {
__extends(TreeMultiSet, _super);
function TreeMultiSet() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new SetElementList_1.SetElementList(thisArg); }) || this;
ITreeContainer_1.ITreeContainer.construct.apply(ITreeContainer_1.ITreeContainer, __spreadArray([_this,
TreeMultiSet,
function (comp) {
_this.tree_ = new MultiSetTree_1.MultiSetTree(_this, comp);
}], __read(args), false));
return _this;
}
/**
* @inheritDoc
*/
TreeMultiSet.prototype.clear = function () {
_super.prototype.clear.call(this);
this.tree_.clear();
};
/**
* @inheritDoc
*/
TreeMultiSet.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
SetElementList_1.SetElementList._Swap_associative(this.data_, obj.data_);
// SWAP RB-TREE
MultiSetTree_1.MultiSetTree._Swap_source(this.tree_, obj.tree_);
_b = __read([obj.tree_, this.tree_], 2), this.tree_ = _b[0], obj.tree_ = _b[1];
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
TreeMultiSet.prototype.key_comp = function () {
return this.tree_.key_comp();
};
/**
* @inheritDoc
*/
TreeMultiSet.prototype.lower_bound = function (key) {
return this.tree_.lower_bound(key);
};
/**
* @inheritDoc
*/
TreeMultiSet.prototype.upper_bound = function (key) {
return this.tree_.upper_bound(key);
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
TreeMultiSet.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.insert(first);
};
TreeMultiSet.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.erase(first);
};
return TreeMultiSet;
}(MultiTreeSet_1.MultiTreeSet));
exports.TreeMultiSet = TreeMultiSet;
/**
*
*/
(function (TreeMultiSet) {
// BODY
TreeMultiSet.Iterator = SetElementList_1.SetElementList.Iterator;
TreeMultiSet.ReverseIterator = SetElementList_1.SetElementList.ReverseIterator;
})(TreeMultiSet = exports.TreeMultiSet || (exports.TreeMultiSet = {}));
exports.TreeMultiSet = TreeMultiSet;
//# sourceMappingURL=TreeMultiSet.js.map
+80
View File
@@ -0,0 +1,80 @@
/**
* @packageDocumentation
* @module std
*/
import { UniqueTreeSet } from "../internal/container/associative/UniqueTreeSet";
import { IForwardIterator } from "../iterator/IForwardIterator";
import { SetElementList } from "../internal/container/associative/SetElementList";
import { Comparator } from "../internal/functional/Comparator";
/**
* Unique-key Set based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class TreeSet<Key> extends UniqueTreeSet<Key, TreeSet<Key>, TreeSet.Iterator<Key>, TreeSet.ReverseIterator<Key>> {
private tree_;
/**
* Default Constructor.
*
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(comp?: Comparator<Key>);
/**
* Initializer Constructor.
*
* @param items Items to assign.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(items: Key[], comp?: Comparator<Key>);
/**
* Copy Constructor.
*
* @param obj Object to copy.
*/
constructor(container: TreeSet<Key>);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iterator of the last position.
* @param comp A binary function predicates *x* element would be placed before *y*. When returns `true`, then *x* precedes *y*. Note that, because *equality* is predicated by `!comp(x, y) && !comp(y, x)`, the function must not cover the *equality* like `<=` or `>=`. It must exclude the *equality* like `<` or `>`. Default is {@link less}.
*/
constructor(first: Readonly<IForwardIterator<Key>>, last: Readonly<IForwardIterator<Key>>, comp?: Comparator<Key>);
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
swap(obj: TreeSet<Key>): void;
/**
* @inheritDoc
*/
key_comp(): Comparator<Key>;
/**
* @inheritDoc
*/
lower_bound(key: Key): TreeSet.Iterator<Key>;
/**
* @inheritDoc
*/
upper_bound(key: Key): TreeSet.Iterator<Key>;
protected _Handle_insert(first: TreeSet.Iterator<Key>, last: TreeSet.Iterator<Key>): void;
protected _Handle_erase(first: TreeSet.Iterator<Key>, last: TreeSet.Iterator<Key>): void;
}
/**
*
*/
export declare namespace TreeSet {
/**
* Iterator of {@link TreeSet}
*/
type Iterator<Key> = SetElementList.Iterator<Key, true, TreeSet<Key>>;
/**
* Reverse iterator of {@link TreeSet}
*/
type ReverseIterator<Key> = SetElementList.ReverseIterator<Key, true, TreeSet<Key>>;
const Iterator: typeof SetElementList.Iterator;
const ReverseIterator: typeof SetElementList.ReverseIterator;
}
+137
View File
@@ -0,0 +1,137 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeSet = void 0;
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
var UniqueTreeSet_1 = require("../internal/container/associative/UniqueTreeSet");
var ITreeContainer_1 = require("../internal/container/associative/ITreeContainer");
var SetElementList_1 = require("../internal/container/associative/SetElementList");
var UniqueSetTree_1 = require("../internal/tree/UniqueSetTree");
/**
* Unique-key Set based on Tree.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var TreeSet = /** @class */ (function (_super) {
__extends(TreeSet, _super);
function TreeSet() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this, function (thisArg) { return new SetElementList_1.SetElementList(thisArg); }) || this;
ITreeContainer_1.ITreeContainer.construct.apply(ITreeContainer_1.ITreeContainer, __spreadArray([_this,
TreeSet,
function (comp) {
_this.tree_ = new UniqueSetTree_1.UniqueSetTree(_this, comp);
}], __read(args), false));
return _this;
}
/**
* @inheritDoc
*/
TreeSet.prototype.clear = function () {
_super.prototype.clear.call(this);
this.tree_.clear();
};
/**
* @inheritDoc
*/
TreeSet.prototype.swap = function (obj) {
var _a, _b;
// SWAP CONTENTS
_a = __read([obj.data_, this.data_], 2), this.data_ = _a[0], obj.data_ = _a[1];
SetElementList_1.SetElementList._Swap_associative(this.data_, obj.data_);
// SWAP RB-TREE
UniqueSetTree_1.UniqueSetTree._Swap_source(this.tree_, obj.tree_);
_b = __read([obj.tree_, this.tree_], 2), this.tree_ = _b[0], obj.tree_ = _b[1];
};
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritDoc
*/
TreeSet.prototype.key_comp = function () {
return this.tree_.key_comp();
};
/**
* @inheritDoc
*/
TreeSet.prototype.lower_bound = function (key) {
return this.tree_.lower_bound(key);
};
/**
* @inheritDoc
*/
TreeSet.prototype.upper_bound = function (key) {
return this.tree_.upper_bound(key);
};
/* ---------------------------------------------------------
POST-PROCESS
--------------------------------------------------------- */
TreeSet.prototype._Handle_insert = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.insert(first);
};
TreeSet.prototype._Handle_erase = function (first, last) {
for (; !first.equals(last); first = first.next())
this.tree_.erase(first);
};
return TreeSet;
}(UniqueTreeSet_1.UniqueTreeSet));
exports.TreeSet = TreeSet;
/**
*
*/
(function (TreeSet) {
// BODY
TreeSet.Iterator = SetElementList_1.SetElementList.Iterator;
TreeSet.ReverseIterator = SetElementList_1.SetElementList.ReverseIterator;
})(TreeSet = exports.TreeSet || (exports.TreeSet = {}));
exports.TreeSet = TreeSet;
//# sourceMappingURL=TreeSet.js.map
+73
View File
@@ -0,0 +1,73 @@
/**
* @packageDocumentation
* @module std
*/
import { IArrayContainer } from "../base/container/IArrayContainer";
import { VectorContainer } from "../internal/container/linear/VectorContainer";
import { ArrayIterator } from "../internal/iterator/ArrayIterator";
import { ArrayReverseIterator } from "../internal/iterator/ArrayReverseIterator";
import { IForwardIterator } from "../iterator/IForwardIterator";
/**
* Vector, an array with variable capacity.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export declare class Vector<T> extends VectorContainer<T, Vector<T>, Vector<T>, Vector.Iterator<T>, Vector.ReverseIterator<T>> implements IArrayContainer<T, Vector<T>, Vector.Iterator<T>, Vector.ReverseIterator<T>> {
/**
* Default Constructor.
*/
constructor();
/**
* Initializer Constructor.
*
* @param items Items to assign.
*/
constructor(items: Array<T>);
/**
* Copy Constructor
*
* @param obj Object to copy.
*/
constructor(obj: Vector<T>);
/**
* Fill Constructor.
*
* @param size Initial size.
* @param val Value to fill.
*/
constructor(n: number, val: T);
/**
* Range Constructor.
*
* @param first Input iterator of the first position.
* @param last Input iteartor of the last position.
*/
constructor(first: Readonly<IForwardIterator<T>>, last: Readonly<IForwardIterator<T>>);
/**
* Wrap an array into a vector.
*
* @param data Target array to be wrapped
* @return A vector wrapping the parametric array.
*/
static wrap<T>(data: Array<T>): Vector<T>;
/**
* @inheritDoc
*/
nth(index: number): Vector.Iterator<T>;
protected source(): Vector<T>;
}
/**
*
*/
export declare namespace Vector {
/**
* Iterator of {@link Vector}
*/
type Iterator<T> = ArrayIterator<T, Vector<T>>;
/**
* Reverse iterator of {@link Vector}
*/
type ReverseIterator<T> = ArrayReverseIterator<T, Vector<T>>;
const Iterator: typeof ArrayIterator;
const ReverseIterator: typeof ArrayReverseIterator;
}
+90
View File
@@ -0,0 +1,90 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vector = void 0;
var VectorContainer_1 = require("../internal/container/linear/VectorContainer");
var ArrayIterator_1 = require("../internal/iterator/ArrayIterator");
var ArrayReverseIterator_1 = require("../internal/iterator/ArrayReverseIterator");
/**
* Vector, an array with variable capacity.
*
* @author Jeongho Nam - https://github.com/samchon
*/
var Vector = /** @class */ (function (_super) {
__extends(Vector, _super);
function Vector() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.call(this) || this;
// CONSTRUCTORS BRANCH
if (args.length === 0) {
// DEFAULT CONSTRUCTOR
_this.data_ = [];
}
else if (args[0] instanceof Array) {
// INITIALIZER CONSTRUCTOR
var array = args[0];
_this.data_ = args[1] === true ? array : array.slice();
}
else if (args.length === 1 && args[0] instanceof Vector) {
// COPY CONSTRUCTOR
var v = args[0];
_this.data_ = v.data_.slice();
}
else if (args.length === 2) {
// ASSIGN CONSTRUCTOR
_this.data_ = [];
_this.assign(args[0], args[1]);
}
return _this;
}
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* Wrap an array into a vector.
*
* @param data Target array to be wrapped
* @return A vector wrapping the parametric array.
*/
Vector.wrap = function (data) {
return new Vector(data, true);
};
/**
* @inheritDoc
*/
Vector.prototype.nth = function (index) {
return new Vector.Iterator(this, index);
};
Vector.prototype.source = function () {
return this;
};
return Vector;
}(VectorContainer_1.VectorContainer));
exports.Vector = Vector;
/**
*
*/
(function (Vector) {
// BODY
Vector.Iterator = ArrayIterator_1.ArrayIterator;
Vector.ReverseIterator = ArrayReverseIterator_1.ArrayReverseIterator;
})(Vector = exports.Vector || (exports.Vector = {}));
exports.Vector = Vector;
//# sourceMappingURL=Vector.js.map

Some files were not shown because too many files have changed in this diff Show More