Commit de81c4b1 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

random-dfa: Use Word32 as base data type

Alright, compromise. Word16 might have been a little too small
parent 273a65b1
......@@ -23,7 +23,7 @@ transitionsB :: DFA -> Build.Builder
transitionsB dfa = foldMap (forStateB dfa) [0 .. dfa ^. states - 1]
forStateB :: DFA -> Word16 -> Build.Builder
forStateB :: DFA -> Word32 -> Build.Builder
forStateB dfa n =
"s"
<> Build.decimal n
......@@ -41,5 +41,5 @@ forStateB dfa n =
<> "})\n"
successorB :: Word16 -> Word16 -> Build.Builder
successorB :: Word32 -> Word32 -> Build.Builder
successorB label target = Build.decimal label <> ": s" <> Build.decimal target
......@@ -17,7 +17,7 @@ nodesB :: DFA -> Build.Builder
nodesB dfa = foldMap (nodeB dfa) [0 .. dfa ^. states - 1]
nodeB :: DFA -> Word16 -> Build.Builder
nodeB :: DFA -> Word32 -> Build.Builder
nodeB dfa n = " \"n" <> Build.decimal n <> "\" [shape = " <> shape <> "];\n"
where
shape =
......@@ -28,14 +28,14 @@ transitionsB :: DFA -> Build.Builder
transitionsB dfa = foldMap (transitionsForB dfa) [0 .. dfa ^. states - 1]
transitionsForB :: DFA -> Word16 -> Build.Builder
transitionsForB :: DFA -> Word32 -> Build.Builder
transitionsForB dfa n = fold
(zipWith (transitionB n)
[0 ..]
(dfa ^.. transitions . ix (fromIntegral n) . each))
transitionB :: Word16 -> Word16 -> Word16 -> Build.Builder
transitionB :: Word32 -> Word32 -> Word32 -> Build.Builder
transitionB source letter target =
" n"
<> Build.decimal source
......
......@@ -25,8 +25,8 @@ import ValmariOutput
-- | Generate a random DFA
randomDFA
:: Word16 -- ^ Number of states
-> Word16 -- ^ Size of the alphabet
:: Word32 -- ^ Number of states
-> Word32 -- ^ Size of the alphabet
-> IO Bool -- ^ Random finality
-> IO DFA
randomDFA s a randomIsFinal = do
......@@ -53,8 +53,8 @@ instance Show OutputFormat where
data Options = Options
{ _optStates :: Word16
, _optLetters :: Word16
{ _optStates :: Word32
, _optLetters :: Word32
, _optFinal :: Int
, _optOutputs :: [(OutputFormat, Maybe (NE.NonEmpty Char))]
} deriving (Show)
......
......@@ -15,15 +15,15 @@ import qualified Data.Vector.Unboxed as VU
import Lens.Micro.TH
-- The objective here is to support large DFAs and thus is might seem backwards
-- to restrict the number of states and letters to Word16. In reality, the
-- to restrict the number of states and letters to Word32. In reality, the
-- limiting factor is RAM, e.g 10000x10000 requires already more ram than my
-- 16GB machine has. Word16 requires 4 times less RAM than Int, so it allows for
-- 16GB machine has. Word32 requires half as much RAM than Int, so it allows for
-- larger graphs in practice.
data DFA = DFA
{ dfaStates :: Word16
, dfaLetters :: Word16
, dfaTransitions :: Vector (VU.Vector Word16)
{ dfaStates :: Word32
, dfaLetters :: Word32
, dfaTransitions :: Vector (VU.Vector Word32)
, dfaIsFinal :: VU.Vector Bool
}
......
......@@ -39,7 +39,7 @@ transitionsB dfa = foldMap
]
transB :: DFA -> Word16 -> Word16 -> Build.Builder
transB :: DFA -> Word32 -> Word32 -> Build.Builder
transB dfa from letter =
Build.decimal (from + 1)
<> " "
......
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