Stable Sorts

Stable Sorts

Stable Sorts

Implementations of sorting benefit from consistent ordering of items whose sort parameters are equivalent (e.g. 2 records with the same time stamp). This requires choosing one or more resource attributes that, when taken together, provide a unique, sequential identifier for the resource within the collection. This ensures the resource collection always has a unique, linear ordering with respect to this identifier. Examples of possible such identifiers include:

  • Event timestamp combined with “Received Time” It is possible that 2 events can occur at the same time (“event time”) but it is impossible for 2 event data packets to arrive into the server at exactly the same time (“received time”). In the case of sorting by event time, the received time can be used as a secondary sort parameter that is used when the event times of 2 or more records are equivalent to ensure the sort order is stable.
  • People’s names combined with employee ID Similar to event timestamp, it is possible for 2 people to have the same name so using an attribute such as employee id as the secondary sort parameter ensures a stable and repeatable sort order.