A stable merge sort.
Name | Type | Description |
---|---|---|
array |
Array | The array to sort. |
comparator |
mergeSort~Comparator | The function to use to compare elements in the array. |
userDefinedObject |
Object |
optional
An object to pass as the third parameter to comparator . |
Example:
// Assume array contains BoundingSpheres in world coordinates.
// Sort them in ascending order of distance from the camera.
var position = camera.positionWC;
Cesium.mergeSort(array, function(a, b, position) {
return Cesium.BoundingSphere.distanceSquaredTo(b, position) - Cesium.BoundingSphere.distanceSquaredTo(a, position);
}, position);
Type Definitions
-
A function used to compare two items while performing a merge sort.
Name Type Description a
Object An item in the array. b
Object An item in the array. userDefinedObject
Object optional An object that was passed to mergeSort
.Returns:
Returns a negative value ifa
is less thanb
, a positive value ifa
is greater thanb
, or 0 ifa
is equal tob
.Example:
function compareNumbers(a, b, userDefinedObject) { return a - b; }