1
+ {-# LANGUAGE BangPatterns #-}
1
2
{-# LANGUAGE DataKinds #-}
2
3
{-# LANGUAGE OverloadedStrings #-}
3
4
{-# LANGUAGE ScopedTypeVariables #-}
@@ -18,19 +19,23 @@ import HaskellWorks.Data.Json.Query
18
19
import HaskellWorks.Data.Json.Standard.Cursor.Generic
19
20
import HaskellWorks.Data.MQuery
20
21
import HaskellWorks.Data.MQuery.Micro
21
- import HaskellWorks.Data.RankSelect.CsPoppy
22
+ import HaskellWorks.Data.RankSelect.CsPoppy1
22
23
import HaskellWorks.Data.TreeCursor
23
24
import Options.Applicative hiding (columns )
24
25
25
- import qualified App.Commands.Types as Z
26
- import qualified Data.ByteString as BS
27
- import qualified Data.ByteString.Internal as BSI
28
- import qualified Data.DList as DL
29
- import qualified Data.Vector.Storable as DVS
30
- import qualified HaskellWorks.Data.BalancedParens.RangeMin as RM
31
- import qualified System.IO.MMap as IO
26
+ import qualified App.Commands.Types as Z
27
+ import qualified Data.ByteString as BS
28
+ import qualified Data.ByteString.Internal as BSI
29
+ import qualified Data.DList as DL
30
+ import qualified Data.Vector.Storable as DVS
31
+ import qualified HaskellWorks.Data.BalancedParens.RangeMin as RM
32
+ import qualified HaskellWorks.Data.Json.Standard.Cursor.Fast as JCF
33
+ import qualified HaskellWorks.Data.Json.Standard.Cursor.Internal.IbBp as IBBP
34
+ import qualified HaskellWorks.Data.RankSelect.CsPoppy.Internal.Alpha1 as A1
35
+ import qualified System.IO as IO
36
+ import qualified System.IO.MMap as IO
32
37
33
- siblings :: GenericCursor BSI. ByteString CsPoppy (RM. RangeMin CsPoppy ) -> [GenericCursor BSI. ByteString CsPoppy (RM. RangeMin CsPoppy )]
38
+ siblings :: GenericCursor BSI. ByteString CsPoppy1 (RM. RangeMin CsPoppy1 ) -> [GenericCursor BSI. ByteString CsPoppy1 (RM. RangeMin CsPoppy1 )]
34
39
siblings c = c: cs
35
40
where cs = case nextSibling c of
36
41
Just d -> siblings d
@@ -39,24 +44,47 @@ siblings c = c:cs
39
44
runCount :: Z. CountOptions -> IO ()
40
45
runCount opts = do
41
46
let inputFile = opts ^. the @ " inputFile"
42
- let ibIndex = opts ^. the @ " ibIndex"
43
- let bpIndex = opts ^. the @ " bpIndex"
44
47
let expression = opts ^. the @ " expression"
45
48
jsonFr <- IO. mmapFileForeignPtr inputFile IO. ReadOnly Nothing
46
- jsonIbFr <- IO. mmapFileForeignPtr ibIndex IO. ReadOnly Nothing
47
- jsonBpFr <- IO. mmapFileForeignPtr bpIndex IO. ReadOnly Nothing
48
49
let jsonBs = fromForeignRegion jsonFr :: BS. ByteString
49
- let jsonIb = fromForeignRegion jsonIbFr :: DVS. Vector Word64
50
- let jsonBp = fromForeignRegion jsonBpFr :: DVS. Vector Word64
51
50
52
- let cursor = GenericCursor jsonBs (makeCsPoppy jsonIb) (RM. mkRangeMin (makeCsPoppy jsonBp)) 1
51
+ cursor <- case opts ^. the @ " indexes" of
52
+ Just indexes -> do
53
+ let ibIndex = indexes ^. the @ " ibIndex"
54
+ let bpIndex = indexes ^. the @ " bpIndex"
55
+ jsonIbFr <- IO. mmapFileForeignPtr ibIndex IO. ReadOnly Nothing
56
+ jsonBpFr <- IO. mmapFileForeignPtr bpIndex IO. ReadOnly Nothing
57
+ let jsonIb = fromForeignRegion jsonIbFr :: DVS. Vector Word64
58
+ let jsonBp = fromForeignRegion jsonBpFr :: DVS. Vector Word64
59
+
60
+ return $ GenericCursor jsonBs (makeCsPoppy jsonIb) (RM. mkRangeMin (makeCsPoppy jsonBp)) 1
61
+ Nothing -> do
62
+ IO. putStrLn " Running"
63
+ let ! ibip = JCF. simdToIbBp jsonBs
64
+ let ! _ = A1. makeCsPoppyIndex (IBBP. ib ibip)
65
+ let ! c = JCF. fromBsIbBp jsonBs ibip
66
+ IO. putStrLn " Created cursor"
67
+ return c
53
68
54
69
let q = MQuery (DL. fromList $ fmap lightJsonAt (siblings cursor))
55
70
56
71
putPretty $ q >>= (entry >=> named expression) & count
57
72
58
73
return ()
59
74
75
+ optsFileIndex :: Parser Z. FileIndexes
76
+ optsFileIndex = Z. FileIndexes
77
+ <$> strOption
78
+ ( long " ib-index"
79
+ <> help " IB index"
80
+ <> metavar " FILE"
81
+ )
82
+ <*> strOption
83
+ ( long " bp-index"
84
+ <> help " BP index"
85
+ <> metavar " FILE"
86
+ )
87
+
60
88
optsCount :: Parser Z. CountOptions
61
89
optsCount = Z. CountOptions
62
90
<$> strOption
@@ -65,16 +93,7 @@ optsCount = Z.CountOptions
65
93
<> help " Input JSON file"
66
94
<> metavar " FILE"
67
95
)
68
- <*> strOption
69
- ( long " ib-index"
70
- <> help " IB index"
71
- <> metavar " FILE"
72
- )
73
- <*> strOption
74
- ( long " bp-index"
75
- <> help " BP index"
76
- <> metavar " FILE"
77
- )
96
+ <*> optional optsFileIndex
78
97
<*> option auto
79
98
( long " expression"
80
99
<> help " JSON expression"
0 commit comments