summaryrefslogtreecommitdiff
path: root/hsolve
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-08-08 23:17:20 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-08-08 23:22:48 +0200
commitff7dbb854805b0f7cc2a75854c836673d7fb1ac6 (patch)
treec1e536c1e4c90c18316f94bb56ed93656e5479f6 /hsolve
parent3747e30a79e6e656e82f7a83144afd9f3c365b34 (diff)
Unboxed arrays in FSu
20% faster than before on suvh.txt
Diffstat (limited to 'hsolve')
-rw-r--r--hsolve/FSu.hs14
1 files changed, 6 insertions, 8 deletions
diff --git a/hsolve/FSu.hs b/hsolve/FSu.hs
index 1bd250a..1d0eea3 100644
--- a/hsolve/FSu.hs
+++ b/hsolve/FSu.hs
@@ -10,7 +10,7 @@ import Data.STRef
type Value = Int -- Sudoku value
type Index = Int -- Sudoku index
-type Arr s a = STArray s Int a
+type Arr s a = STUArray s Int a
data State s = State { stateMark :: Arr s Bool, stateResults :: STRef s [[Maybe Value]] }
@@ -54,7 +54,7 @@ tryAll arr !i (v:vs) st = do
-- assumes the considered position is empty
getPoss :: forall s. Arr s Value -> Index -> State s -> ST s [Value]
getPoss arr i st = do
- fillArray mark 0 8 True
+ fillArrayBool mark 0 8 True
goRow (rowOf i) 0
goCol (colOf i) 0
goBlock (blockOrigin (blockOf i)) 0
@@ -107,7 +107,7 @@ isValidBlock arr b st = indexSetNoDups arr [blockOrigin b + 9 * y + x| y <- [0..
indexSetNoDups :: forall s. Arr s Value -> [Index] -> State s -> ST s Bool
indexSetNoDups arr set st = do
- fillArray mark 0 8 False
+ fillArrayBool mark 0 8 False
applyInMark set
where
mark = stateMark st
@@ -124,11 +124,9 @@ indexSetNoDups arr set st = do
then return False
else writeArray mark v True >> applyInMark is
-fillArray :: Arr s a -> Int -> Int -> a -> ST s ()
-fillArray arr !i1 !i2 v
- | i1 <= i2 = do
- writeArray arr i1 v
- fillArray arr (i1 + 1) i2 v
+fillArrayBool :: Arr s Bool -> Int -> Int -> Bool -> ST s ()
+fillArrayBool arr !i1 !i2 v
+ | i1 <= i2 = unsafeWrite arr i1 v >> fillArrayBool arr (i1 + 1) i2 v
| otherwise = return ()
rowOf :: Index -> Index