Skip to content

Commit

Permalink
v1.3.8
Browse files Browse the repository at this point in the history
Refactoring and some global methods newly added.
  • Loading branch information
Jeongho Nam committed Jan 14, 2017
1 parent c6892dd commit c4ed516
Show file tree
Hide file tree
Showing 18 changed files with 312 additions and 22,339 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ======================================================
# CUSTOM IGNORE
# ======================================================

*.bat
*.lnk
11,111 changes: 0 additions & 11,111 deletions lib/tstl.d.ts

This file was deleted.

10,297 changes: 0 additions & 10,297 deletions lib/tstl.js

This file was deleted.

636 changes: 0 additions & 636 deletions lib/tstl.min.js

This file was deleted.

34 changes: 17 additions & 17 deletions ts/src/std/Algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace std
* <p> Test condition on all elements in range. </p>
*
* <p> Returns <code>true</code> if <i>pred</i> returns <code>true</code> for all the elements in the range
* [<i>first</i>, <i>last</i>) or if the range is {@link IContainer.empty empty}, and <code>false</code> otherwise.
* [<i>first</i>, <i>last</i>) or if the range is {@link Container.empty empty}, and <code>false</code> otherwise.
* </p>
*
* @param first An {@link Iterator} to the initial position in a sequence.
Expand All @@ -85,7 +85,7 @@ namespace std
* checked by this function. The function shall not modify its argument.
*
* @return <code>true</code> if pred returns true for all the elements in the range or if the range is
* {@link IContainer.empty empty}, and <code>false</code> otherwise.
* {@link Container.empty empty}, and <code>false</code> otherwise.
*/
export function all_of<T, InputIterator extends Iterator<T>>
(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean
Expand All @@ -103,7 +103,7 @@ namespace std
* <p> Returns <code>true</code> if <i>pred</i> returns true for any of the elements in the range
* [<i>first</i>, <i>last</i>), and <code>false</code> otherwise. </p>
*
* <p> If [<i>first</i>, <i>last</i>) is an {@link IContainer.empty empty} range, the function returns
* <p> If [<i>first</i>, <i>last</i>) is an {@link Container.empty empty} range, the function returns
* <code>false</code>. </p>
*
* @param first An {@link Iterator} to the initial position in a sequence.
Expand All @@ -116,7 +116,7 @@ namespace std
*
* @return <code>true</code> if <i>pred</i> returns <code>true</code> for any of the elements in the range
* [<i>first</i>, <i>last</i>), and <code>false</code> otherwise. If [<i>first</i>, <i>last</i>) is an
* {@link IContainer.empty empty} range, the function returns <code>false</code>.
* {@link Container.empty empty} range, the function returns <code>false</code>.
*/
export function any_of<T, InputIterator extends Iterator<T>>
(first: InputIterator, last: InputIterator, pred: (val: T) => boolean): boolean
Expand All @@ -132,7 +132,7 @@ namespace std
* <p> Test if no elements fulfill condition. </p>
*
* <p> Returns <code>true</code> if <i>pred</i> returns false for all the elements in the range
* [<i>first</i>, <i>last</i>) or if the range is {@link IContainer.empty empty}, and <code>false</code> otherwise.
* [<i>first</i>, <i>last</i>) or if the range is {@link Container.empty empty}, and <code>false</code> otherwise.
* </p>
*
* @param first An {@link Iterator} to the initial position in a sequence.
Expand All @@ -144,7 +144,7 @@ namespace std
* checked by this function. The function shall not modify its argument.
*
* @return <code>true</code> if <i>pred</i> returns <code>false</code> for all the elements in the range
* [<i>first</i>, <i>last</i>) or if the range is {@link IContainer.empty empty}, and <code>false</code>
* [<i>first</i>, <i>last</i>) or if the range is {@link Container.empty empty}, and <code>false</code>
* otherwise.
*/
export function none_of<T, InputIterator extends Iterator<T>>
Expand Down Expand Up @@ -1890,8 +1890,8 @@ namespace std
{
for (let it = first; !it.equals(last); it = it.next() as RandomAccessIterator)
{
let last_index: number = (last.index == -1) ? last.source().size() : last.index;
let rand_index: number = Math.floor(Math.random() * (last_index - first.index));
let last_index: number = (last.index() == -1) ? last.source().size() : last.index();
let rand_index: number = Math.floor(Math.random() * (last_index - first.index()));

it.swap(first.advance(rand_index));
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ namespace std
export function sort<T, RandomAccessIterator extends base.IArrayIterator<T>>
(first: RandomAccessIterator, last: RandomAccessIterator, compare: (left: T, right: T) => boolean = std.less): void
{
qsort(first.source() as base.IArrayContainer<T>, first.index, last.index - 1, compare);
qsort(first.source() as base.IArrayContainer<T>, first.index(), last.index() - 1, compare);
}

/**
Expand Down Expand Up @@ -2002,7 +2002,7 @@ namespace std
compare: (x: T, y: T) => boolean = std.less
): void
{
selection_sort(first.source() as base.IArrayContainer<T>, first.index, middle.index, last.index, compare);
selection_sort(first.source() as base.IArrayContainer<T>, first.index(), middle.index(), last.index(), compare);
}

/**
Expand Down Expand Up @@ -2076,7 +2076,7 @@ namespace std
): RandomAccessIterator;

export function partial_sort_copy
<T, InputIterator extends Iterator<T>, RandomAccessIterator extends Iterator<T>>
<T, InputIterator extends Iterator<T>, RandomAccessIterator extends base.IArrayIterator<T>>
(
first: InputIterator, last: InputIterator,
result_first: RandomAccessIterator, result_last: RandomAccessIterator,
Expand Down Expand Up @@ -3119,7 +3119,7 @@ namespace std
* <p> Returns <code>true</code> if all the elements in the range [<i>first</i>, <i>last</i>) for which <i>pred</i>
* returns <code>true</code> precede those for which it returns <code>false</code>. </p>
*
* <p> If the range is {@link IContainer.empty empty}, the function returns <code>true</code>. </p>
* <p> If the range is {@link Container.empty empty}, the function returns <code>true</code>. </p>
*
* @param first {@link Iterator Input iterator} to the initial position of the sequence.
* @param last {@link Iterator Input iterator} to the final position of the sequence. The range used is
Expand All @@ -3132,7 +3132,7 @@ namespace std
*
* @return <code>true</code> if all the elements in the range [<i>first</i>, <i>last</i>) for which <i>pred</i> returns
* <code>true</code> precede those for which it returns <code>false</code>. Otherwise it returns
* <code>false</code>. If the range is {@link IContainer.empty empty}, the function returns <code>true</code>.
* <code>false</code>. If the range is {@link Container.empty empty}, the function returns <code>true</code>.
*/
export function is_partitioned<T, InputIterator extends Iterator<T>>
(first: InputIterator, last: InputIterator, pred: (x: T) => boolean): boolean
Expand Down Expand Up @@ -3167,7 +3167,7 @@ namespace std
* <code>false</code>). The function shall not modify its argument.
*
* @return An iterator that points to the first element of the second group of elements (those for which <i>pred</i>
* returns <code>false</code>), or <i>last</i> if this group is {@link IContainer.empty empty}.
* returns <code>false</code>), or <i>last</i> if this group is {@link Container.empty empty}.
*/
export function partition<T, BidirectionalIterator extends Iterator<T>>
(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator
Expand Down Expand Up @@ -3214,7 +3214,7 @@ namespace std
* <code>false</code>). The function shall not modify its argument.
*
* @return An iterator that points to the first element of the second group of elements (those for which <i>pred</i>
* returns <code>false</code>), or <i>last</i> if this group is {@link IContainer.empty empty}.
* returns <code>false</code>), or <i>last</i> if this group is {@link Container.empty empty}.
*/
export function stable_partition<T, BidirectionalIterator extends Iterator<T>>
(first: BidirectionalIterator, last: BidirectionalIterator, pred: (x: T) => boolean): BidirectionalIterator
Expand Down Expand Up @@ -3467,13 +3467,13 @@ namespace std
* considered to go before the second in the specific <i>strict weak ordering</i> it defines. The
* function shall not modify any of its arguments.
*/
export function inplace_merge<T, BidirectionalIterator extends Iterator<T>>
export function inplace_merge<T, BidirectionalIterator extends base.ILinearIterator<T>>
(
first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator,
compare: (x: T, y: T) => boolean
): void;

export function inplace_merge<T, BidirectionalIterator extends Iterator<T>>
export function inplace_merge<T, BidirectionalIterator extends base.ILinearIterator<T>>
(
first: BidirectionalIterator, middle: BidirectionalIterator, last: BidirectionalIterator,
compare: (x: T, y: T) => boolean = std.less
Expand Down
78 changes: 43 additions & 35 deletions ts/src/std/Deque.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ namespace std
// WHEN FITTING INTO RESERVED CAPACITY IS POSSIBLE
// ------------------------------------------------------
// INSERTS CAREFULLY CONSIDERING THE COL_SIZE
let index_pair = this._Fetch_index(position.index);
let index_pair = this._Fetch_index(position.index());
let index = index_pair.first;

let spliced_values = this.matrix_[index].splice(index_pair.second);
Expand Down Expand Up @@ -785,7 +785,7 @@ namespace std
}
else
{
let indexPair = this._Fetch_index(position.index);
let indexPair = this._Fetch_index(position.index());
let index = indexPair.first;

let splicedValues = this.matrix_[index].splice(indexPair.second);
Expand Down Expand Up @@ -858,22 +858,22 @@ namespace std
*/
protected _Erase_by_range(first: DequeIterator<T>, last: DequeIterator<T>): DequeIterator<T>
{
if (first.index == -1)
if (first.index() == -1)
return first;

// INDEXING
let size: number;
if (last.index == -1) // LAST IS END()
size = this.size() - first.index;
if (last.index() == -1) // LAST IS END()
size = this.size() - first.index();
else // LAST IS NOT END()
size = last.index - first.index;
size = last.index() - first.index();

this.size_ -= size;

// ERASING
while (size != 0)
{
let indexPair: Pair<number, number> = this._Fetch_index(first.index);
let indexPair: Pair<number, number> = this._Fetch_index(first.index());
let array: Array<T> = this.matrix_[indexPair.first];

let myDeleteSize: number = Math.min(size, array.length - indexPair.second);
Expand All @@ -885,7 +885,7 @@ namespace std
size -= myDeleteSize;
}

if (last.index == -1)
if (last.index() == -1)
return this.end();
else
return first;
Expand All @@ -909,7 +909,7 @@ namespace std
*
* @param obj Another {@link Deque container} of the same type of elements (i.e., instantiated
* with the same template parameter, <b>T</b>) whose content is swapped with that of this
* {@link container Deque}.
* {@link Deque container}.
*/
public swap(obj: Deque<T>): void

Expand Down Expand Up @@ -976,12 +976,28 @@ namespace std
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritdoc
*/
public source(): Deque<T>
{
return this.source_ as Deque<T>;
}

/**
* @inheritdoc
*/
public index(): number
{
return this.index_;
}

/**
* @inheritdoc
*/
public get value(): T
{
return (this.source_ as Deque<T>).at(this.index_);
return this.source().at(this.index_);
}

/**
Expand All @@ -991,15 +1007,7 @@ namespace std
*/
public set value(val: T)
{
(this.source_ as Deque<T>).set(this.index_, val);
}

/**
* @inheritdoc
*/
public get index(): number
{
return this.index_;
this.source().set(this.index_, val);
}

/* ---------------------------------------------------------
Expand All @@ -1011,11 +1019,11 @@ namespace std
public prev(): DequeIterator<T>
{
if (this.index_ == -1)
return new DequeIterator(this.source_ as Deque<T>, this.source_.size() - 1);
return new DequeIterator(this.source(), this.source_.size() - 1);
else if (this.index_ - 1 < 0)
return (this.source_ as Deque<T>).end();
return this.source().end();
else
return new DequeIterator<T>(this.source_ as Deque<T>, this.index_ - 1);
return new DequeIterator<T>(this.source(), this.index_ - 1);
}

/**
Expand All @@ -1024,9 +1032,9 @@ namespace std
public next(): DequeIterator<T>
{
if (this.index_ >= this.source_.size() - 1)
return (this.source_ as Deque<T>).end();
return this.source().end();
else
return new DequeIterator<T>(this.source_ as Deque<T>, this.index_ + 1);
return new DequeIterator<T>(this.source(), this.index_ + 1);
}

/**
Expand All @@ -1041,9 +1049,9 @@ namespace std
new_index = this.index_ + n;

if (new_index < 0 || new_index >= this.source_.size())
return (this.source_ as Deque<T>).end();
return this.source().end();
else
return new DequeIterator<T>(this.source_ as Deque<T>, new_index);
return new DequeIterator<T>(this.source(), new_index);
}

/* ---------------------------------------------------------
Expand Down Expand Up @@ -1081,7 +1089,7 @@ namespace std
* @author Jeongho Nam <http://samchon.org>
*/
export class DequeReverseIterator<T>
extends ReverseIterator<T, DequeIterator<T>, DequeReverseIterator<T>>
extends ReverseIterator<T, Deque<T>, DequeIterator<T>, DequeReverseIterator<T>>
implements base.IArrayIterator<T>
{
/* ---------------------------------------------------------
Expand All @@ -1108,6 +1116,14 @@ namespace std
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
/**
* @inheritdoc
*/
public index(): number
{
return this.base_.index();
}

/**
* @inheritdoc
*/
Expand All @@ -1125,13 +1141,5 @@ namespace std
{
this.base_.value = val;
}

/**
* Get index.
*/
public get index(): number
{
return this.base_.index;
}
}
}
6 changes: 3 additions & 3 deletions ts/src/std/Functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ namespace std
* <p> This is an overload of the generic algorithm swap that improves its performance by mutually transferring
* ownership over their assets to the other container (i.e., the containers exchange references to their data, without
* actually performing any element copy or movement): It behaves as if <i>left</i>.
* {@link IContainer.swap swap}(<i>right</i>) was called. </p>
* {@link Container.swap swap}(<i>right</i>) was called. </p>
*
* @param left A {@link IContainer container} to swap its contents.
* @param right A {@link IContainer container} to swap its contents.
* @param left A {@link Container container} to swap its contents.
* @param right A {@link Container container} to swap its contents.
*/
export function swap<T>
(left: base.Container<T>, right: base.Container<T>): void;
Expand Down
Loading

0 comments on commit c4ed516

Please sign in to comment.