Safe Haskell | Safe-Infered |
---|
Segment Descriptors.
See Data.Array.Parallel.Unlifted for how this works.
- data USegd = USegd {
- usegd_lengths :: !(Vector Int)
- usegd_indices :: !(Vector Int)
- usegd_elements :: !Int
- mkUSegd :: Vector Int -> Vector Int -> Int -> USegd
- valid :: USegd -> Bool
- empty :: USegd
- singleton :: Int -> USegd
- fromLengths :: Vector Int -> USegd
- length :: USegd -> Int
- takeLengths :: USegd -> Vector Int
- takeIndices :: USegd -> Vector Int
- takeElements :: USegd -> Int
- getSeg :: USegd -> Int -> (Int, Int)
- append :: USegd -> USegd -> USegd
- slice :: USegd -> Int -> Int -> USegd
- extract :: USegd -> Int -> Int -> USegd
Types
Segment descriptor.
USegd | |
|
Constructors
:: Vector Int | Length of each segment. |
-> Vector Int | Starting index of each segment. |
-> Int | Total number of elements in the flat array. |
-> USegd |
O(1). Construct a new segment descriptor.
O(1). Check the internal consistency of a segment descriptor.
As the indices and elemens field can be generated based on the segment lengths, we check the consistency by rebuilding these fields and comparing the rebuilt ones against the originals.
singleton :: Int -> USegdSource
O(1). Construct a singleton segment descriptor. The single segment covers the given number of elements.
fromLengths :: Vector Int -> USegdSource
O(segs). Convert an array of segment lengths into a segment descriptor.
The array contains the length of each segment, and we compute the indices from that.
Projections
takeLengths :: USegd -> Vector IntSource
O(1). Yield the lengths of the individual segments.
takeIndices :: USegd -> Vector IntSource
O(1). Yield the segment indices of a segment descriptor.
takeElements :: USegd -> IntSource
O(1). Yield the number of data elements.
Operations
append :: USegd -> USegd -> USegdSource
O(segs). Produce a segment descriptor that describes the result of appending two arrays.
:: USegd | Source segment descriptor. |
-> Int | Index of first segment. |
-> Int | Number of segments to slice out. |
-> USegd |
O(segs) Extract a slice of a segment descriptor, avoiding copying where possible.
We can share the segment lengths with the original segment descriptor, but still need to recompute the starting indices of each. Hence runtime is O(segs) in the number of segments sliced out.
:: USegd | Source segment desciptor. |
-> Int | Undex of the first segment. |
-> Int | Number of segments to extract out. |
-> USegd |
Extract a slice of a segment descriptor, copying everything.
In contrast to slice
, this function copies the array of
segment lengths as well as recomputing the starting indices of each.