HH\Lib\Keyset\sort

Meta Engineer?

This is available as Keyset\sort in the www repository.

Returns a new keyset sorted by the values of the given Traversable

namespace HH\Lib\Keyset;

function sort<Tv as arraykey>(
  Traversable<Tv> $traversable,
  ?(function(Tv, Tv): num) $comparator = NULL,
): keyset<Tv>;

If the optional comparator function isn't provided, the values will be sorted in ascending order.

Time complexity: O((n log n) * c), where c is the complexity of the comparator function (which is O(1) if not explicitly provided) Space complexity: O(n)

Parameters

Returns

  • keyset<Tv>

Examples

$result = Keyset\sort(keyset[1,200, 5]);
print_r($result);
//result: keyset[1,5,200]

$result = Keyset\sort(keyset[100,2000,3,4]);
print_r($result);
//result: keyset[3,4,100,2000]