this repo has no description
1module Lib
2 ( spinlockValues
3 ) where
4
5import qualified Data.Sequence as S
6
7type SpinlockValues = S.Seq Int
8
9spinlockValues :: Int -> Int -> SpinlockValues
10spinlockValues steps m = go 1 0 $ S.singleton 0
11 where go :: Int -> Int -> SpinlockValues -> SpinlockValues
12 go step pos vals
13 | step == (m + 1) = vals
14 | otherwise = let (newVals, newPos) = insertVal step steps pos vals
15 in go (step + 1) newPos newVals
16
17insertVal :: Int -> Int -> Int -> SpinlockValues -> (SpinlockValues, Int)
18insertVal step steps pos vals =
19 let realSteps = rem steps $ length vals
20 insertPos = case pos + realSteps > length vals of
21 True -> (pos + realSteps) - length vals
22 False -> pos + realSteps
23 newVals = S.insertAt insertPos step vals
24 in (newVals, insertPos + 1)