naming convention corrected
@@ -182,12 +182,12 @@ $.assert(arr.sum() == 15)
},
_partition: #[desc("Private function needed for .sort()")]
- (self, low: @number, high: @number, key: @macro = (a, b) => a <= b) {
+ (self, low: @number, high: @number, comp: @macro = (a, b) => a <= b) {
pivot = self[high]
let i = low - 1
for j in low..high {
- if key(self[j], pivot) {
+ if comp(self[j], pivot) {
i += 1
self[i] <=> self[j]
}
@@ -210,7 +210,7 @@ arr = [5, 1, 5, 3, 2]
arr.sort(key = (a, b) => a > b)
$.assert(arr == [5, 5, 3, 2, 1])
")]
- (self, begin: @number = 0, end: @number = -1, key: @macro = (a, b) => a <= b) {
+ (self, begin: @number = 0, end: @number = -1, comp: @macro = (a, b) => a <= b) {
// when end == -1, that means the end of the array, but comparing to -1 doesnt work so switch it back to legnth - 1
let new_end = end
@@ -222,10 +222,10 @@ $.assert(arr == [5, 5, 3, 2, 1])
// no type checking becuase theoretically this can sort anything if it hasthe right comparator
// if sort was overloaded we could have two seperate implementations
if begin < new_end {
- let q = self._partition(low = begin, high = new_end, key = key)
+ let q = self._partition(low = begin, high = new_end, comp = comp)
- self.sort(begin = begin, end = q-1, key = key)
- self.sort(begin = q+1, end = new_end, key = key)
+ self.sort(begin = begin, end = q-1, comp = comp)
+ self.sort(begin = q+1, end = new_end, comp = comp)
}
},
