Implement <TypedArray>#sort and improve default comparator (#208)

This commit is contained in:
Max Graey
2018-08-04 16:30:03 +03:00
committed by Daniel Wirtz
parent 7965776133
commit 947cee08c7
15 changed files with 9782 additions and 1643 deletions

View File

@ -32,6 +32,7 @@ export class Array<T> {
);
}
@inline
get length(): i32 {
return this.length_;
}
@ -324,12 +325,15 @@ export class Array<T> {
if (isReference<T>()) {
// TODO replace this to faster stable sort (TimSort) when it implemented
return changetype<this>(insertionSort<T>(this, comparator));
insertionSort<T>(buffer, 0, length, comparator);
return this;
} else {
return changetype<this>(length < 256
? insertionSort<T>(this, comparator)
: weakHeapSort<T>(this, comparator)
);
if (length < 256) {
insertionSort<T>(buffer, 0, length, comparator);
} else {
weakHeapSort<T>(buffer, 0, length, comparator);
}
return this;
}
}