Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Database.LSMTree.Internal.RawBytes
Description
This module is intended to be imported qualified, to avoid name clashes with Prelude functions:
import Database.LSMTree.Internal.RawBytes (RawBytes (..)) import qualified Database.LSMTree.Internal.RawBytes as RB
Synopsis
- newtype RawBytes = RawBytes (Vector Word8)
- size :: RawBytes -> Int
- take :: Int -> RawBytes -> RawBytes
- drop :: Int -> RawBytes -> RawBytes
- topBits64 :: RawBytes -> Word64
- copy :: RawBytes -> RawBytes
- force :: RawBytes -> ByteArray
- fromVector :: Vector Word8 -> RawBytes
- fromByteArray :: Int -> Int -> ByteArray -> RawBytes
- pack :: [Word8] -> RawBytes
- unpack :: RawBytes -> [Word8]
- fromByteString :: ByteString -> RawBytes
- unsafeFromByteString :: HasCallStack => ByteString -> RawBytes
- toByteString :: RawBytes -> ByteString
- unsafePinnedToByteString :: HasCallStack => RawBytes -> ByteString
- fromShortByteString :: ShortByteString -> RawBytes
- builder :: RawBytes -> Builder
Raw bytes
Raw bytes with no alignment constraint (i.e. byte aligned), and no guarantee of pinned or unpinned memory (i.e. could be either).
Instances
IsString RawBytes Source # | Mostly to make test cases shorter to write. |
Defined in Database.LSMTree.Internal.RawBytes Methods fromString :: String -> RawBytes # | |
Monoid RawBytes Source # | |
Semigroup RawBytes Source # | |
IsList RawBytes Source # | |
Show RawBytes Source # | |
NFData RawBytes Source # | |
Defined in Database.LSMTree.Internal.RawBytes | |
Eq RawBytes Source # | |
Ord RawBytes Source # | Lexicographical |
Defined in Database.LSMTree.Internal.RawBytes | |
Hashable RawBytes Source # | |
Defined in Database.LSMTree.Internal.RawBytes | |
type Item RawBytes Source # | |
Defined in Database.LSMTree.Internal.RawBytes |
Accessors
Length information
Extracting subvectors (slicing)
topBits64 :: RawBytes -> Word64 Source #
slices the first topBits64
rb64
bits from the top of the raw bytes
rb
. Returns the string of bits as a Word64
.
The top corresponds to the most significant bit (big-endian).
PRECONDITION: The byte-size of the raw bytes should be at least 8 bytes.
TODO: optimisation ideas: use unsafe shift/byteswap primops, look at GHC core, find other opportunities for using primops.
Construction
copy :: RawBytes -> RawBytes Source #
O(n) Yield the argument, but force it not to retain any extra memory by copying it.
Useful when dealing with slices. Also, see Database.LSMTree.Internal.Unsliced
force :: RawBytes -> ByteArray Source #
Force RawBytes
to not retain any extra memory. This may copy the contents.
Conversions
Lists
bytestring
utils
fromByteString :: ByteString -> RawBytes Source #
\( O(n) \) conversion from a strict bytestring to raw bytes.
unsafeFromByteString :: HasCallStack => ByteString -> RawBytes Source #
\( O(1) \) conversion from a strict bytestring to raw bytes.
Strict bytestrings are allocated using mallocPlainForeignPtrBytes
, so we
are expecting a PlainPtr
(or FinalPtr
with length 0).
For other variants, this function will fail.
toByteString :: RawBytes -> ByteString Source #
\( O(1) \) conversion from raw bytes to a bytestring if pinned, \( O(n) \) if unpinned.
unsafePinnedToByteString :: HasCallStack => RawBytes -> ByteString Source #
\( O(1) \) conversion from raw bytes to a bytestring. Fails if the underlying byte array is not pinned.
fromShortByteString :: ShortByteString -> RawBytes Source #
\( O(1) \) conversion from a short bytestring to raw bytes.