Skip to content

Commit

Permalink
Revert "Add Data.AssocMap fix"
Browse files Browse the repository at this point in the history
This reverts commit c4e88bd.
  • Loading branch information
ana-pantilie committed Jun 7, 2024
1 parent 21c5ebc commit 329f7b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 205618894
| mem: 1216678})
({cpu: 201521366
| mem: 1194270})
4 changes: 4 additions & 0 deletions plutus-tx/src/PlutusTx/AssocMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ newtype Map k v = Map {unMap :: [(k, v)]}
deriving stock (Generic, Haskell.Show, Data, TH.Lift)
deriving newtype (NFData)

instance (Eq k, Eq v) => Eq (Map k v) where
Map m1 == m2 =
List.all (\(k, v) -> lookup k m2 == Just v) m1

instance (Haskell.Eq k, Haskell.Eq v) => Haskell.Eq (Map k v) where
Map m1 == Map m2 =
Haskell.all (\(k, v) -> Haskell.lookup k m2 Haskell.== Just v) m1
Expand Down
31 changes: 1 addition & 30 deletions plutus-tx/src/PlutusTx/Data/AssocMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,7 @@ this implementation provides slow lookup and update operations because it is bas
on a list representation.
-}
newtype Map k a = Map (BI.BuiltinList (BI.BuiltinPair BuiltinData BuiltinData))
deriving stock (Haskell.Show)

instance (Haskell.Eq k, Haskell.Eq v) => Haskell.Eq (Map k v) where
m1 == m2@(Map m2') =
size m1 == size m2
&& all' (\(P.pairToPair -> (k, v)) -> lookup' k m2' Haskell.== Just v) m1
where
all' p (Map m) = go m
where
go xs =
P.matchList
xs
(\() -> True)
( \hd tl ->
if p hd
then go tl
else False
)
deriving stock (Haskell.Eq, Haskell.Show)

instance P.ToData (Map k a) where
{-# INLINEABLE toBuiltinData #-}
Expand All @@ -88,18 +71,6 @@ instance P.UnsafeFromData (Map k a) where
{-# INLINABLE unsafeFromBuiltinData #-}
unsafeFromBuiltinData = Map . BI.unsafeDataAsMap

{-# INLINEABLE size #-}
size :: forall k a. Map k a -> Integer
size (Map m) = go m
where
go l =
P.matchList
l
(\() -> 0)
( \_ tl ->
1 + go tl
)

{-# INLINEABLE lookup #-}
-- | Look up the value corresponding to the key.
-- If the `Map` is not well-defined, the result is the value associated with
Expand Down

0 comments on commit 329f7b5

Please sign in to comment.