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

Issue39 #40

Merged
merged 1 commit into from May 8, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Data/HashMap/Array.hs
Expand Up @@ -48,6 +48,7 @@ module Data.HashMap.Array
, map'
, traverse
, filter
, toList
) where

import qualified Data.Traversable as Traversable
Expand Down
17 changes: 15 additions & 2 deletions Data/HashMap/Base.hs
Expand Up @@ -104,6 +104,7 @@ hash :: H.Hashable a => a -> Hash
hash = fromIntegral . H.hash

data Leaf k v = L !k v
deriving (Eq)

instance (NFData k, NFData v) => NFData (Leaf k v) where
rnf (L k v) = rnf k `seq` rnf v
Expand Down Expand Up @@ -150,9 +151,21 @@ instance (Show k, Show v) => Show (HashMap k v) where
instance Traversable (HashMap k) where
traverse f = traverseWithKey (const f)

-- NOTE: This is just a placeholder.
instance (Eq k, Eq v) => Eq (HashMap k v) where
a == b = toList a == toList b
(==) = equal

equal :: (Eq k, Eq v) => HashMap k v -> HashMap k v -> Bool
equal (BitmapIndexed b1 ary1) (BitmapIndexed b2 ary2) =
b1 == b2 && A.toList ary1 == A.toList ary2
equal (Leaf k1 v1) (Leaf k2 v2) =
k1 == k2 && v1 == v2
equal (Full ary1) (Full ary2) =
A.toList ary1 == A.toList ary2
equal (Collision k1 ary1) (Collision k2 ary2) =
k1 == k2 && A.length ary1 == A.length ary2
&& L.null (A.toList ary1 L.\\ A.toList ary2)
equal Empty Empty = True
equal _ _ = False

------------------------------------------------------------------------
-- * Construction
Expand Down
9 changes: 9 additions & 0 deletions tests/Regressions.hs
Expand Up @@ -13,13 +13,22 @@ issue32 = assert $ isJust $ HM.lookup 7 m'
m = HM.fromList (zip ns (repeat []))
m' = HM.delete 10 m

issue39 :: Assertion
issue39 = assert $ hm1 == hm2
where
hm1 = HM.fromList ([a, b] `zip` [1, 1 :: Int ..])
hm2 = HM.fromList ([b, a] `zip` [1, 1 :: Int ..])
a = (1, -1) :: (Int, Int)
b = (-1, 1) :: (Int, Int)

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

tests :: [Test]
tests =
[
testCase "issue32" issue32
, testCase "issue39" issue39
]

------------------------------------------------------------------------
Expand Down