99module Database.LSMTree.Internal.Index.Ordinary
1010(
1111 IndexOrdinary (IndexOrdinary ),
12- toLastKeys ,
12+ toUnslicedLastKeys ,
1313 search,
1414 sizeInPages,
1515 headerLBS,
@@ -41,6 +41,7 @@ import Database.LSMTree.Internal.Page (NumPages (NumPages),
4141 PageNo (PageNo ), PageSpan (PageSpan ))
4242import Database.LSMTree.Internal.Serialise
4343 (SerialisedKey (SerialisedKey' ))
44+ import Database.LSMTree.Internal.Unsliced (Unsliced , makeUnslicedKey )
4445import Database.LSMTree.Internal.Vector (binarySearchL , mkPrimVector )
4546
4647{-|
@@ -66,22 +67,22 @@ supportedTypeAndVersion = 0x0101
6667 ascending order and must comprise at least one page for 'search' to be able
6768 to return a valid page span.
6869-}
69- newtype IndexOrdinary = IndexOrdinary (Vector SerialisedKey )
70+ newtype IndexOrdinary = IndexOrdinary (Vector ( Unsliced SerialisedKey ) )
7071 deriving stock (Eq , Show )
7172
7273instance NFData IndexOrdinary where
7374
74- rnf (IndexOrdinary lastKeys ) = rnf lastKeys
75+ rnf (IndexOrdinary unslicedLastKeys ) = rnf unslicedLastKeys
7576
76- toLastKeys :: IndexOrdinary -> Vector SerialisedKey
77- toLastKeys (IndexOrdinary lastKeys ) = lastKeys
77+ toUnslicedLastKeys :: IndexOrdinary -> Vector ( Unsliced SerialisedKey )
78+ toUnslicedLastKeys (IndexOrdinary unslicedLastKeys ) = unslicedLastKeys
7879
7980{-|
8081 For a specification of this operation, see the documentation of [its
8182 type-agnostic version]('Database.LSMTree.Internal.Index.search').
8283-}
8384search :: SerialisedKey -> IndexOrdinary -> PageSpan
84- search key (IndexOrdinary lastKeys )
85+ search key (IndexOrdinary unslicedLastKeys )
8586 -- TODO: ideally, we could assert that an index is never empty, but
8687 -- unfortunately we can not currently do this. Runs (and thefeore indexes)
8788 -- /can/ be empty if they were created by a last-level merge where all input
@@ -94,35 +95,35 @@ search key (IndexOrdinary lastKeys)
9495 | otherwise = assert (pageCount > 0 ) result where
9596
9697 protoStart :: Int
97- ! protoStart = binarySearchL lastKeys key
98+ ! protoStart = binarySearchL unslicedLastKeys (makeUnslicedKey key)
9899
99100 pageCount :: Int
100- ! pageCount = length lastKeys
101+ ! pageCount = length unslicedLastKeys
101102
102103 result :: PageSpan
103104 result | protoStart < pageCount
104105 = let
105106
106- resultKey :: SerialisedKey
107- ! resultKey = lastKeys ! protoStart
107+ unslicedResultKey :: Unsliced SerialisedKey
108+ ! unslicedResultKey = unslicedLastKeys ! protoStart
108109
109110 end :: Int
110111 ! end = maybe (pred pageCount) (+ protoStart) $
111- findIndex (/= resultKey ) $
112- drop (succ protoStart) lastKeys
112+ findIndex (/= unslicedResultKey ) $
113+ drop (succ protoStart) unslicedLastKeys
113114
114115 in PageSpan (PageNo $ protoStart)
115116 (PageNo $ end)
116117 | otherwise
117118 = let
118119
119- resultKey :: SerialisedKey
120- ! resultKey = last lastKeys
120+ unslicedResultKey :: Unsliced SerialisedKey
121+ ! unslicedResultKey = last unslicedLastKeys
121122
122123 start :: Int
123124 ! start = maybe 0 succ $
124- findIndexR (/= resultKey ) $
125- lastKeys
125+ findIndexR (/= unslicedResultKey ) $
126+ unslicedLastKeys
126127
127128 in PageSpan (PageNo $ start)
128129 (PageNo $ pred pageCount)
@@ -132,7 +133,8 @@ search key (IndexOrdinary lastKeys)
132133 type-agnostic version]('Database.LSMTree.Internal.Index.sizeInPages').
133134-}
134135sizeInPages :: IndexOrdinary -> NumPages
135- sizeInPages (IndexOrdinary lastKeys) = NumPages $ fromIntegral (length lastKeys)
136+ sizeInPages (IndexOrdinary unslicedLastKeys)
137+ = NumPages $ fromIntegral (length unslicedLastKeys)
136138
137139{-|
138140 For a specification of this operation, see the documentation of [its
@@ -203,10 +205,11 @@ fromSBS shortByteString@(SBS unliftedByteArray)
203205 Primitive. Vector _ _ entryCountRep = Primitive. force entryCountBytes
204206
205207 index :: Either String IndexOrdinary
206- index = IndexOrdinary <$> fromList <$> lastKeys lastKeysBytes
208+ index = IndexOrdinary <$> fromList <$> unslicedLastKeys lastKeysBytes
207209
208- lastKeys :: Primitive. Vector Word8 -> Either String [SerialisedKey ]
209- lastKeys bytes
210+ unslicedLastKeys :: Primitive. Vector Word8
211+ -> Either String [Unsliced SerialisedKey ]
212+ unslicedLastKeys bytes
210213 | Primitive. null bytes
211214 = Right []
212215 | otherwise
@@ -234,8 +237,8 @@ fromSBS shortByteString@(SBS unliftedByteArray)
234237 (firstBytes, othersBytes)
235238 = Primitive. splitAt firstSize postFirstSizeBytes
236239
237- first :: SerialisedKey
238- ! first = SerialisedKey' ( Primitive. force firstBytes)
240+ first :: Unsliced SerialisedKey
241+ ! first = makeUnslicedKey ( SerialisedKey' firstBytes)
239242
240- others <- lastKeys othersBytes
243+ others <- unslicedLastKeys othersBytes
241244 return (first : others)
0 commit comments