Skip to content

Commit 0920ed3

Browse files
Fix off-by-1 bug in slidingWindow
1 parent 0ab8a0b commit 0920ed3

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

core/src/Streamly/Internal/Data/RingArray.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ slidingWindowWith n (Fold step1 initial1 extract1 final1) =
918918
return $
919919
case r of
920920
Partial s -> Partial
921-
$ SWArray (MutArray.arrContents arr) 0 s n
921+
$ SWArray (MutArray.arrContents arr) 0 s (n - 1)
922922
Done b -> Done b
923923

924924
step (SWArray mba rh st i) a = do
@@ -929,12 +929,13 @@ slidingWindowWith n (Fold step1 initial1 extract1 final1) =
929929
case r of
930930
Partial s ->
931931
if i > 0
932-
then Partial $ SWArray mba rh1 s (i-1)
932+
then Partial $ SWArray mba rh1 s (i - 1)
933933
else Partial $ SWRing mba rh1 s
934934
Done b -> Done b
935935

936936
step (SWRing mba rh st) a = do
937-
(rb1@(RingArray _ _ rh1), old) <- replace (RingArray mba (n * SIZE_OF(a)) rh) a
937+
(rb1@(RingArray _ _ rh1), old) <-
938+
replace (RingArray mba (n * SIZE_OF(a)) rh) a
938939
r <- step1 st ((a, Just old), toMutArray rb1)
939940
return $
940941
case r of

0 commit comments

Comments
 (0)