From 60db9a2eca692611a193074ebb083de183960c70 Mon Sep 17 00:00:00 2001 From: konsumlamm Date: Mon, 25 Dec 2023 01:51:59 +0100 Subject: [PATCH] Fix wrong `insertShift` computation in `<|` --- src/Data/RRBVector/Internal.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Data/RRBVector/Internal.hs b/src/Data/RRBVector/Internal.hs index 73d0fd8..ec4378c 100644 --- a/src/Data/RRBVector/Internal.hs +++ b/src/Data/RRBVector/Internal.hs @@ -768,7 +768,9 @@ x <| Root size sh tree -- compute the shift at which the new branch needs to be inserted (0 means there is space in the leaf) -- the size is computed for efficient calculation of the shift in a balanced subtree computeShift !sz !sh !min (Balanced _) = - let newShift = (log2 sz `div` blockShift) * blockShift + let hiShift = (log2 (sz - 1) `div` blockShift) * blockShift + hi = (sz - 1) `unsafeShiftR` hiShift + newShift = if hi < blockMask then hiShift else hiShift + blockShift in if newShift > sh then min else newShift computeShift _ sh min (Unbalanced arr sizes) = let sz' = indexPrimArray sizes 0 -- the size of the first subtree