More ast_transformation work, but the big change was fixing regex so that it didn't have an exponential implmentation by using sets instead of vectors to deduplicate

This commit is contained in:
Nathan Braswell
2016-01-02 01:43:41 -05:00
parent 6107dda825
commit 8b77a60be5
5 changed files with 40 additions and 20 deletions

View File

@@ -26,6 +26,10 @@ obj set<T> (Object, Serializable) {
data.construct()
return this
}
fun construct(ammt: int): *set<T> {
data.construct(ammt)
return this
}
fun copy_construct(old: *set<T>) {
data.copy_construct(&old->data)
}
@@ -71,6 +75,9 @@ obj set<T> (Object, Serializable) {
if (!contains(item))
data.add(item)
}
fun add_all(items: ref set<T>) {
add(items)
}
fun add(items: ref set<T>) {
items.for_each( fun(item: ref T) add(item); )
}
@@ -94,5 +101,16 @@ obj set<T> (Object, Serializable) {
fun reduce<U>(func: fun(T,U): U, initial: U): U {
return data.reduce(func, initial)
}
fun flatten_map<U>(func: fun(T):set<U>):set<U> {
var newSet.construct(size()): set<U>
for (var i = 0; i < size(); i++;)
func(data[i]).for_each(fun(item: ref U) newSet.add(item);)
return newSet
}
fun filter(func: fun(T):bool):set<T> {
var newSet.construct(): set<T>
newSet.data = data.filter(func)
return newSet
}
}