@@ -6,10 +6,10 @@ module Database.LSMTree.Internal.Index.Compact (
66 -- $compact
77 IndexCompact (.. )
88 -- * Queries
9- , search
9+ , Index. search
10+ , Index. sizeInPages
1011 , countClashes
1112 , hasClashes
12- , sizeInPages
1313 -- * Non-incremental serialisation
1414 , toLBS
1515 -- * Incremental serialisation
@@ -18,7 +18,7 @@ module Database.LSMTree.Internal.Index.Compact (
1818 , finalLBS
1919 , word64VectorToChunk
2020 -- * Deserialisation
21- , fromSBS
21+ , Index. fromSBS
2222 ) where
2323
2424import Control.DeepSeq (NFData (.. ))
@@ -48,6 +48,9 @@ import Database.LSMTree.Internal.ByteString (byteArrayFromTo)
4848import Database.LSMTree.Internal.Chunk (Chunk (Chunk ))
4949import qualified Database.LSMTree.Internal.Chunk as Chunk (toByteString )
5050import Database.LSMTree.Internal.Entry (NumEntries (.. ))
51+ import Database.LSMTree.Internal.Index (Index )
52+ import qualified Database.LSMTree.Internal.Index as Index (fromSBS , search ,
53+ sizeInPages )
5154import Database.LSMTree.Internal.Page
5255import Database.LSMTree.Internal.Serialise
5356import Database.LSMTree.Internal.Unsliced
@@ -378,13 +381,13 @@ instance NFData IndexCompact where
378381 Queries
379382-------------------------------------------------------------------------------}
380383
381- -- | Searches for a page span that contains a key–value pair with the given key.
382- --
383- -- If there is indeed such a pair, the result is the corresponding page span; if
384- -- there is no such pair, the result is an arbitrary but valid page span.
385- --
386- -- See [an informal description of the search algorithm](#search-descr) for more
387- -- details about the search algorithm.
384+ {-|
385+ For a specification of this operation, see the documentation of [its
386+ polymorphic version]('Index.search').
387+
388+ See [an informal description of the search algorithm](#search-descr) for
389+ more details about the search algorithm.
390+ -}
388391search :: SerialisedKey -> IndexCompact -> PageSpan
389392-- One way to think of the search algorithm is that it starts with the full page
390393-- number interval, and shrinks it to a minimal interval that contains the
@@ -443,7 +446,10 @@ countClashes = Map.size . icTieBreaker
443446hasClashes :: IndexCompact -> Bool
444447hasClashes = not . Map. null . icTieBreaker
445448
446- -- | The number of pages within the index.
449+ {-|
450+ For a specification of this operation, see the documentation of [its
451+ polymorphic version]('Index.sizeInPages').
452+ -}
447453sizeInPages :: IndexCompact -> NumPages
448454sizeInPages = NumPages . toEnum . VU. length . icPrimary
449455
@@ -548,13 +554,10 @@ putPaddingTo64 written
548554 Deserialisation
549555-------------------------------------------------------------------------------}
550556
551- -- | The input bytestring must be 64 bit aligned and exactly contain the
552- -- serialised compact index, with no leading or trailing space.
553- -- It is directly used as the backing memory for the compact index.
554- --
555- -- Also note that the implementation reads values in little-endian byte order.
556- -- If the file has been serialised in big-endian order, the mismatch will be
557- -- detected by looking at the type–version indicator.
557+ {-|
558+ For a specification of this operation, see the documentation of [its
559+ polymorphic version]('Index.fromSBS').
560+ -}
558561fromSBS :: ShortByteString -> Either String (NumEntries , IndexCompact )
559562fromSBS (SBS ba') = do
560563 let ba = ByteArray ba'
@@ -675,6 +678,21 @@ checkedBitVec off len ba
675678 | otherwise =
676679 Nothing
677680
681+ {- ------------------------------------------------------------------------------
682+ Type class instantiation
683+ -------------------------------------------------------------------------------}
684+
685+ instance Index IndexCompact where
686+
687+ search :: SerialisedKey -> IndexCompact -> PageSpan
688+ search = search
689+
690+ sizeInPages :: IndexCompact -> NumPages
691+ sizeInPages = sizeInPages
692+
693+ fromSBS :: ShortByteString -> Either String (NumEntries , IndexCompact )
694+ fromSBS = fromSBS
695+
678696{- ------------------------------------------------------------------------------
679697 Vector extras
680698-------------------------------------------------------------------------------}
0 commit comments