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.

This type imposes no alignment constraint and provides no guarantee of whether the memory is pinned or unpinned.

Constructors

RawBytes (Vector Word8) 

Instances

Instances details
IsString RawBytes Source #

fromString: \(O(n)\).

Warning: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes "�6k�nh~�Q��n�".

Instance details

Defined in Database.LSMTree.Internal.RawBytes

Monoid RawBytes Source #

mempty: \(O(1)\).

mconcat: \(O(n)\).

Instance details

Defined in Database.LSMTree.Internal.RawBytes

Semigroup RawBytes Source #

(<>): \(O(n)\).

sconcat: \(O(n)\).

Instance details

Defined in Database.LSMTree.Internal.RawBytes

IsList RawBytes Source #

fromList: \(O(n)\).

toList: \(O(n)\).

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 #

This instance uses lexicographic ordering.

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.