repa-scalar-4.2.3.1: Scalar data types and conversions.

Safe HaskellNone
LanguageHaskell98

Data.Repa.Scalar.Int

Contents

Description

Loading and storing integers directly from/to memory buffers.

  • The implementation uses native Haskell unboxed primitives. There there should not be any significant performance penalty relative to the standard implementations in other languages (like C).

Synopsis

Reading from strings

readInt :: String -> Maybe Int Source #

Read an Int from a String, or Nothing if this isn't one.

readIntFromByteString :: ByteString -> Maybe Int Source #

Read an Int from a ByteString, or Nothing if this isn't one.

Loading from buffers

loadInt Source #

Arguments

:: Ptr Word8

Buffer holding digits.

-> Int

Length of buffer.

-> b

On convert failure, return this value.

-> (Int -> Int -> b)

On convert success, given int read and number of chars.

-> b 

Load an ASCII Int from a foreign buffer, returning the value and number of characters read.

  • This function is set to INLINE. It unboxes the pointer and integer then calls loadInt#, which is NOINLINE.

loadInt# Source #

Arguments

:: Addr#

Address of buffer holding digits

-> Int#

Length of buffer.

-> (#Int#, Int#, Int##)

Convert success?, value, length read.

Load an ASCII Int from a buffer, producing an unboxed tuple describing the result.

  • This function is set to NOINLINE, so it can be safely called from multiple places in the program.

loadIntWith# Source #

Arguments

:: Int#

Length of input buffer.

-> (Int# -> Int#)

Function to get a byte from the source.

-> (#Int#, Int#, Int##)

Convert success?, value, length read

Primitive Int loading function.

  • This function is set to INLINE, so you will get a new copy of it in the compiled program each time it is invoked. Consider providing an appropriate wrapper for your use case.

Showing to strings

Unpadded

showInt :: Int -> String Source #

Show an Int, allocating a new String.

showIntToByteString :: Int -> ByteString Source #

Show an Int, allocating a new ByteString.

Padded

showIntPad :: Int -> Int -> String Source #

Show an Int, allocating a new String.

showIntPadToByteString :: Int -> Int -> ByteString Source #

Show an Int, allocating a new ByteString.

Storing to buffers

Unpadded

storeInt Source #

Arguments

:: Ptr Word8

Pointer to output buffer.

-> Int

Int to store.

-> IO Int

Number of bytes written.

Store an ASCII Int into a buffer, producing the number of bytes written.

  • This functon is set to INLINE. It unboxes the pointer and integer then calls storeInt# which is NOINLINE.

storeInt# Source #

Arguments

:: Addr#

Address of output buffer.

-> Int#

Int to store.

-> IO Int

Number of bytes written.

Store an ASCII Int into a buffer, producing the number of bytes written.

  • This function is set to NOINLINE, so it can be safely called from multiple places in the program.

storeIntWith# Source #

Arguments

:: (Int# -> IO buf)

Function to allocate a new output buffer, given the length in bytes.

-> (buf -> Int# -> Int# -> IO ())

Function to write a byte to the buffer, given the index and byte value.

-> Int#

Int to store.

-> (buf -> Int# -> IO b)

Continuation for buffer and bytes written.

-> IO b 

Primitive Int storing function.

  • This function is set to INLINE, so you will get a new copy of it in the compiled program each time it is invoked. Consider providing an appropriate wrapper for your use case.

Padded

storeIntPad Source #

Arguments

:: Ptr Word8

Pointer to output buffer.

-> Int

Int to store.

-> Int

Minimum number of digits.

-> IO Int

Number of bytes written.

Store an ASCII Int into a buffer, producing the number of bytes written.

storeIntPad# Source #

Arguments

:: Addr#

Address of output buffer.

-> Int#

Int to store.

-> Int#

Minimum number of digits.

-> IO Int

Number of bytes written.

Store an ASCII Int into a buffer, producing the number of bytes written.

  • This function is set to NOINLINE, so it can be safely called from multiple places in the program.

storeIntPadWith# Source #

Arguments

:: (Int# -> IO buf)

Function to allocate a new output buffer, given the length in bytes.

-> (buf -> Int# -> Int# -> IO ())

Function to write a byte to the buffer, given the index and byte value.

-> Int#

Int to store.

-> Int#

Pad out result to achieve at this many digits.

-> (buf -> Int# -> IO b)

Continuation for buffer and bytes written.

-> IO b 

Like storeIntWith#, but add leading zeros to the front of the integer to pad it out to at least the given number of digits.