9
9
module Database.LSMTree.Internal.Index.Ordinary
10
10
(
11
11
IndexOrdinary (IndexOrdinary ),
12
- toLastKeys ,
12
+ toUnslicedLastKeys ,
13
13
search,
14
14
sizeInPages,
15
15
headerLBS,
@@ -41,6 +41,7 @@ import Database.LSMTree.Internal.Page (NumPages (NumPages),
41
41
PageNo (PageNo ), PageSpan (PageSpan ))
42
42
import Database.LSMTree.Internal.Serialise
43
43
(SerialisedKey (SerialisedKey' ))
44
+ import Database.LSMTree.Internal.Unsliced (Unsliced , makeUnslicedKey )
44
45
import Database.LSMTree.Internal.Vector (binarySearchL , mkPrimVector )
45
46
46
47
{-|
@@ -66,22 +67,22 @@ supportedTypeAndVersion = 0x0101
66
67
ascending order and must comprise at least one page for 'search' to be able
67
68
to return a valid page span.
68
69
-}
69
- newtype IndexOrdinary = IndexOrdinary (Vector SerialisedKey )
70
+ newtype IndexOrdinary = IndexOrdinary (Vector ( Unsliced SerialisedKey ) )
70
71
deriving stock (Eq , Show )
71
72
72
73
instance NFData IndexOrdinary where
73
74
74
- rnf (IndexOrdinary lastKeys ) = rnf lastKeys
75
+ rnf (IndexOrdinary unslicedLastKeys ) = rnf unslicedLastKeys
75
76
76
- toLastKeys :: IndexOrdinary -> Vector SerialisedKey
77
- toLastKeys (IndexOrdinary lastKeys ) = lastKeys
77
+ toUnslicedLastKeys :: IndexOrdinary -> Vector ( Unsliced SerialisedKey )
78
+ toUnslicedLastKeys (IndexOrdinary unslicedLastKeys ) = unslicedLastKeys
78
79
79
80
{-|
80
81
For a specification of this operation, see the documentation of [its
81
82
type-agnostic version]('Database.LSMTree.Internal.Index.search').
82
83
-}
83
84
search :: SerialisedKey -> IndexOrdinary -> PageSpan
84
- search key (IndexOrdinary lastKeys )
85
+ search key (IndexOrdinary unslicedLastKeys )
85
86
-- TODO: ideally, we could assert that an index is never empty, but
86
87
-- unfortunately we can not currently do this. Runs (and thefeore indexes)
87
88
-- /can/ be empty if they were created by a last-level merge where all input
@@ -94,35 +95,35 @@ search key (IndexOrdinary lastKeys)
94
95
| otherwise = assert (pageCount > 0 ) result where
95
96
96
97
protoStart :: Int
97
- ! protoStart = binarySearchL lastKeys key
98
+ ! protoStart = binarySearchL unslicedLastKeys (makeUnslicedKey key)
98
99
99
100
pageCount :: Int
100
- ! pageCount = length lastKeys
101
+ ! pageCount = length unslicedLastKeys
101
102
102
103
result :: PageSpan
103
104
result | protoStart < pageCount
104
105
= let
105
106
106
- resultKey :: SerialisedKey
107
- ! resultKey = lastKeys ! protoStart
107
+ unslicedResultKey :: Unsliced SerialisedKey
108
+ ! unslicedResultKey = unslicedLastKeys ! protoStart
108
109
109
110
end :: Int
110
111
! end = maybe (pred pageCount) (+ protoStart) $
111
- findIndex (/= resultKey ) $
112
- drop (succ protoStart) lastKeys
112
+ findIndex (/= unslicedResultKey ) $
113
+ drop (succ protoStart) unslicedLastKeys
113
114
114
115
in PageSpan (PageNo $ protoStart)
115
116
(PageNo $ end)
116
117
| otherwise
117
118
= let
118
119
119
- resultKey :: SerialisedKey
120
- ! resultKey = last lastKeys
120
+ unslicedResultKey :: Unsliced SerialisedKey
121
+ ! unslicedResultKey = last unslicedLastKeys
121
122
122
123
start :: Int
123
124
! start = maybe 0 succ $
124
- findIndexR (/= resultKey ) $
125
- lastKeys
125
+ findIndexR (/= unslicedResultKey ) $
126
+ unslicedLastKeys
126
127
127
128
in PageSpan (PageNo $ start)
128
129
(PageNo $ pred pageCount)
@@ -132,7 +133,8 @@ search key (IndexOrdinary lastKeys)
132
133
type-agnostic version]('Database.LSMTree.Internal.Index.sizeInPages').
133
134
-}
134
135
sizeInPages :: IndexOrdinary -> NumPages
135
- sizeInPages (IndexOrdinary lastKeys) = NumPages $ fromIntegral (length lastKeys)
136
+ sizeInPages (IndexOrdinary unslicedLastKeys)
137
+ = NumPages $ fromIntegral (length unslicedLastKeys)
136
138
137
139
{-|
138
140
For a specification of this operation, see the documentation of [its
@@ -203,10 +205,11 @@ fromSBS shortByteString@(SBS unliftedByteArray)
203
205
Primitive. Vector _ _ entryCountRep = Primitive. force entryCountBytes
204
206
205
207
index :: Either String IndexOrdinary
206
- index = IndexOrdinary <$> fromList <$> lastKeys lastKeysBytes
208
+ index = IndexOrdinary <$> fromList <$> unslicedLastKeys lastKeysBytes
207
209
208
- lastKeys :: Primitive. Vector Word8 -> Either String [SerialisedKey ]
209
- lastKeys bytes
210
+ unslicedLastKeys :: Primitive. Vector Word8
211
+ -> Either String [Unsliced SerialisedKey ]
212
+ unslicedLastKeys bytes
210
213
| Primitive. null bytes
211
214
= Right []
212
215
| otherwise
@@ -234,8 +237,8 @@ fromSBS shortByteString@(SBS unliftedByteArray)
234
237
(firstBytes, othersBytes)
235
238
= Primitive. splitAt firstSize postFirstSizeBytes
236
239
237
- first :: SerialisedKey
238
- ! first = SerialisedKey' ( Primitive. force firstBytes)
240
+ first :: Unsliced SerialisedKey
241
+ ! first = makeUnslicedKey ( SerialisedKey' firstBytes)
239
242
240
- others <- lastKeys othersBytes
243
+ others <- unslicedLastKeys othersBytes
241
244
return (first : others)
0 commit comments