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 intersection bug #420 #427

Merged
merged 5 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
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 Data/HashMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,11 @@ intersectionArrayBy f !b1 !b2 !ary1 !ary2
(len, bFinal) <- go 0 0 0 bCombined bIntersect
case len of
0 -> pure Empty
1 -> A.read mary 0
1 -> do
l <- A.read mary 0
if isLeafOrCollision l
then pure l
else BitmapIndexed bFinal <$> (A.unsafeFreeze =<< A.shrink mary 1)
_ -> bitmapIndexedOrFull bFinal <$> (A.unsafeFreeze =<< A.shrink mary len)
where
bCombined = b1 .|. b2
Expand Down Expand Up @@ -1915,7 +1919,6 @@ searchSwap toFind start = go start toFind start
else go i0 k (i + 1) mary
{-# INLINE searchSwap #-}


------------------------------------------------------------------------
-- * Folds

Expand Down
15 changes: 15 additions & 0 deletions tests/Regressions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Regressions (tests) where

import Control.Exception (evaluate)
import Control.Monad (replicateM)
import Data.Bits (shiftL)
import Data.Hashable (Hashable (..))
import Data.List (delete)
import Data.Maybe (isJust, isNothing)
Expand All @@ -24,6 +25,7 @@ import Test.Tasty.QuickCheck (testProperty)

import qualified Data.HashMap.Lazy as HML
import qualified Data.HashMap.Strict as HMS
import qualified Data.HashSet as HS

#if MIN_VERSION_base(4,12,0)
-- nothunks requires base >= 4.12
Expand Down Expand Up @@ -248,6 +250,18 @@ issue383 = do

#endif

------------------------------------------------------------------------
-- Issue #420

issue420 :: Assertion
issue420 = do
let k1 :: Int = 1 `shiftL` 10
let k2 :: Int = 2 `shiftL` 10
let s0 = HS.fromList [k1, k2]
let s1 = s0 `HS.intersection` s0
assert $ k1 `HS.member` s1
assert $ k2 `HS.member` s1

------------------------------------------------------------------------
-- * Test list

Expand Down Expand Up @@ -277,4 +291,5 @@ tests = testGroup "Regression tests"
#ifdef HAVE_NOTHUNKS
, testCase "issue383" issue383
#endif
, testCase "issue420" issue420
]