Safe Haskell | None |
---|---|
Language | Haskell98 |
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
- readInt :: String -> Maybe Int
- readIntFromByteString :: ByteString -> Maybe Int
- loadInt :: Ptr Word8 -> Int -> b -> (Int -> Int -> b) -> b
- loadInt# :: Addr# -> Int# -> (#Int#, Int#, Int##)
- loadIntWith# :: Int# -> (Int# -> Int#) -> (#Int#, Int#, Int##)
- showInt :: Int -> String
- showIntToByteString :: Int -> ByteString
- showIntPad :: Int -> Int -> String
- showIntPadToByteString :: Int -> Int -> ByteString
- storeInt :: Ptr Word8 -> Int -> IO Int
- storeInt# :: Addr# -> Int# -> IO Int
- storeIntWith# :: (Int# -> IO buf) -> (buf -> Int# -> Int# -> IO ()) -> Int# -> (buf -> Int# -> IO b) -> IO b
- storeIntPad :: Ptr Word8 -> Int -> Int -> IO Int
- storeIntPad# :: Addr# -> Int# -> Int# -> IO Int
- storeIntPadWith# :: (Int# -> IO buf) -> (buf -> Int# -> Int# -> IO ()) -> Int# -> Int# -> (buf -> Int# -> IO b) -> IO b
Reading from strings
Loading from buffers
:: 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.
:: 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
showIntToByteString :: Int -> ByteString Source #
Show an Int
, allocating a new ByteString
.
Padded
showIntPadToByteString :: Int -> Int -> ByteString Source #
Show an Int
, allocating a new ByteString
.
Storing to buffers
Unpadded
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.
:: (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
:: 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.
:: 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.
:: (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.