1+ {-# LANGUAGE MagicHash #-}
2+
13-- | A compact fence-pointer index for uniformly distributed keys.
24--
35-- TODO: add utility functions for clash probability calculations
@@ -13,9 +15,8 @@ module Database.LSMTree.Internal.Index.Compact (
1315 -- * Non-incremental serialisation
1416 , toLBS
1517 -- * Incremental serialisation
16- -- $incremental-serialisation
17- , headerLBS
18- , finalLBS
18+ , Index. headerLBS
19+ , Index. finalLBS
1920 , word64VectorToChunk
2021 -- * Deserialisation
2122 , Index. fromSBS
@@ -49,12 +50,13 @@ import Database.LSMTree.Internal.Chunk (Chunk (Chunk))
4950import qualified Database.LSMTree.Internal.Chunk as Chunk (toByteString )
5051import Database.LSMTree.Internal.Entry (NumEntries (.. ))
5152import Database.LSMTree.Internal.Index (Index )
52- import qualified Database.LSMTree.Internal.Index as Index (fromSBS , search ,
53- sizeInPages )
53+ import qualified Database.LSMTree.Internal.Index as Index (finalLBS , fromSBS ,
54+ headerLBS , search , sizeInPages )
5455import Database.LSMTree.Internal.Page
5556import Database.LSMTree.Internal.Serialise
5657import Database.LSMTree.Internal.Unsliced
5758import Database.LSMTree.Internal.Vector
59+ import GHC.Exts (Proxy #, proxy #)
5860
5961{- $compact
6062
@@ -460,38 +462,34 @@ sizeInPages = NumPages . toEnum . VU.length . icPrimary
460462-- | Serialises a compact index in one go.
461463toLBS :: NumEntries -> IndexCompact -> LBS. ByteString
462464toLBS numEntries index =
463- headerLBS
465+ headerLBS (proxy # @ IndexCompact )
464466 <> LBS. fromStrict (Chunk. toByteString (word64VectorToChunk (icPrimary index)))
465467 <> finalLBS numEntries index
466468
467469{- ------------------------------------------------------------------------------
468470 Incremental serialisation
469471-------------------------------------------------------------------------------}
470472
471- {- $incremental-serialisation
472-
473- To incrementally serialise a compact index as it is being constructed, start
474- by using 'headerLBS'. Each yielded chunk can then be written using
475- 'Chunk.toByteString'. Once construction is completed, 'finalLBS' will
476- serialise the remaining parts of the compact index.
477- Also see module "Database.LSMTree.Internal.Index.CompactAcc".
478- -}
479-
480473-- | By writing out the type–version indicator in host endianness, we also
481474-- indicate endianness. During deserialisation, we would discover an endianness
482475-- mismatch.
483476supportedTypeAndVersion :: Word32
484477supportedTypeAndVersion = 0x0001
485478
486- -- | 64 bits, to be used before writing any other parts of the serialised file!
487- headerLBS :: LBS. ByteString
488- headerLBS =
479+ {-|
480+ For a specification of this operation, see the documentation of [its
481+ polymorphic version]('Index.headerLBS').
482+ -}
483+ headerLBS :: Proxy # IndexCompact -> LBS. ByteString
484+ headerLBS _ =
489485 -- create a single 4 byte chunk
490486 BB. toLazyByteStringWith (BB. safeStrategy 4 BB. smallChunkSize) mempty $
491487 BB. word32Host supportedTypeAndVersion <> BB. word32Host 0
492488
493- -- | Writes everything after the primary array, which is assumed to have already
494- -- been written using 'Chunk.toByteString'.
489+ {-|
490+ For a specification of this operation, see the documentation of [its
491+ polymorphic version]('Index.finalLBS').
492+ -}
495493finalLBS :: NumEntries -> IndexCompact -> LBS. ByteString
496494finalLBS (NumEntries numEntries) IndexCompact {.. } =
497495 -- use a builder, since it is all relatively small
@@ -690,6 +688,12 @@ instance Index IndexCompact where
690688 sizeInPages :: IndexCompact -> NumPages
691689 sizeInPages = sizeInPages
692690
691+ headerLBS :: Proxy # IndexCompact -> LBS. ByteString
692+ headerLBS = headerLBS
693+
694+ finalLBS :: NumEntries -> IndexCompact -> LBS. ByteString
695+ finalLBS = finalLBS
696+
693697 fromSBS :: ShortByteString -> Either String (NumEntries , IndexCompact )
694698 fromSBS = fromSBS
695699
0 commit comments