summaryrefslogtreecommitdiff
path: root/src/Storage.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-27 00:43:19 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-27 00:43:19 +1100
commit57d88b07166911a13b37aea54c4247097dc2d0fa (patch)
tree922f9467ef148ccf887268b72c27a6463c856250 /src/Storage.hs
parente7dbb4348d17f44c0f9162bea68738f3e2dc72f8 (diff)
Groundwork for new Criteria setup
Diffstat (limited to 'src/Storage.hs')
-rw-r--r--src/Storage.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Storage.hs b/src/Storage.hs
index 2f0ed1c..295273b 100644
--- a/src/Storage.hs
+++ b/src/Storage.hs
@@ -3,6 +3,8 @@ module Storage(
createStore,
setPref,
+ setPrefs,
+ getPrefs,
checkPref
) where
@@ -25,7 +27,7 @@ data Store = Store
createStore :: Int -> Int -> IO Store
createStore maxCapacity ballotSize = do
- v <- Vec.new (maxCapacity * ballotSize)
+ v <- Vec.replicate (maxCapacity * ballotSize) 0
return (Store v ballotSize)
@@ -39,6 +41,25 @@ setPref prefStore ballot (position,rank) = do
+setPrefs :: Store -> Int -> [Preference] -> IO ()
+setPrefs prefStore ballot prefList =
+ mapM_ (setPref prefStore ballot) prefList
+
+
+
+
+getPrefs :: Store -> Int -> IO [Preference]
+getPrefs prefStore ballot = do
+ let startPlace = (ballot - 1) * (getBallotSize prefStore)
+ endPlace = startPlace + (getBallotSize prefStore) - 1
+ base = [startPlace .. endPlace]
+ r0 <- mapM (Vec.read (getPointer prefStore)) base
+ let r1 = zip [1..] (map fromIntegral r0)
+ return (filter ((/= 0) . snd) r1)
+
+
+
+
checkPref :: Store -> Int -> Preference -> IO Bool
checkPref prefStore ballot (position,rank) = do
let place = (ballot - 1) * (getBallotSize prefStore) + (position - 1)