summaryrefslogtreecommitdiff
path: root/lib/Data
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-01 09:09:41 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-01 09:09:41 +0000
commitfc6e8a553c99f50768b49c8612f800edef790d93 (patch)
treea12535768912682a23e6b651b85f37e123141926 /lib/Data
parent4957cff8af91cbb23c12382e25f5373fe96acb95 (diff)
chunkified-binary-vector
Diffstat (limited to 'lib/Data')
-rw-r--r--lib/Data/Packed/Vector.hs23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index 66aa71d..7264528 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -36,15 +36,32 @@ import Control.Monad(replicateM)
36 36
37------------------------------------------------------------------- 37-------------------------------------------------------------------
38 38
39-- a 64K cache, with a Double taking 13 bytes in Bytestring,
40-- implies a chunk size of 5041
41chunk :: Int
42chunk = 5000
43
44chunks :: Int -> [Int]
45chunks d = let c = d `div` chunk
46 in ((d-c*chunk):(replicate c chunk))
47
48putVector v = do
49 let d = dim v
50 mapM_ (\i -> put $ v @> i) [0..(d-1)]
51
52getVector d = do
53 xs <- replicateM d get
54 return $! fromList xs
55
39instance (Binary a, Storable a) => Binary (Vector a) where 56instance (Binary a, Storable a) => Binary (Vector a) where
40 put v = do 57 put v = do
41 let d = dim v 58 let d = dim v
42 put d 59 put d
43 mapM_ (\i -> put $ v @> i) [0..(d-1)] 60 mapM_ putVector $! takesV (chunks d) v
44 get = do 61 get = do
45 d <- get 62 d <- get
46 xs <- replicateM d get 63 vs <- mapM getVector $ chunks d
47 return $ fromList xs 64 return $! join vs
48 65
49------------------------------------------------------------------- 66-------------------------------------------------------------------
50 67