Skip to content

Commit 0c3e466

Browse files
committed
Move some type definitions back into the public API.
Since none of the internal code still relies on these type definitions, remove the `D.L.I.Normal` and `D.L.I.Monoidal` modules, and move the types to the `D.L.Normal` and `D.L.Monoidal` modules.
1 parent a5a739d commit 0c3e466

File tree

6 files changed

+72
-90
lines changed

6 files changed

+72
-90
lines changed

lsm-tree.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ library
135135
Database.LSMTree.Internal.Lookup
136136
Database.LSMTree.Internal.Merge
137137
Database.LSMTree.Internal.MergeSchedule
138-
Database.LSMTree.Internal.Monoidal
139-
Database.LSMTree.Internal.Normal
140138
Database.LSMTree.Internal.PageAcc
141139
Database.LSMTree.Internal.PageAcc1
142140
Database.LSMTree.Internal.Paths

src/Database/LSMTree/Internal/Monoidal.hs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Database/LSMTree/Internal/Normal.hs

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/Database/LSMTree/Monoidal.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ import Database.LSMTree.Common (IOLike, Range (..), SerialiseKey,
135135
import qualified Database.LSMTree.Common as Common
136136
import qualified Database.LSMTree.Internal as Internal
137137
import qualified Database.LSMTree.Internal.Entry as Entry
138-
import Database.LSMTree.Internal.Monoidal
139138
import Database.LSMTree.Internal.RawBytes (RawBytes)
140139
import qualified Database.LSMTree.Internal.Serialise as Internal
141140
import qualified Database.LSMTree.Internal.Vector as V
@@ -216,6 +215,12 @@ close (Internal.MonoidalTable th) = Internal.close th
216215
Table queries
217216
-------------------------------------------------------------------------------}
218217

218+
-- | Result of a single point lookup.
219+
data LookupResult v =
220+
NotFound
221+
| Found !v
222+
deriving stock (Eq, Show, Functor, Foldable, Traversable)
223+
219224
{-# SPECIALISE lookups ::
220225
(SerialiseKey k, SerialiseValue v, ResolveValue v)
221226
=> V.Vector k
@@ -244,6 +249,11 @@ lookups ks (Internal.MonoidalTable th) =
244249
Entry.Delete -> NotFound
245250
toLookupResult Nothing = NotFound
246251

252+
-- | A result for one point in a cursor read or range query.
253+
data QueryResult k v =
254+
FoundInQuery !k !v
255+
deriving stock (Eq, Show, Functor, Foldable, Traversable)
256+
247257
{-# SPECIALISE rangeLookup ::
248258
(SerialiseKey k, SerialiseValue v, ResolveValue v)
249259
=> Range k
@@ -397,6 +407,22 @@ readCursor n (Internal.MonoidalCursor c) =
397407
Table updates
398408
-------------------------------------------------------------------------------}
399409

410+
-- | Monoidal tables support insert, delete and monoidal upsert operations.
411+
--
412+
-- An __update__ is a term that groups all types of table-manipulating
413+
-- operations, like inserts, deletes and mupserts.
414+
data Update v =
415+
Insert !v
416+
| Delete
417+
-- | TODO: should be given a more suitable name.
418+
| Mupsert !v
419+
deriving stock (Show, Eq)
420+
421+
instance NFData v => NFData (Update v) where
422+
rnf (Insert v) = rnf v
423+
rnf Delete = ()
424+
rnf (Mupsert v) = rnf v
425+
400426
{-# SPECIALISE updates ::
401427
(SerialiseKey k, SerialiseValue v, ResolveValue v)
402428
=> V.Vector (k, Update v)

src/Database/LSMTree/Normal.hs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module Database.LSMTree.Normal (
111111
, IOLike
112112
) where
113113

114+
import Control.DeepSeq
114115
import Control.Exception (throw)
115116
import Control.Monad
116117
import Data.Bifunctor (Bifunctor (..))
@@ -125,7 +126,6 @@ import qualified Database.LSMTree.Common as Common
125126
import qualified Database.LSMTree.Internal as Internal
126127
import qualified Database.LSMTree.Internal.BlobRef as Internal
127128
import qualified Database.LSMTree.Internal.Entry as Entry
128-
import Database.LSMTree.Internal.Normal
129129
import qualified Database.LSMTree.Internal.Serialise as Internal
130130
import qualified Database.LSMTree.Internal.Vector as V
131131
import qualified System.FS.API as FS
@@ -290,6 +290,24 @@ close (Internal.NormalTable th) = Internal.close th
290290
Table queries
291291
-------------------------------------------------------------------------------}
292292

293+
-- | Result of a single point lookup.
294+
data LookupResult v blobref =
295+
NotFound
296+
| Found !v
297+
| FoundWithBlob !v !blobref
298+
deriving stock (Eq, Show, Functor, Foldable, Traversable)
299+
300+
instance Bifunctor LookupResult where
301+
first f = \case
302+
NotFound -> NotFound
303+
Found v -> Found (f v)
304+
FoundWithBlob v b -> FoundWithBlob (f v) b
305+
306+
second g = \case
307+
NotFound -> NotFound
308+
Found v -> Found v
309+
FoundWithBlob v b -> FoundWithBlob v (g b)
310+
293311
{-# SPECIALISE lookups ::
294312
(SerialiseKey k, SerialiseValue v)
295313
=> V.Vector k
@@ -319,6 +337,17 @@ lookups ks (Internal.NormalTable th) =
319337
Entry.Delete -> NotFound
320338
toLookupResult Nothing = NotFound
321339

340+
-- | A result for one point in a cursor read or range lookup.
341+
data QueryResult k v blobref =
342+
FoundInQuery !k !v
343+
| FoundInQueryWithBlob !k !v !blobref
344+
deriving stock (Eq, Show, Functor, Foldable, Traversable)
345+
346+
instance Bifunctor (QueryResult k) where
347+
bimap f g = \case
348+
FoundInQuery k v -> FoundInQuery k (f v)
349+
FoundInQueryWithBlob k v b -> FoundInQueryWithBlob k (f v) (g b)
350+
322351
{-# SPECIALISE rangeLookup ::
323352
(SerialiseKey k, SerialiseValue v)
324353
=> Range k
@@ -488,6 +517,19 @@ toNormalQueryResult k v = \case
488517
Table updates
489518
-------------------------------------------------------------------------------}
490519

520+
-- | Normal tables support insert and delete operations.
521+
--
522+
-- An __update__ is a term that groups all types of table-manipulating
523+
-- operations, like inserts and deletes.
524+
data Update v blob =
525+
Insert !v !(Maybe blob)
526+
| Delete
527+
deriving stock (Show, Eq)
528+
529+
instance (NFData v, NFData blob) => NFData (Update v blob) where
530+
rnf Delete = ()
531+
rnf (Insert v b) = rnf v `seq` rnf b
532+
491533
{-# SPECIALISE updates ::
492534
(SerialiseKey k, SerialiseValue v, SerialiseValue blob)
493535
=> V.Vector (k, Update v blob)

test/Test/Database/LSMTree/Internal/Entry.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Data.Semigroup
1212
import Database.LSMTree.Extras.Generators ()
1313
import Database.LSMTree.Internal.BlobRef
1414
import Database.LSMTree.Internal.Entry
15-
import qualified Database.LSMTree.Internal.Monoidal as Monoidal
16-
import qualified Database.LSMTree.Internal.Normal as Normal
15+
import qualified Database.LSMTree.Monoidal as Monoidal
16+
import qualified Database.LSMTree.Normal as Normal
1717
import Test.QuickCheck
1818
import Test.QuickCheck.Classes (semigroupLaws)
1919
import Test.Tasty

0 commit comments

Comments
 (0)