module Data.PrimitiveArray.Index.Int where
import Data.Vector.Fusion.Stream.Monadic (map,Step(..))
import Prelude hiding (map)
import Data.PrimitiveArray.Index.Class
import Data.PrimitiveArray.Vector.Compat
instance Index Int where
linearIndex _ _ k = k
smallestLinearIndex _ = error "still needed?"
largestLinearIndex h = h
size _ h = h+1
inBounds l h k = l <= k && k <= h
instance IndexStream z => IndexStream (z:.Int) where
streamUp (ls:.l) (hs:.h) = flatten mk step $ streamUp ls hs
where mk z = return (z,l)
step (z,k)
| k > h = return $ Done
| otherwise = return $ Yield (z:.k) (z,k+1)
streamDown (ls:.l) (hs:.h) = flatten mk step $ streamDown ls hs
where mk z = return (z,h)
step (z,k)
| k < l = return $ Done
| otherwise = return $ Yield (z:.k) (z,k1)
instance IndexStream Int where
streamUp l h = map (\(Z:.k) -> k) $ streamUp (Z:.l) (Z:.h)
streamDown l h = map (\(Z:.k) -> k) $ streamDown (Z:.l) (Z:.h)