Skip to content

Commit b3f669d

Browse files
committed
Add n-way unions to the public API class
1 parent 4d2e8ec commit b3f669d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/Database/LSMTree/Class.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Database.LSMTree.Class (
88
, withTableFromSnapshot
99
, withTableDuplicate
1010
, withTableUnion
11+
, withTableUnions
1112
, withCursor
1213
, module Common
1314
, module Types
@@ -162,6 +163,13 @@ class (IsSession (Session h)) => IsTable h where
162163
-> h m k v b
163164
-> m (h m k v b)
164165

166+
unions ::
167+
( IOLike m
168+
, C k v b
169+
)
170+
=> V.Vector (h m k v b)
171+
-> m (h m k v b)
172+
165173
withTableNew :: forall h m k v b a.
166174
(IOLike m, IsTable h, C k v b)
167175
=> Session h m
@@ -194,6 +202,13 @@ withTableUnion :: forall h m k v b a.
194202
-> m a
195203
withTableUnion table1 table2 = bracket (table1 `union` table2) close
196204

205+
withTableUnions :: forall h m k v b a.
206+
(IOLike m, IsTable h, C k v b)
207+
=> V.Vector (h m k v b)
208+
-> (h m k v b -> m a)
209+
-> m a
210+
withTableUnions tables = bracket (unions tables) close
211+
197212
withCursor :: forall h m k v b a.
198213
(IOLike m, IsTable h, C k v b)
199214
=> Maybe k
@@ -232,3 +247,4 @@ instance IsTable R.Table where
232247

233248
duplicate = R.duplicate
234249
union = R.union
250+
unions = R.unions

test/Database/LSMTree/Model/IO.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Database.LSMTree.Model.IO (
1717
import Control.Concurrent.Class.MonadSTM.Strict
1818
import Control.Exception (Exception)
1919
import Control.Monad.Class.MonadThrow (MonadThrow (..))
20+
import qualified Data.Vector as V
2021
import qualified Database.LSMTree.Class as Class
2122
import Database.LSMTree.Model.Session (TableConfig (..))
2223
import qualified Database.LSMTree.Model.Session as Model
@@ -90,3 +91,8 @@ instance Class.IsTable Table where
9091

9192
union (Table s1 t1) (Table _s2 t2) =
9293
Table s1 <$> runInOpenSession s1 (Model.union Model.getResolve t1 t2)
94+
95+
unions ts =
96+
Table s <$> runInOpenSession s (Model.unions Model.getResolve (V.map thTable ts))
97+
where
98+
Table s _ = V.head ts

0 commit comments

Comments
 (0)