Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/HaskellWorks/Data/RankSelect/Internal/BitSeq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ instance HW.Cons BitSeq where
instance HW.Snoc BitSeq where
snoc (BitSeq ft) b = BitSeq $ case FT.viewr ft of
lt :> Elem w nw -> if nw >= 0 && nw < 64
then Elem (w .|. (bw .<. nw)) (nw + 1) <| lt
else Elem bw 1 <| lt
then lt |> Elem (w .|. (bw .<. nw)) (nw + 1)
else ft |> Elem bw 1
FT.EmptyR -> FT.singleton (Elem bw 1)
where bw = if b then 1 else 0

Expand All @@ -99,6 +99,9 @@ instance Semigroup BitSeq where
FT.EmptyL -> tr
FT.EmptyR -> FT.empty

instance Monoid BitSeq where
mempty = BitSeq mempty

instance Select1 BitSeq where
select1 (BitSeq ft) n = case FT.split (atPopCountBelow n) ft of
(lt, _) -> case FT.viewr lt of
Expand All @@ -112,7 +115,7 @@ instance Rank1 BitSeq where
rank1 bs n = let (lt, _) = splitAt n bs in popCount1 lt

instance PopCount1 BitSeq where
popCount1 (BitSeq ft) = measureBitCount (FT.measure ft :: Measure)
popCount1 (BitSeq ft) = measurePopCount (FT.measure ft :: Measure)

(|>#) :: BitSeqFt -> Elem -> BitSeqFt
(|>#) ft e@(Elem _ wn) = if wn > 0 then ft |> e else ft
Expand Down