Skip to content

Commit

Permalink
Fixing #46 and #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Samchon committed Nov 25, 2019
1 parent 60dd605 commit 935aea8
Show file tree
Hide file tree
Showing 55 changed files with 1,285 additions and 612 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"email": "samchon@samchon.org",
"url": "http://samchon.org"
},
"version": "2.4.0-dev.20191125",
"version": "2.4.0-dev.20191126",
"main": "./index.js",
"typings": "./index.d.ts",
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions src/algorithm/index.ts
Expand Up @@ -14,6 +14,4 @@ export * from "./modifiers";
export * from "./partition";
export * from "./random";
export * from "./sorting";
export * from "./merge";

export import ranges = require("./ranges");
export * from "./merge";
1 change: 1 addition & 0 deletions src/algorithm/iterations.ts
Expand Up @@ -150,6 +150,7 @@ export function none_of<InputIterator extends Readonly<IForwardIterator<IPointer
* @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.
*/
Expand Down
21 changes: 14 additions & 7 deletions src/algorithm/merge.ts
Expand Up @@ -13,6 +13,12 @@ import { back_inserter } from "../iterator/factory";
import { Vector } from "../container/Vector";
import { Temporary } from "../base/Temporary";

/**
* @hidden
*/
type Comparator<Iterator extends IForwardIterator<IPointer.ValueType<Iterator>, Iterator>> =
(x: IPointer.ValueType<Iterator>, y: IPointer.ValueType<Iterator>) => boolean;

/* =========================================================
MERGE & SET OPERATIONS
- MERGE
Expand Down Expand Up @@ -40,7 +46,7 @@ export function merge<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
output: OutputIterator,
comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
comp: Comparator<InputIterator1> = less
): OutputIterator
{
while (true)
Expand Down Expand Up @@ -77,7 +83,7 @@ export function inplace_merge<BidirectionalIterator extends General<IBidirection
first: BidirectionalIterator,
middle: BidirectionalIterator,
last: BidirectionalIterator,
comp: (x: IPointer.ValueType<BidirectionalIterator>, y: IPointer.ValueType<BidirectionalIterator>) => boolean = less
comp: Comparator<BidirectionalIterator> = less
): void
{
let vector: Vector<IPointer.ValueType<BidirectionalIterator>> = new Vector();
Expand Down Expand Up @@ -106,7 +112,7 @@ export function includes<
(
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
comp: Comparator<InputIterator1> = less
): boolean
{
while (!first2.equals(last2))
Expand Down Expand Up @@ -142,7 +148,7 @@ export function set_union<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
output: OutputIterator,
comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
comp: Comparator<InputIterator1> = less
): OutputIterator
{
while (true)
Expand Down Expand Up @@ -194,7 +200,7 @@ export function set_intersection<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
output: OutputIterator,
comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
comp: Comparator<InputIterator1> = less
): OutputIterator
{
while (true)
Expand Down Expand Up @@ -239,7 +245,7 @@ export function set_difference<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
output: OutputIterator,
comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
comp: Comparator<InputIterator1> = less
): OutputIterator
{
while (!first1.equals(last1) && !first2.equals(last2))
Expand Down Expand Up @@ -280,7 +286,8 @@ export function set_symmetric_difference<
(
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2, last2: InputIterator2,
output: OutputIterator, comp: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator1>) => boolean = less
output: OutputIterator,
comp: Comparator<InputIterator1> = less
): OutputIterator
{
while (true)
Expand Down
38 changes: 31 additions & 7 deletions src/algorithm/modifiers.ts
Expand Up @@ -11,6 +11,29 @@ import { equal_to } from "../functional/comparators";
import { randint } from "./random";
import { advance } from "../iterator/global";

/**
* @hidden
*/
type UnaryPredicator<Iterator extends IForwardIterator<IPointer.ValueType<Iterator>, Iterator>> =
(val: IPointer.ValueType<Iterator>) => boolean;

/**
* @hidden
*/
type UnaryOperator<
InputIterator extends Readonly<IForwardIterator<IPointer.ValueType<InputIterator>, InputIterator>>,
OutputIterator extends Writeonly<IForwardIterator<IPointer.ValueType<OutputIterator>, OutputIterator>>> =
(val: IPointer.ValueType<InputIterator>) => IPointer.ValueType<OutputIterator>;

/**
* @hidden
*/
type BinaryOperator<
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>;

/* =========================================================
MODIFIERS (MODIFYING SEQUENCE)
- FILL
Expand Down Expand Up @@ -82,7 +105,7 @@ export function copy_if<
(
first: InputIterator, last: InputIterator,
output: OutputIterator,
pred: (x: IPointer.ValueType<InputIterator>) => boolean
pred: UnaryPredicator<InputIterator>
): OutputIterator
{
for (; !first.equals(last); first = first.next())
Expand Down Expand Up @@ -184,7 +207,7 @@ export function transform<
(
first: InputIterator, last: InputIterator,
result: OutputIterator,
op: (val: IPointer.ValueType<InputIterator>) => IPointer.ValueType<OutputIterator>
op: UnaryOperator<InputIterator, OutputIterator>
): OutputIterator;

/**
Expand All @@ -206,7 +229,7 @@ export function transform<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2,
result: OutputIterator,
op: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator2>) => IPointer.ValueType<OutputIterator>
op: BinaryOperator<InputIterator1, InputIterator2, OutputIterator>
): OutputIterator;

export function transform(...args: any[]): any
Expand All @@ -226,7 +249,7 @@ function _Unary_transform<
(
first: InputIterator, last: InputIterator,
result: OutputIterator,
op: (val: IPointer.ValueType<InputIterator>) => IPointer.ValueType<OutputIterator>
op: UnaryOperator<InputIterator, OutputIterator>
): OutputIterator
{
for (; !first.equals(last); first = first.next())
Expand All @@ -248,7 +271,7 @@ function _Binary_transform<
first1: InputIterator1, last1: InputIterator1,
first2: InputIterator2,
result: OutputIterator,
binary_op: (x: IPointer.ValueType<InputIterator1>, y: IPointer.ValueType<InputIterator2>) => IPointer.ValueType<OutputIterator>
binary_op: BinaryOperator<InputIterator1, InputIterator2, OutputIterator>
): OutputIterator
{
while (!first1.equals(last1))
Expand Down Expand Up @@ -452,7 +475,7 @@ export function remove_copy_if<
(
first: InputIterator, last: InputIterator,
output: OutputIterator,
pred: (x: IPointer.ValueType<InputIterator>) => boolean
pred: UnaryPredicator<InputIterator>
): OutputIterator
{
for (; !first.equals(last); first = first.next())
Expand Down Expand Up @@ -719,6 +742,7 @@ export function shuffle<RandomAccessIterator extends General<IRandomAccessIterat
for (let it = first; !it.equals(last); it = it.next())
{
let rand_index: number = randint(first.index(), last.index() - 1);
iter_swap(it, first.advance(rand_index));
if (it.index() !== rand_index)
iter_swap(it, first.advance(rand_index));
}
}
179 changes: 0 additions & 179 deletions src/algorithm/ranges/iterations.ts

This file was deleted.

0 comments on commit 935aea8

Please sign in to comment.