Static Public Member Functions | |
| static | sortByKeys (&$items, $keys) |
| Sorts an array based on a defined key order. | |
| static | stableSort (array &$items, $comparator, $keepKeys=false) |
| Use a stable sorting algorithm to sort on an array. | |
| static | stableSortMap (array &$keys, array &$values, $comparator) |
| Use a stable sorting algorithm to sort on a ma map. | |
Static Private Member Functions | |
| static | mergeSort (&$items, $comparator, $offset, $length) |
| An implementation of merge sort. | |
| static | merge (&$items, $comparator, $offset1, $length1, $offset2, $length2) |
| A merge function for the merge sort implementation. | |
| static | swap (&$items, $offset1, $offset2) |
| Swaps two elements of an array. | |
Started with the need for stable sorting algorithm, which PHP doesn't provide.
Definition at line 8 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::merge | ( | &$ | items, | |
| $ | comparator, | |||
| $ | offset1, | |||
| $ | length1, | |||
| $ | offset2, | |||
| $ | length2 | |||
| ) | [static, private] |
A merge function for the merge sort implementation.
Merges two sorted chunks of the array.
| $items | The items to sort. | |
| $comparator | A comparing function as accepted by spunQ_Callback::call(). See stableSort() for an in-depth explanation. | |
| offset1 | The start offset of the first chunk to merge. | |
| length1 | Length of the first chunk. | |
| offset2 | The start offset of the second chunk to merge. | |
| length2 | Length of the second chunk. |
Definition at line 131 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::mergeSort | ( | &$ | items, | |
| $ | comparator, | |||
| $ | offset, | |||
| $ | length | |||
| ) | [static, private] |
An implementation of merge sort.
All operations are performed in-place.
| $items | The items to sort. | |
| $comparator | A comparing function as accepted by spunQ_Callback::call(). See stableSort() for an in-depth explanation. | |
| $offset | The array index to start sorting from. | |
| $length | The array index to sort until. |
Definition at line 97 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::sortByKeys | ( | &$ | items, | |
| $ | keys | |||
| ) | [static] |
Sorts an array based on a defined key order.
E.g. useful for sorting the return value of getByIds(). Example:
$objects = db()->getByIds($ids, $type); spunQ_CallbackSorter::sortByKeys($objects, $ids)
Definition at line 20 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::stableSort | ( | array &$ | items, | |
| $ | comparator, | |||
| $ | keepKeys = false | |||
| ) | [static] |
Use a stable sorting algorithm to sort on an array.
Stable means that objects with the same want change order.
| $items | Array of items to sort. Note that this is a reference and the operation will be performed in-place. | |
| $comparator | A comparing function as accepted by spunQ_Callback::call(). The function must return a negative value, if the first parameter is smaller than the second value, 0 if they are equal and a positive value otherwise. This format is the same as for the builtin function usort(). See http://php.net/usort. | |
| $keepKeys | Whether key order should be maintained. Setting this to true will slow down function a bit. |
Definition at line 45 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::stableSortMap | ( | array &$ | keys, | |
| array &$ | values, | |||
| $ | comparator | |||
| ) | [static] |
Use a stable sorting algorithm to sort on a ma map.
Stable means that objects with the same want change order. Note that maps actually do not have an order, that's why the keys and values are passed separately. Note that each key/value pair will be matched by common array keys as described in spunQ_Map::getKeys().
| $keys | The keys of the map. The keys are adjusted to match the indexes of the values array. The values are the ones that are actually sorted. | |
| $values | The values to sort. Note that this parameter is a reference, the sorting is done in-place. | |
| $comparator | A comparing function as accepted by spunQ_Callback::call(). The function must return a negative value, if the first parameter is smaller than the second value, 0 if they are equal and a positive value otherwise. This format is the same as for the builtin function usort(). See http://php.net/usort. |
Definition at line 76 of file CallbackSorter.class.php.
| static spunQ_CallbackSorter::swap | ( | &$ | items, | |
| $ | offset1, | |||
| $ | offset2 | |||
| ) | [static, private] |
Swaps two elements of an array.
| $items | the array to swap items in. | |
| $offset1 | index of the first item. | |
| $offset2 | index of the second item. |
Definition at line 156 of file CallbackSorter.class.php.
1.5.9