Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong insertShift computation in <| #18

Merged
merged 2 commits into from
Dec 30, 2023
Merged
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
7 changes: 5 additions & 2 deletions src/Data/RRBVector/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
where
subtree = A.index arr i

-- Integer log base 2.
-- | Integer log base 2.
log2 :: Int -> Int
log2 x = bitSizeMinus1 - countLeadingZeros x
where
Expand Down Expand Up @@ -716,10 +716,10 @@

viewrArr arr = (A.take arr (length arr - 1), A.last arr)

-- the type signature is necessary to compile

Check warning on line 719 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.2)

Pattern match(es) are non-exhaustive

Check warning on line 719 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.4)

Pattern match(es) are non-exhaustive

Check warning on line 719 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.6)

Pattern match(es) are non-exhaustive

Check warning on line 719 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.8)

Pattern match(es) are non-exhaustive
mergeRebalance :: forall a. Shift -> A.Array (Tree a) -> A.Array (Tree a) -> A.Array (Tree a) -> A.Array (Tree a)
mergeRebalance !sh !left !center !right
| sh == blockShift = mergeRebalance' (\(Leaf arr) -> arr) Leaf

Check warning on line 722 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.2)

Pattern match(es) are non-exhaustive

Check warning on line 722 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.4)

Pattern match(es) are non-exhaustive

Check warning on line 722 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.6)

Pattern match(es) are non-exhaustive

Check warning on line 722 in src/Data/RRBVector/Internal.hs

View workflow job for this annotation

GitHub Actions / build (9.8)

Pattern match(es) are non-exhaustive
| otherwise = mergeRebalance' treeToArray (computeSizes (down sh))
where
mergeRebalance' :: (Tree a -> A.Array t) -> (A.Array t -> Tree a) -> A.Array (Tree a)
Expand Down Expand Up @@ -768,7 +768,10 @@
-- 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
-- @sz - 1@ is the index of the last element
let hiShift = max ((log2 (sz - 1) `div` blockShift) * blockShift) 0 -- the shift of the root when normalizing
hi = (sz - 1) `unsafeShiftR` hiShift -- the length of the root node when normalizing minus 1
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
Expand Down