Commit 54994870 authored by Kai Zhang's avatar Kai Zhang

bump bytestring-lexing version to 0.5

parent 1f2f2294
...@@ -40,7 +40,7 @@ library ...@@ -40,7 +40,7 @@ library
build-depends: build-depends:
base >=4.0 && <5.0 base >=4.0 && <5.0
, bytestring >=0.9 , bytestring >=0.9
, bytestring-lexing , bytestring-lexing >=0.5
, primitive , primitive
, unordered-containers , unordered-containers
, hashable , hashable
......
module IGraph.Read where module IGraph.Read
( readAdjMatrix
, readAdjMatrixWeighted
) where
import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Char8 as B
import Data.ByteString.Lex.Double (readDouble) import Data.ByteString.Lex.Fractional (readSigned, readExponential)
import Data.Maybe import Data.Maybe (fromJust)
import IGraph import IGraph
readDouble :: B.ByteString -> Double
readDouble = fst . fromJust . readSigned readExponential
{-# INLINE readDouble #-}
readAdjMatrix :: Graph d => FilePath -> IO (LGraph d B.ByteString ()) readAdjMatrix :: Graph d => FilePath -> IO (LGraph d B.ByteString ())
readAdjMatrix fl = do readAdjMatrix fl = do
c <- B.readFile fl c <- B.readFile fl
let (header:xs) = B.lines c let (header:xs) = B.lines c
mat = map (map (fst . fromJust . readDouble) . B.words) xs mat = map (map readDouble . B.words) xs
es = fst $ unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat es = fst $ unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat
nrow = length mat nrow = length mat
ncol = length $ head mat ncol = length $ head mat
...@@ -24,7 +31,7 @@ readAdjMatrixWeighted :: Graph d => FilePath -> IO (LGraph d B.ByteString Double ...@@ -24,7 +31,7 @@ readAdjMatrixWeighted :: Graph d => FilePath -> IO (LGraph d B.ByteString Double
readAdjMatrixWeighted fl = do readAdjMatrixWeighted fl = do
c <- B.readFile fl c <- B.readFile fl
let (header:xs) = B.lines c let (header:xs) = B.lines c
mat = map (map (fst . fromJust . readDouble) . B.words) xs mat = map (map readDouble . B.words) xs
(es, ws) = unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat (es, ws) = unzip $ filter f $ zip [ (i,j) | i <- [0..nrow-1], j <- [0..nrow-1] ] $ concat mat
nrow = length mat nrow = length mat
ncol = length $ head mat ncol = length $ head mat
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment