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
+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