lsm-tree-0.1.0.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

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

Raw bytes

newtype RawBytes Source #

Raw bytes with no alignment constraint (i.e. byte aligned), and no guarantee of pinned or unpinned memory (i.e. could be either).

Constructors

RawBytes (Vector Word8) 

Instances

Instances details
IsString RawBytes Source #

Mostly to make test cases shorter to write.

Instance details

Defined in Database.LSMTree.Internal.RawBytes

Monoid RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

Semigroup RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

IsList RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

Associated Types

type Item RawBytes #

Show RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

NFData RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

Methods

rnf :: RawBytes -> () #

Eq RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

Ord RawBytes Source #

Lexicographical Ord instance.

Instance details

Defined in Database.LSMTree.Internal.RawBytes

Hashable RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

type Item RawBytes Source # 
Instance details

Defined in Database.LSMTree.Internal.RawBytes

Accessors

Length information

size :: RawBytes -> Int Source #

\( O(1) \)

Extracting subvectors (slicing)

take :: Int -> RawBytes -> RawBytes Source #

\( O(1) \)

drop :: Int -> RawBytes -> RawBytes Source #

\( O(1) \)

topBits64 :: RawBytes -> Word64 Source #

topBits64 rb slices the first 64 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

Use Semigroup and Monoid operations ** Restricting memory usage

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.