Sorts an entire array using the default ordering.
Modulevector-algorithms-0.9.1.0Haskell2010
Data.Vector.Algorithms.Heap
This module implements operations for working with a quaternary heap stored in an unboxed array. Most heapsorts are defined in terms of a binary heap, in which each internal node has at most two children. By contrast, a quaternary heap has internal nodes with up to four children. This reduces the number of comparisons in a heapsort slightly, and improves locality (again, slightly) by flattening out the heap.
- 1 type
- 16 values
- Packagevector-algorithms-0.9.1.0
- Exports17
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceHeap.hs
Sorting
5 declarationsA variant on sort that returns a vector of unique elements.
Sorts an entire array using a custom ordering.
A variant on sortBy which returns a vector of unique elements.
sortByBounds Sorts a portion of an array [l,u) using a custom ordering
Selection
3 declarationsselect Moves the lowest k elements to the front of the array. The elements will be in no particular order.
selectBy :: (PrimMonad m, MVector v e)=> Comparison e-> v (PrimState m) e-> Intnumber of elements to select, k
-> m ()
Moves the lowest (as defined by the comparison) k elements to the front of the array. The elements will be in no particular order.
selectByBounds Moves the lowest k elements in the portion [l,u) of the
array into the positions [l,k+l). The elements will be in
no particular order.
Partial sorts
3 declarationspartialSort Moves the lowest k elements to the front of the array, sorted.
The remaining values of the array will be in no particular order.
partialSortBy :: (PrimMonad m, MVector v e)=> Comparison e-> v (PrimState m) e-> Intnumber of elements to sort, k
-> m ()
Moves the lowest k elements (as defined by the comparison) to the front of the array, sorted.
The remaining values of the array will be in no particular order.
partialSortByBounds Moves the lowest k elements in the portion [l,u) of the array into positions [l,k+l), sorted.
The remaining values in [l,u) will be in no particular order. Values outside the range [l,u) will be unaffected.
Heap operations
6 declarationsheapify pop Given a heap stored in a portion of an array [l,u), swaps the top of the heap with the element at u and rebuilds the heap.
popTo Given a heap stored in a portion of an array [l,u) swaps the top of the heap with the element at position t, and rebuilds the heap.
sortHeap Given a heap stored in a portion of an array [l,u), sorts the highest values into [m,u). The elements in [l,m) are not in any particular order.
heapInsert Given a heap stored in a portion of an array [l,u) and an element e, inserts the element into the heap, resulting in a heap in [l,u].
Note: it is best to only use this operation when incremental construction of a heap is required. heapify is capable of building a heap in O(n) time, while repeated insertion takes O(n*log n) time.
A type of comparisons between two values of a given type.