module System.TPFS.SuperBlock (
module System.TPFS.SolidArray,
SuperBlockState(..),
bitsToSBStates,
sbStatesToBits
) where
import Control.Applicative
import qualified Data.ByteString.Lazy as B
import System.TPFS.Bitmap
import System.TPFS.SolidArray
data SuperBlockState = SBEmpty
| SBSpaceAvailable
| SBFull
deriving (Show, Read, Eq)
instance SolidArray SuperBlockState where
arrRead h a (s,e) = bitsToSBStates <$> arrRead h a (s*2,e*2+1)
arrWrite h a o = arrWrite h a (o*2) . sbStatesToBits
bitsToSBStates :: [Bool] -> [SuperBlockState]
bitsToSBStates (False : False : xs) = SBEmpty : bitsToSBStates xs
bitsToSBStates (True : False : xs) = SBSpaceAvailable : bitsToSBStates xs
bitsToSBStates (True : True : xs) = SBFull : bitsToSBStates xs
bitsToSBStates [] = []
sbStatesToBits :: [SuperBlockState] -> [Bool]
sbStatesToBits (SBEmpty : xs) = False : False : sbStatesToBits xs
sbStatesToBits (SBSpaceAvailable : xs) = True : False : sbStatesToBits xs
sbStatesToBits (SBFull : xs) = True : True : sbStatesToBits xs
sbStatesToBits [] = []