Sort Libraries is a library of sort-related procedures for working on lists.
The library is inspired by Scheme's SRFI 132, and uses the same procedure API. The library provides procedures to sort, merge and work with sorted lists, and is useful particularly in cases where records or other structures must be ordered with custom comparison procedures.
statistics
list_binary_search (is_lt, is_equal, lst, item, start_index, end_index)
Returns the index of given item in list, or fails if item is not in list.
list_binary_search("<", "=", [1,1,2,3], 2) # => 3
Parameters:
list_delete_neighbour_dups (is_equal, lst)
Returns a new list without duplicate items from the given (sorted) list.
list_delete_neighbour_dups("=", [1,1,2,2,3]) # => [1,2,3]
Parameters:
list_find_median (is_lt, lst, nil, compute_mean)
Returns the median element from given list.
list_find_median("<", [1,2,3,4,5], 0) # => 3 list_find_median("<", [1,2,3,4], 0) # => 2.5
Parameters:
list_is_sorted (is_lt, lst)
Succeeds if the given list is sorted.
list_is_sorted("<", [1,2,2,3]) # => succeeds
Parameters:
list_merge (is_lt, lst1, lst2)
Returns a new ordered list consisting of the items in the two given lists.
list_merge("<", [1,3,5], [2,4]) # => [1,2,3,4,5]
Parameters:
list_select (is_lt, lst, k)
Returns the kth smallest element. Fails if the list is smaller than k elements.
list_select("<", [4,1,2,5], 3) # => 4
Parameters:
list_separate (is_lt, lst, k)
Destructively modifies the list to place the smallest k items at the front.
list_separate("<", [4,1,2,5], 2) # list changed to => [1,2,5,4]
Parameters:
list_sort (is_lt, lst)
Destructively sorts the given list.
list_sort(">", [3,1,2]) # list changed to => [3,2,1]
Parameters: