diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-01 09:09:41 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-01 09:09:41 +0000 |
commit | fc6e8a553c99f50768b49c8612f800edef790d93 (patch) | |
tree | a12535768912682a23e6b651b85f37e123141926 /lib/Data | |
parent | 4957cff8af91cbb23c12382e25f5373fe96acb95 (diff) |
chunkified-binary-vector
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Vector.hs | 23 |
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 | ||
41 | chunk :: Int | ||
42 | chunk = 5000 | ||
43 | |||
44 | chunks :: Int -> [Int] | ||
45 | chunks d = let c = d `div` chunk | ||
46 | in ((d-c*chunk):(replicate c chunk)) | ||
47 | |||
48 | putVector v = do | ||
49 | let d = dim v | ||
50 | mapM_ (\i -> put $ v @> i) [0..(d-1)] | ||
51 | |||
52 | getVector d = do | ||
53 | xs <- replicateM d get | ||
54 | return $! fromList xs | ||
55 | |||
39 | instance (Binary a, Storable a) => Binary (Vector a) where | 56 | instance (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 | ||