repa-array-4.2.3.1: Bulk array representations and operators.

Safe HaskellNone
LanguageHaskell98

Data.Repa.Array.Generic.Unpacks

Synopsis

Documentation

unsafeUnpacksToBuffer Source #

Arguments

:: (Unpackable format, TargetI lStart Int, TargetI lEnd Int, TargetI lVal (Value format)) 
=> format

Format for each element.

-> Word8

Field separator character.

-> Array F Word8

Packed binary source data.

-> Buffer lStart Int

Starting offsets for fields.

-> Buffer lEnd Int

Ending offsets of rows.

-> Buffer lVal (Value format)

Destination buffer for parsed fields.

-> IO (Maybe (Int, Int))

Nothing on successful parse.

Given a buffer containing an encoded table where the values in each column all have the same time, decode all the values from a single column and write them to a buffer.

For example, suppose we have a table as follows, where the rows are separated by newline characters and the field separated by spaces.

RED 1.0 0.0 0.0
GREEN 0.0 1.0 0.0
BLUE 0.0 0.0 1.0
CYAN 0.0 1.0 1.0

To decode the second column use:

  • Format: DoubleAsc, as they are encoded doubles.
  • Field separator: ' ' as the fields are separated by spaces.
  • Starting offsets: [3, 21, 38, 55], which are the indices of the starting character of each field in the second column.
  • Ending offsets: [16, 34, 51, 68], which are the indices of the newline characters.
  • Destination buffer: an new buffer with at least as many elements as there are lines in the input data.

If the parse succeeds then the buffer containing the starting offets is updated so each element is the index of the NEXT field in each column. This allows the client to easilly decode the next column.

If there was a parse error then this function returns a pair of the row index and offset in the buffer of the field which could not be parsed.

UNSAFE: Both the buffer containing ending offsets, and the destination buffer must be at least as long as the buffer containing starting offsets but this is not checked. If this is not true then the function will will perform an out of bounds access.

INLINE: This function is set to INLINE so that it will be specialised at the call site for the given format. For standard formats it's better to use the pre-specialised versions for Auto arrays.