Experimenting with fungll optimization, implement the okmij.org poly-variadic fix-point combinator for mutual recursion
This commit is contained in:
@@ -110,5 +110,11 @@ obj hash_map<T,U> (Object, Serializable) {
|
||||
size = 0
|
||||
data.add(map::map<T,U>())
|
||||
}
|
||||
fun pop(): util::pair<T,U> {
|
||||
for (var i = 0; i < data.size; i++;)
|
||||
if (data[i].size() > 0)
|
||||
return data[i].pop()
|
||||
io::println("trying to pop out of an empty hash_map")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,5 +127,21 @@ obj hash_set<T> (Object, Serializable) {
|
||||
}
|
||||
|
||||
}
|
||||
fun pop(): T {
|
||||
return data.pop().first
|
||||
}
|
||||
fun union(other: hash_set<T>): hash_set<T> {
|
||||
for_each(fun(i: T) {
|
||||
other.add(i)
|
||||
})
|
||||
return other
|
||||
}
|
||||
fun operator-(items: ref hash_set<T>): hash_set<T> {
|
||||
var to_ret.copy_construct(this): hash_set<T>
|
||||
items.for_each(fun(i: T) {
|
||||
to_ret.remove(i)
|
||||
})
|
||||
return to_ret
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ obj map<T,U> (Object, Serializable) {
|
||||
fun remove(key: ref T) {
|
||||
var idx = keys.find(key)
|
||||
if (idx < 0)
|
||||
util::error("trying to remove nonexistant key-value!")
|
||||
return;
|
||||
keys.remove(idx)
|
||||
values.remove(idx)
|
||||
}
|
||||
@@ -123,5 +123,8 @@ obj map<T,U> (Object, Serializable) {
|
||||
}
|
||||
return to_ret
|
||||
}
|
||||
fun pop(): util::pair<T,U> {
|
||||
return util::make_pair(keys.pop(), values.pop())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,9 +149,7 @@ obj set<T> (Object, Serializable) {
|
||||
|
||||
}
|
||||
fun pop(): T {
|
||||
var to_ret = data.last()
|
||||
data.remove(data.size-1)
|
||||
return to_ret
|
||||
return data.pop()
|
||||
}
|
||||
fun union(other: set<T>): set<T> {
|
||||
for (var i = 0; i < data.size; i++;)
|
||||
|
||||
@@ -384,5 +384,10 @@ obj vec<T> (Object, Serializable) {
|
||||
return to_ret
|
||||
}
|
||||
}
|
||||
fun pop(): T {
|
||||
var to_ret = data[size-1]
|
||||
remove(size-1)
|
||||
return to_ret
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user