Skip to content

Commit

Permalink
Merge pull request #155 from haskell-works/use-construct64UnzipN-func…
Browse files Browse the repository at this point in the history
…tion-from-hw-prim

Use construct64UnzipN function from hw-prim
  • Loading branch information
newhoggy committed Sep 17, 2019
2 parents e96d75b + 8335ad7 commit 1afaf34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
29 changes: 2 additions & 27 deletions app/App/Commands/Demo.hs
Expand Up @@ -22,45 +22,20 @@ import HaskellWorks.Data.Json.Standard.Cursor.Load.Cursor
import HaskellWorks.Data.MQuery
import HaskellWorks.Data.MQuery.Micro
import HaskellWorks.Data.RankSelect.CsPoppy
import HaskellWorks.Data.Vector.AsVector8
import HaskellWorks.Data.Vector.Storable
import Options.Applicative hiding (columns)

import qualified App.Commands.Types as Z
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BSI
import qualified Data.ByteString.Lazy as LBS
import qualified Data.DList as DL
import qualified Data.Vector.Storable as DVS
import qualified Data.Vector.Storable.Mutable as DVSM
import qualified HaskellWorks.Data.BalancedParens.RangeMin as RM
import qualified HaskellWorks.Data.ByteString.Lazy as LBS
import qualified HaskellWorks.Data.Json.Simd.Index.Standard as S
import qualified Options.Applicative as OA
import qualified System.IO as IO
import qualified System.IO.MMap as IO

constructUnzipN :: Int -> [(BS.ByteString, BS.ByteString)] -> (DVS.Vector Word64, DVS.Vector Word64)
constructUnzipN nBytes xs = (DVS.unsafeCast ibv, DVS.unsafeCast bpv)
where [ibv, bpv] = DVS.createT $ do
let nW64s = (nBytes + 7) `div` 8
let capacity = nW64s * 8
ibmv <- DVSM.new capacity
bpmv <- DVSM.new capacity
(ibmvRemaining, bpmvRemaining) <- go ibmv bpmv xs
return
[ DVSM.take (((DVSM.length ibmv - ibmvRemaining) `div` 8) * 8) ibmv
, DVSM.take (((DVSM.length bpmv - bpmvRemaining) `div` 8) * 8) bpmv
]
go :: DVSM.MVector s Word8 -> DVSM.MVector s Word8 -> [(BS.ByteString, BS.ByteString)] -> ST s (Int, Int)
go ibmv bpmv ((ib, bp):ys) = do
DVS.copy (DVSM.take (BS.length ib) ibmv) (asVector8 ib)
DVS.copy (DVSM.take (BS.length bp) bpmv) (asVector8 bp)
go (DVSM.drop (BS.length ib) ibmv) (DVSM.drop (BS.length bp) bpmv) ys
go ibmv bpmv [] = do
DVSM.set (DVSM.take 8 ibmv) 0
DVSM.set (DVSM.take 8 bpmv) 0
return (DVSM.length (DVSM.drop 8 ibmv), DVSM.length (DVSM.drop 8 bpmv))

runDemo :: Z.DemoOptions -> IO ()
runDemo opts = do
let filePath = opts ^. the @"filePath"
Expand All @@ -76,7 +51,7 @@ runDemo opts = do
let !bs = BSI.fromForeignPtr (castForeignPtr fptr) offset size
case S.makeStandardJsonIbBps (LBS.resegmentPadded 512 (LBS.fromStrict bs)) of
Right ibBps -> do
let (!ib, !bp) = constructUnzipN size ibBps
let (!ib, !bp) = construct64UnzipN size ibBps
let !cursor = GenericCursor bs (makeCsPoppy ib) (RM.mkRangeMin bp) 1
let !json = lightJsonAt cursor
let q = MQuery (DL.singleton json)
Expand Down
2 changes: 1 addition & 1 deletion hw-json.cabal
Expand Up @@ -59,7 +59,7 @@ common hw-json-simple-cursor { build-depends: hw-json-simple-cursor >= 0.1
common hw-json-standard-cursor { build-depends: hw-json-standard-cursor >= 0.2.1.0 && < 0.3 }
common hw-mquery { build-depends: hw-mquery >= 0.2.0.0 && < 0.3 }
common hw-parser { build-depends: hw-parser >= 0.1 && < 0.2 }
common hw-prim { build-depends: hw-prim >= 0.6.2.28 && < 0.7 }
common hw-prim { build-depends: hw-prim >= 0.6.2.32 && < 0.7 }
common hw-rankselect { build-depends: hw-rankselect >= 0.13 && < 0.14 }
common hw-rankselect-base { build-depends: hw-rankselect-base >= 0.3.2.1 && < 0.4 }
common hw-simd { build-depends: hw-simd >= 0.1.1.2 && < 0.2 }
Expand Down

0 comments on commit 1afaf34

Please sign in to comment.