More work, finishing the parse_input and lots of reducer

This commit is contained in:
Nathan Braswell
2015-08-06 17:38:41 -04:00
parent 1f119af8ad
commit 674e7e6538
13 changed files with 315 additions and 75 deletions

View File

@@ -1,12 +1,13 @@
import mem
import vector
fun greater<T>(a: T, b: T): T {
fun max<T>(a: T, b: T): T {
if (a > b)
return a;
return b;
}
fun lesser<T>(a: T, b: T): T {
fun min<T>(a: T, b: T): T {
if (a > b)
return b;
return a;
@@ -42,6 +43,12 @@ obj pair<T,U> (Object) {
mem::maybe_destruct(&first)
mem::maybe_destruct(&second)
}
// the old unnecessary template to prevent generation
// if not used trick (in this case, changing out U with V)
fun operator==<V>(other: ref pair<T,V>): bool {
return first == other.first && second == other.second
}
}
fun range(end:int): range {
@@ -71,6 +78,12 @@ obj range {
for (var i = begin; i < end; i+= step;)
func(i)
}
fun map<T>(func: fun(int): T): vector::vector<T> {
var ret.construct( (end-begin)/step + 1 ) : vector::vector<T>
for (var i = begin; i < end; i+= step;)
ret.addEnd(func(i))
return ret
}
fun any_true(func: fun(int):bool):bool {
for (var i = begin; i < end; i+= step;)
if (func(i))