-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
76 lines (66 loc) · 2.45 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// index.d.ts
/**
* The comparison function signature, similar to JS's Array.sort.
* @returns A positive number if a > b, negative if a < b, or 0 if equal.
*/
export type CompareFn<T> = (a: T, b: T) => number;
/**
* A function for extracting numeric values from items (used by radixSort).
* @returns The numeric value of the item.
*/
export type GetNumberFn<T> = (item: T) => number;
/**
* Sorts an array in-place using the bubble sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function bubbleSort<T>(list: T[], compare?: CompareFn<T>): T[];
/**
* Sorts an array in-place using the insertion sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function insertionSort<T>(list: T[], compare?: CompareFn<T>): T[];
/**
* Sorts an array in-place using the selection sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function selectionSort<T>(list: T[], compare?: CompareFn<T>): T[];
/**
* Sorts an array of numeric data (or data convertible to numeric)
* in-place using the radix sort algorithm.
* @param list The array to sort.
* @param order (Optional) 'asc' or 'desc' (default: 'asc').
* @param getNumber (Optional) function to extract numeric value from an item (default: (n) => n).
* @returns The same array, now sorted.
*/
export function radixSort<T>(
list: T[],
order?: 'asc' | 'desc',
getNumber?: GetNumberFn<T>
): T[];
/**
* Sorts an array in-place using the heap sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function heapSort<T>(list: T[], compare?: CompareFn<T>): T[];
/**
* Sorts an array in-place using the merge sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function mergeSort<T>(list: T[], compare?: CompareFn<T>): T[];
/**
* Sorts an array in-place using the quick sort algorithm.
* @param list The array to sort.
* @param compare (Optional) comparison function.
* @returns The same array, now sorted.
*/
export function quickSort<T>(list: T[], compare?: CompareFn<T>): T[];