Comparing version 0.0.2 to 0.0.3
@@ -48,4 +48,4 @@ import { Pair } from "../utility/Pair"; | ||
{ | ||
const lower = lower_bound(first, last, val, comp); | ||
const upper = upper_bound(first, last, val, comp); | ||
const lower: ForwardIterator = lower_bound<ForwardIterator, T, Comparator>(first, last, val, comp); | ||
const upper: ForwardIterator = upper_bound<ForwardIterator, T, Comparator>(lower, last, val, comp); | ||
@@ -59,4 +59,4 @@ return new Pair(lower, upper); | ||
{ | ||
first = lower_bound(first, last, val, comp); | ||
first = lower_bound<ForwardIterator, T, Comparator>(first, last, val, comp); | ||
return first != last && comp(val, first.value) === false; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { distance } from "../iterator/global"; | ||
import { advance, distance } from "../iterator/global"; | ||
@@ -11,3 +11,3 @@ /* ========================================================= | ||
--------------------------------------------------------- */ | ||
export function make_heap<RandomAccessIterator, Comparator, T> | ||
export function make_heap<RandomAccessIterator, Comparator> | ||
(first: RandomAccessIterator, last: RandomAccessIterator, comp: Comparator): void | ||
@@ -22,4 +22,4 @@ { | ||
{ | ||
const temp: T = first.advance(--parentPosition).value; | ||
_Adjust_heap<RandomAccessIterator, T, Comparator>(first, parentPosition, heapSize, parentPosition, temp, comp); | ||
const temp = first.advance(--parentPosition).value; | ||
_Adjust_heap(first, parentPosition, heapSize, parentPosition, temp, comp); | ||
} | ||
@@ -29,3 +29,3 @@ while (parentPosition !== 0); | ||
export function push_heap<RandomAccessIterator, Comparator, T> | ||
export function push_heap<RandomAccessIterator, Comparator> | ||
( | ||
@@ -37,4 +37,4 @@ first: RandomAccessIterator, | ||
{ | ||
const temp: T = last.prev().value; | ||
_Promote_heap<RandomAccessIterator, T, Comparator>(first, 0, distance(first, last) - 1, temp, comp); | ||
const temp = last.prev().value; | ||
_Promote_heap(first, 0, distance(first, last) - 1, temp, comp); | ||
} | ||
@@ -49,3 +49,3 @@ | ||
*/ | ||
export function pop_heap<RandomAccessIterator, Comparator, T> | ||
export function pop_heap<RandomAccessIterator, Comparator> | ||
( | ||
@@ -57,7 +57,7 @@ first: RandomAccessIterator, | ||
{ | ||
const bottom: RandomAccessIterator = last.prev(); | ||
const temp: T = bottom.value; | ||
const bottom = last.prev(); | ||
const temp = bottom.value; | ||
bottom.value = first.value; | ||
_Adjust_heap<RandomAccessIterator, T, Comparator>(first, 0, distance(first, last) - 1, 0, temp, comp); | ||
_Adjust_heap(first, 0, distance(first, last) - 1, 0, temp, comp); | ||
} | ||
@@ -75,4 +75,4 @@ | ||
{ | ||
const it = is_heap_until(first, last, comp); | ||
return it.equals(last); | ||
const it: RandomAccessIterator = is_heap_until(first, last, comp); | ||
return it == last; | ||
} | ||
@@ -87,3 +87,3 @@ | ||
{ | ||
let counter: number = 0; | ||
let counter: isize = 0; | ||
for (let child = first.next(); child < last; child = child.next(), counter ^= 1) | ||
@@ -98,3 +98,3 @@ { | ||
export function sort_heap<RandomAccessIterator, Comparator, T> | ||
export function sort_heap<RandomAccessIterator, Comparator> | ||
( | ||
@@ -107,3 +107,3 @@ first: RandomAccessIterator, | ||
for (; distance(first, last) > 1; last = last.prev()) | ||
pop_heap<RandomAccessIterator, Comparator, T>(first, last, comp); | ||
pop_heap<RandomAccessIterator, Comparator>(first, last, comp); | ||
} | ||
@@ -110,0 +110,0 @@ |
@@ -85,3 +85,3 @@ import { Pair } from "../utility/Pair"; | ||
for (let it = first1; it != last1; it = it.next()) | ||
if (_Find_if(first1, it, pred, it) == it) | ||
if (_Find_if(first1, it, it, pred) == it) | ||
{ | ||
@@ -95,3 +95,3 @@ const n: usize = _Count_if(first2, last2, it, pred); | ||
export function prev_permutation<BidirectionalIterator, Comparator, T> | ||
export function prev_permutation<BidirectionalIterator, Comparator> | ||
( | ||
@@ -120,4 +120,4 @@ first: BidirectionalIterator, last: BidirectionalIterator, | ||
iter_swap<BidirectionalIterator, BidirectionalIterator, T>(previous, y); | ||
reverse<BidirectionalIterator, T>(x, last); | ||
iter_swap(previous, y); | ||
reverse(x, last); | ||
return true; | ||
@@ -128,3 +128,3 @@ } | ||
{ | ||
reverse<BidirectionalIterator, T>(first, last); | ||
reverse(first, last); | ||
return false; | ||
@@ -135,3 +135,3 @@ } | ||
export function next_permutation<BidirectionalIterator, Comparator, T> | ||
export function next_permutation<BidirectionalIterator, Comparator> | ||
( | ||
@@ -171,2 +171,32 @@ first: BidirectionalIterator, last: BidirectionalIterator, | ||
} | ||
// if (first == last) | ||
// return false; | ||
// let previous: BidirectionalIterator = last.prev(); | ||
// if (first == previous) | ||
// return false; | ||
// while (true) | ||
// { | ||
// const x: BidirectionalIterator = previous; | ||
// previous = previous.prev(); | ||
// if (comp(previous.value, x.value) === true) | ||
// { | ||
// let y: BidirectionalIterator = last.prev(); | ||
// while (comp(previous.value, y.value) === false) | ||
// y = y.prev(); | ||
// iter_swap<BidirectionalIterator, BidirectionalIterator>(previous, y); | ||
// reverse<BidirectionalIterator>(x, last); | ||
// return true; | ||
// } | ||
// if (previous == first) | ||
// { | ||
// reverse<BidirectionalIterator>(first, last); | ||
// return false; | ||
// } | ||
// } | ||
} | ||
@@ -196,5 +226,5 @@ | ||
for (; first != last; first = first.next()) | ||
if (pred(first.value, it.value)) | ||
if (pred(first.value, it.value) === true) | ||
return first; | ||
return last; | ||
} |
@@ -304,6 +304,6 @@ import { advance } from "../iterator/global"; | ||
export function iter_swap<ForwardIterator1, ForwardIterator2, T> | ||
export function iter_swap<ForwardIterator1, ForwardIterator2> | ||
(x: ForwardIterator1, y: ForwardIterator2): void | ||
{ | ||
const value: T = x.value; | ||
const value = x.value; | ||
x.value = y.value; | ||
@@ -313,3 +313,3 @@ y.value = value; | ||
export function swap_ranges<ForwardIterator1, ForwardIterator2, T> | ||
export function swap_ranges<ForwardIterator1, ForwardIterator2> | ||
(first1: ForwardIterator2, last1: ForwardIterator2, first2: ForwardIterator2): ForwardIterator2 | ||
@@ -319,3 +319,3 @@ { | ||
{ | ||
iter_swap<ForwardIterator1, ForwardIterator2, T>(first1, first2); | ||
iter_swap<ForwardIterator1, ForwardIterator2>(first1, first2); | ||
first2 = first2.next(); | ||
@@ -329,8 +329,8 @@ } | ||
--------------------------------------------------------- */ | ||
export function reverse<BidirectionalIterator, T> | ||
export function reverse<BidirectionalIterator> | ||
(first: BidirectionalIterator, last: BidirectionalIterator): void | ||
{ | ||
while (first != last && first != last.prev()) | ||
while (first != last && first != (last = last.prev())) | ||
{ | ||
iter_swap<BidirectionalIterator, BidirectionalIterator, T>(first, last); | ||
iter_swap<BidirectionalIterator, BidirectionalIterator>(first, last); | ||
first = first.next(); | ||
@@ -367,3 +367,3 @@ } | ||
export function rotate<InputIterator, T> | ||
export function rotate<InputIterator> | ||
(first: InputIterator, middle: InputIterator, last: InputIterator): InputIterator | ||
@@ -373,3 +373,3 @@ { | ||
{ | ||
iter_swap<InputIterator, InputIterator, T>(first, middle); | ||
iter_swap<InputIterator, InputIterator>(first, middle); | ||
@@ -389,3 +389,3 @@ first = first.next(); | ||
export function shuffle<RandomAccessIterator, T> | ||
export function shuffle<RandomAccessIterator> | ||
(first: RandomAccessIterator, last: RandomAccessIterator): void | ||
@@ -397,4 +397,4 @@ { | ||
if (it.index() !== index) | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(it, first.advance(index)); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(it, first.advance(index)); | ||
} | ||
} |
@@ -42,9 +42,9 @@ import { Pair } from "../utility/Pair"; | ||
@inline() | ||
export function partition<BidirectionalIterator, UnaryPredicator, T> | ||
export function partition<BidirectionalIterator, UnaryPredicator> | ||
(first: BidirectionalIterator, last: BidirectionalIterator, pred: UnaryPredicator): BidirectionalIterator | ||
{ | ||
return stable_partition<BidirectionalIterator, UnaryPredicator, T>(first, last, pred); | ||
return stable_partition<BidirectionalIterator, UnaryPredicator>(first, last, pred); | ||
} | ||
export function stable_partition<BidirectionalIterator, UnaryPredicator, T> | ||
export function stable_partition<BidirectionalIterator, UnaryPredicator> | ||
(first: BidirectionalIterator, last: BidirectionalIterator, pred: UnaryPredicator): BidirectionalIterator | ||
@@ -69,3 +69,3 @@ { | ||
iter_swap<BidirectionalIterator, UnaryPredicator, T>(first, last); | ||
iter_swap<BidirectionalIterator, UnaryPredicator>(first, last); | ||
first = first.next(); | ||
@@ -72,0 +72,0 @@ } |
import { Vector } from "../container/Vector"; | ||
import { Comparator } from "../internal/functional/Comparator"; | ||
@@ -10,3 +11,3 @@ import { CMath } from "../internal/numeric/CMath"; | ||
{ | ||
const value: f64 = Math.round(Math.random() * (y - x)); | ||
const value: f64 = Math.round(Math.random() * (y - x) + x); | ||
return <T>value; | ||
@@ -22,6 +23,6 @@ } | ||
// GENERATE REMAINDERS | ||
const step: usize = distance(first, last); | ||
const remainders: usize[] = []; | ||
const step: isize = distance(first, last); | ||
const remainders: isize[] = []; | ||
for (let i: number = 0; i < step; ++i) | ||
for (let i: isize = 0; i < step; ++i) | ||
remainders.push(i); | ||
@@ -32,12 +33,12 @@ | ||
//---- | ||
const advances: Vector<usize> = new Vector(); | ||
const advances: Vector<isize> = new Vector(); | ||
n = CMath.min(n, step); | ||
// PICK SAMPLE INDEXES | ||
for (let i: usize = 0; i < n; ++i) | ||
for (let i: isize = 0; i < <isize>n; ++i) | ||
{ | ||
const index: usize = randint<usize>(0, <usize>remainders.length - 1); | ||
advances.push_back(remainders.splice(index, 1)[0]); | ||
const index: isize = randint<isize>(0, <isize>remainders.length - 1); | ||
advances.push_back(remainders.splice(<i32>index, 1)[0]); | ||
} | ||
sort<Vector.Iterator<usize>, (x: usize, y: usize) => boolean, usize>(advances.begin(), advances.end(), (x, y) => x < y); | ||
sort<Vector.Iterator<isize>, Comparator<isize>>(advances.begin(), advances.end(), (x, y) => x < y); | ||
@@ -51,3 +52,3 @@ // CHANGE INDEXES TO ADVANCES | ||
//---- | ||
for (let i: usize = 0; i < advances.size(); ++i) | ||
for (let i: isize = 0; i < <isize>advances.size(); ++i) | ||
{ | ||
@@ -54,0 +55,0 @@ first = advance(first, advances.at(i)); |
@@ -13,3 +13,3 @@ import { Vector } from "../container/Vector"; | ||
--------------------------------------------------------- */ | ||
export function sort<RandomAccessIterator, Comparator, T> | ||
export function sort<RandomAccessIterator, Comparator> | ||
( | ||
@@ -20,3 +20,3 @@ first: RandomAccessIterator, last: RandomAccessIterator, | ||
{ | ||
const length: isize = distance(first, last); | ||
const length: usize = distance(first, last); | ||
if (length <= 0) | ||
@@ -26,6 +26,6 @@ return; | ||
const pivotIt: RandomAccessIterator = first.advance(length / 2); | ||
const pivot: T = pivotIt.value; | ||
const pivot = pivotIt.value; | ||
if (pivotIt != first) | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(first, pivotIt); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(first, pivotIt); | ||
@@ -38,13 +38,13 @@ let i: usize = 1; | ||
{ | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(jeIt, first.advance(i)); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(jeIt, first.advance(i)); | ||
++i; | ||
} | ||
} | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(first, first.advance(i - 1)); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(first, first.advance(i - 1)); | ||
sort<RandomAccessIterator, Comparator, T>(first, first.advance(i - 1), comp); | ||
sort<RandomAccessIterator, Comparator, T>(first.advance(i), last, comp); | ||
sort<RandomAccessIterator, Comparator>(first, first.advance(i - 1), comp); | ||
sort<RandomAccessIterator, Comparator>(first.advance(i), last, comp); | ||
} | ||
export function stable_sort<RandomAccessIterator, Comparator, T> | ||
export function stable_sort<RandomAccessIterator, Comparator> | ||
( | ||
@@ -60,6 +60,6 @@ first: RandomAccessIterator, last: RandomAccessIterator, | ||
const pivotIt: RandomAccessIterator = first.advance(length / 2); | ||
const pivot: T = pivotIt.value; | ||
const pivot = pivotIt.value; | ||
if (pivotIt != first) | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(first, pivotIt); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(first, pivotIt); | ||
@@ -72,13 +72,13 @@ let i: usize = 1; | ||
{ | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(jeIt, first.advance(i)); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(jeIt, first.advance(i)); | ||
++i; | ||
} | ||
} | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(first, first.advance(i - 1)); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(first, first.advance(i - 1)); | ||
sort<RandomAccessIterator, Comparator, T>(first, first.advance(i - 1), comp); | ||
sort<RandomAccessIterator, Comparator, T>(first.advance(i), last, comp); | ||
sort<RandomAccessIterator, Comparator>(first, first.advance(i - 1), comp); | ||
sort<RandomAccessIterator, Comparator>(first.advance(i), last, comp); | ||
} | ||
export function partial_sort<RandomAccessIterator, Comparator, T> | ||
export function partial_sort<RandomAccessIterator, Comparator> | ||
( | ||
@@ -96,3 +96,3 @@ first: RandomAccessIterator, middle: RandomAccessIterator, last: RandomAccessIterator, | ||
if (i != min) | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(i, min); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(i, min); | ||
} | ||
@@ -113,3 +113,3 @@ } | ||
vector.insert(vector.end(), first, last); | ||
sort<Vector.Iterator<T>, Comparator, T>(vector.begin(), vector.end(), comp); | ||
sort<Vector.Iterator<T>, Comparator>(vector.begin(), vector.end(), comp); | ||
@@ -124,3 +124,3 @@ if (inputLength > resultLength) | ||
export function nth_element<RandomAccessIterator, Comparator, T> | ||
export function nth_element<RandomAccessIterator, Comparator> | ||
( | ||
@@ -143,3 +143,3 @@ first: RandomAccessIterator, nth: RandomAccessIterator, last: RandomAccessIterator, | ||
{ | ||
iter_swap<RandomAccessIterator, RandomAccessIterator, T>(nth, i); | ||
iter_swap<RandomAccessIterator, RandomAccessIterator>(nth, i); | ||
return; | ||
@@ -146,0 +146,0 @@ } |
@@ -25,3 +25,3 @@ import { Vector } from "./Vector"; | ||
this.data_.push_back(elem); | ||
push_heap<Vector.Iterator<T>, Comparator<T, T>, T>(this.data_.begin(), this.data_.end(), this.comp_); | ||
push_heap<Vector.Iterator<T>, Comparator<T, T>>(this.data_.begin(), this.data_.end(), this.comp_); | ||
} | ||
@@ -32,3 +32,3 @@ | ||
{ | ||
pop_heap<Vector.Iterator<T>, Comparator<T, T>, T>(this.data_.begin(), this.data_.end(), this.comp_); | ||
pop_heap<Vector.Iterator<T>, Comparator<T, T>>(this.data_.begin(), this.data_.end(), this.comp_); | ||
this.data_.pop_back(); | ||
@@ -35,0 +35,0 @@ } |
@@ -155,2 +155,9 @@ import { VectorContainer } from "../internal/container/linear/VectorContainer"; | ||
@inline() | ||
@operator("<") | ||
public less(obj: Vector.Iterator<T>): boolean | ||
{ | ||
return this.index_ < obj.index_; | ||
} | ||
@inline() | ||
public get value(): T | ||
@@ -157,0 +164,0 @@ { |
@@ -1,4 +0,2 @@ | ||
import { IForwardIterator } from "./IForwardIterator"; | ||
export function advance<InputIterator extends IForwardIterator<any, InputIterator>> | ||
export function advance<InputIterator> | ||
(it: InputIterator, n: isize): InputIterator | ||
@@ -11,3 +9,3 @@ { | ||
export function distance<IteratorT extends IForwardIterator<any, IteratorT>> | ||
export function distance<IteratorT> | ||
(first: IteratorT, last: IteratorT): isize | ||
@@ -14,0 +12,0 @@ { |
@@ -1,7 +0,5 @@ | ||
import { IPointer } from "../functional/IPointer"; | ||
export declare interface IForwardIterator<T, Iterator extends IForwardIterator<T, Iterator>> | ||
extends IPointer<T> | ||
export interface IForwardIterator<T, Iterator extends IForwardIterator<T, Iterator>> | ||
{ | ||
value: T; | ||
next(): Iterator; | ||
} |
@@ -1,2 +0,1 @@ | ||
export * from "./global"; | ||
export * from "./IBidirectionalIterator"; | ||
@@ -6,2 +5,7 @@ export * from "./IForwardIterator"; | ||
export * from "./IReversableIterator"; | ||
export * from "./IReverseIterator"; | ||
export * from "./IReverseIterator"; | ||
export * from "./BackInsertIterator"; | ||
export * from "./factory"; | ||
export * from "./global"; |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "./index.ts", | ||
@@ -12,0 +12,0 @@ "scripts": { |
@@ -6,3 +6,8 @@ import std from "../../../index"; | ||
{ | ||
StopWatch.measure("test_priority_queue", () => | ||
StopWatch.measure("test_priority_queue", test_priority_queue.core); | ||
} | ||
export namespace test_priority_queue | ||
{ | ||
export function core(): void | ||
{ | ||
@@ -36,3 +41,3 @@ const adaptor: std.PriorityQueue<i32> = new std.PriorityQueue(); | ||
} | ||
}); | ||
} | ||
} |
//---- | ||
// ALGORITHM | ||
//---- | ||
// BINARY-SERACH | ||
import { test_binary_search } from "./algorithm/binary_search/test_binary_search"; | ||
import { test_equal_range } from "./algorithm/binary_search/test_equal_range"; | ||
import { test_lower_bound } from "./algorithm/binary_search/test_lower_bound"; | ||
import { test_upper_bound } from "./algorithm/binary_search/test_upper_bound"; | ||
// HEAP | ||
import { test_make_heap } from "./algorithm/heap/test_make_heap"; | ||
import { test_push_heap } from "./algorithm/heap/test_push_heap"; | ||
import { test_sort_heap } from "./algorithm/heap/test_sort_heap"; | ||
// MATHEMATICS | ||
import { test_max_element } from "./algorithm/mathematics/test_max_element"; | ||
import { test_min_element } from "./algorithm/mathematics/test_min_element"; | ||
import { test_minmax_element } from "./algorithm/mathematics/test_minmax_element"; | ||
import { test_next_permutation } from "./algorithm/mathematics/test_next_permutation"; | ||
import { test_prev_permutation } from "./algorithm/mathematics/test_prev_permutation"; | ||
// RANDOM | ||
import { test_randint } from "./algorithm/random/test_randint"; | ||
import { test_sample } from "./algorithm/random/test_sample"; | ||
//---- | ||
// CONTAINERS | ||
@@ -24,2 +49,5 @@ //---- | ||
//---- | ||
// FUNCTIONAL | ||
//---- | ||
import { test_hash } from "./features/functional/test_hash"; | ||
@@ -29,9 +57,27 @@ | ||
{ | ||
test_hash(); | ||
//---- | ||
// ALGORITHM | ||
//---- | ||
// BINARY SEARCH | ||
test_binary_search(); | ||
test_equal_range(); | ||
test_lower_bound(); | ||
test_upper_bound(); | ||
// HEAP | ||
test_make_heap(); | ||
test_push_heap(); | ||
// test_sort_heap(); | ||
// MATHEMATICS | ||
test_max_element(); | ||
test_min_element(); | ||
test_minmax_element(); | ||
test_next_permutation(); | ||
test_prev_permutation(); | ||
// RANDOM | ||
test_randint(); | ||
test_sample(); | ||
//---- | ||
@@ -64,2 +110,7 @@ // CONTAINERS | ||
test_storing_objects(); | ||
//---- | ||
// FUNCTIONAL | ||
//---- | ||
test_hash(); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
290478
138
7631