Maple 18 adds support for key sorting. Key sorting allows users to specify a function to map elements to keys. The input is then sorted by sorting the corresponding keys. For example, the following list of lists can be sorted by comparing the first element of each sublist.
>
|
|
| (2) |
In previous versions of Maple, this could be achieved by using a custom comparison function. Key sorting is faster because it only requires that the key function be called O(n) times, whereas a comparison function will be called O(n*log(n)) times. In addition, by performing the underlying sort operation with the default Maple comparison function, sorting can be performed in parallel.
The following example shows the timing difference (in seconds) between sorting with a comparison function and a key function.
>
|
|
>
|
|
>
|
|