Skip to content

Instantly share code, notes, and snippets.

@blaxill
Created February 24, 2023 12:42
Show Gist options
  • Save blaxill/8e9dfa2d9b56edc7856f5fb73907fa7b to your computer and use it in GitHub Desktop.
Save blaxill/8e9dfa2d9b56edc7856f5fb73907fa7b to your computer and use it in GitHub Desktop.
index 3a6d622..628027e 100644
--- a/src/HaskellWorks/Data/RankSelect/Internal/BitSeq.hs
+++ b/src/HaskellWorks/Data/RankSelect/Internal/BitSeq.hs
@@ -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
@@ -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
@@ -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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment