Merge branch 'master' of https://github.com/limvot/kraken
This commit is contained in:
@@ -66,7 +66,7 @@ scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ;
|
||||
|
||||
#Note that to prevent confilct with nested templates (T<A<B>>) right_shift is a nonterminal contructed as follows
|
||||
right_shift = ">" ">" ;
|
||||
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | "<" | ">" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "\[]" | "\[]=" ;
|
||||
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | "<" | ">" | "<=" | ">=" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "\[]" | "\[]=" ;
|
||||
func_identifier = identifier | identifier overloadable_operator ;
|
||||
# allow omitting of return type (automatic void)
|
||||
|
||||
|
||||
@@ -206,6 +206,23 @@ obj str (Object, Serializable, Hashable) {
|
||||
var str.construct(other) : str
|
||||
return *this == str
|
||||
}
|
||||
fun operator<=(other: ref str): bool {
|
||||
var l = 0
|
||||
var r = 0
|
||||
while (l < length() || r < other.length()) {
|
||||
if l == length() {
|
||||
return true
|
||||
} else if r == other.length() {
|
||||
return false
|
||||
} else if (*this)[l] < other[r] {
|
||||
return true
|
||||
} else if (*this)[l] > other[r] {
|
||||
return false
|
||||
}
|
||||
l++
|
||||
r++
|
||||
}
|
||||
}
|
||||
|
||||
fun operator*(n: int): str {
|
||||
var to_ret.construct(): str
|
||||
|
||||
@@ -357,5 +357,28 @@ obj vec<T> (Object, Serializable) {
|
||||
initial = func(data[i], initial)
|
||||
return initial
|
||||
}
|
||||
fun sorted<U>(less_than: run(ref U, ref U): bool): vec<T> {
|
||||
if size < 2 {
|
||||
return *this
|
||||
} else {
|
||||
var left = slice(0, size/2).sorted(less_than)
|
||||
var right = slice(size/2, -1).sorted(less_than)
|
||||
var to_ret.construct(size): vec<T>
|
||||
var l = 0
|
||||
var r = 0
|
||||
while (l < left.size || r < right.size) {
|
||||
if l == left.size {
|
||||
to_ret.add(right[r++])
|
||||
} else if r == right.size {
|
||||
to_ret.add(left[l++])
|
||||
} else if less_than(left[l], right[r]) {
|
||||
to_ret.add(left[l++])
|
||||
} else {
|
||||
to_ret.add(right[r++])
|
||||
}
|
||||
}
|
||||
return to_ret
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user