module STMContainers.WordArray.Indices where
import STMContainers.Prelude hiding (toList, traverse_)
import qualified STMContainers.Prelude as Prelude
type Indices = Int
type Index = Int
position :: Index -> Indices -> Int
position i b = popCount (b .&. (bit i 1))
singleton :: Index -> Indices
singleton = bit
insert :: Index -> Indices -> Indices
insert i = (bit i .|.)
invert :: Index -> Indices -> Indices
invert i = (bit i `xor`)
elem :: Index -> Indices -> Bool
elem = flip testBit
size :: Indices -> Int
size = popCount
null :: Indices -> Bool
null = (== 0)
maxSize :: Int
maxSize = bitSize (undefined :: Indices)
fromList :: [Index] -> Indices
fromList = foldr (.|.) 0 . map bit
toList :: Indices -> [Index]
toList w = filter (testBit w) allIndices
allIndices :: [Index]
allIndices = [0 .. pred maxSize]
traverse_ :: Applicative f => (Index -> f b) -> Indices -> f ()
traverse_ f = inline Prelude.traverse_ f . inline toList