| 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.
This type imposes no alignment constraint and provides no guarantee of whether the memory is pinned or unpinned.
Instances
| IsString RawBytes Source # | 
 Warning:   | 
Defined in Database.LSMTree.Internal.RawBytes Methods fromString :: String -> RawBytes #  | |
| Monoid RawBytes Source # | 
 
  | 
| Semigroup RawBytes Source # | 
 
  | 
| IsList RawBytes Source # | 
 
  | 
| Show RawBytes Source # | |
| Hashable RawBytes Source # | |
Defined in Database.LSMTree.Internal.RawBytes  | |
| NFData RawBytes Source # | |
Defined in Database.LSMTree.Internal.RawBytes  | |
| Eq RawBytes Source # | |
| Ord RawBytes Source # | This instance uses lexicographic ordering.  | 
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).
If the number of bits is smaller than 64, then any missing bits default to
 0s.
>>>showHex (topBits64 (pack [1,0,0,0,0,0,0,0])) """100000000000000"
>>>showHex (topBits64 (pack [1,0,0])) """100000000000000"
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.