|
5 | 5 | module Database.LSMTree.Internal.IndexCompact ( |
6 | 6 | -- $compact |
7 | 7 | IndexCompact (..) |
8 | | - , PageNo (..) |
9 | | - , nextPageNo |
10 | | - , NumPages |
11 | | - , getNumPages |
12 | 8 | -- * Queries |
13 | | - , PageSpan (..) |
14 | | - , singlePage |
15 | | - , multiPage |
16 | | - , pageSpanSize |
17 | 9 | , search |
18 | 10 | , countClashes |
19 | 11 | , hasClashes |
@@ -57,6 +49,7 @@ import Database.LSMTree.Internal.BitMath |
57 | 49 | import Database.LSMTree.Internal.ByteString (byteArrayFromTo, |
58 | 50 | byteArrayToByteString) |
59 | 51 | import Database.LSMTree.Internal.Entry (NumEntries (..)) |
| 52 | +import Database.LSMTree.Internal.Page |
60 | 53 | import Database.LSMTree.Internal.Serialise |
61 | 54 | import Database.LSMTree.Internal.Unsliced |
62 | 55 | import Database.LSMTree.Internal.Vector |
@@ -382,60 +375,10 @@ instance NFData IndexCompact where |
382 | 375 | rnf ic = rnf a `seq` rnf b `seq` rnf c `seq` rnf d |
383 | 376 | where IndexCompact a b c d = ic |
384 | 377 |
|
385 | | --- | A 0-based number identifying a disk page. |
386 | | -newtype PageNo = PageNo { unPageNo :: Int } |
387 | | - deriving stock (Show, Eq, Ord) |
388 | | - deriving newtype NFData |
389 | | - |
390 | | --- | Increment the page number. |
391 | | --- |
392 | | --- Note: This does not encure that the incremented page number exists within a given page span. |
393 | | -{-# INLINE nextPageNo #-} |
394 | | -nextPageNo :: PageNo -> PageNo |
395 | | -nextPageNo = PageNo . succ . unPageNo |
396 | | - |
397 | | --- | The number of pages contained by an index or other paging data-structure. |
398 | | --- |
399 | | --- Note: This is a 0-based number; take care to ensure arithmetic underflow |
400 | | --- does not occur during subtraction operations! |
401 | | -newtype NumPages = NumPages Word |
402 | | - deriving stock (Eq, Ord, Show) |
403 | | - deriving newtype (NFData) |
404 | | - |
405 | | --- | A type-safe "unwrapper" for 'NumPages'. Use this accessor whenever you want |
406 | | --- to convert 'NumPages' to a more versatile number type. |
407 | | -{-# INLINE getNumPages #-} |
408 | | -getNumPages :: Integral i => NumPages -> i |
409 | | -getNumPages (NumPages w) = fromIntegral w |
410 | | - |
411 | 378 | {------------------------------------------------------------------------------- |
412 | 379 | Queries |
413 | 380 | -------------------------------------------------------------------------------} |
414 | 381 |
|
415 | | --- | A span of pages, representing an inclusive interval of page numbers. |
416 | | --- |
417 | | --- Typlically used to denote the contiguous page span for a database entry. |
418 | | -data PageSpan = PageSpan { |
419 | | - pageSpanStart :: {-# UNPACK #-} !PageNo |
420 | | - , pageSpanEnd :: {-# UNPACK #-} !PageNo |
421 | | - } |
422 | | - deriving stock (Show, Eq) |
423 | | - |
424 | | -instance NFData PageSpan where |
425 | | - rnf (PageSpan x y) = rnf x `seq` rnf y |
426 | | - |
427 | | -{-# INLINE singlePage #-} |
428 | | -singlePage :: PageNo -> PageSpan |
429 | | -singlePage i = PageSpan i i |
430 | | - |
431 | | -{-# INLINE multiPage #-} |
432 | | -multiPage :: PageNo -> PageNo -> PageSpan |
433 | | -multiPage i j = PageSpan i j |
434 | | - |
435 | | -pageSpanSize :: PageSpan -> NumPages |
436 | | -pageSpanSize pspan = NumPages . toEnum $ |
437 | | - unPageNo (pageSpanEnd pspan) - unPageNo (pageSpanStart pspan) + 1 |
438 | | - |
439 | 382 | -- | Searches for a page span that contains a key–value pair with the given key. |
440 | 383 | -- |
441 | 384 | -- If there is indeed such a pair, the result is the corresponding page span; if |
|
0 commit comments