-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests and benchmarks. * Implement Eq and Ord using foldMap + iterator. Effect on benchmark times, using GHC 9.6.3: Set Int, eq: -61% Set Int, compare: -53% Map Int Int, eq: -68% Map Int Int, compare: -76%
- Loading branch information
Showing
9 changed files
with
213 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{-# LANGUAGE CPP #-} | ||
module Utils.Containers.Internal.EqOrdUtil | ||
( EqM(..) | ||
, OrdM(..) | ||
) where | ||
|
||
#if !MIN_VERSION_base(4,11,0) | ||
import Data.Semigroup (Semigroup(..)) | ||
#endif | ||
import Utils.Containers.Internal.StrictPair | ||
|
||
newtype EqM a = EqM { runEqM :: a -> StrictPair Bool a } | ||
|
||
-- | Composes left-to-right, short-circuits on False | ||
instance Semigroup (EqM a) where | ||
f <> g = EqM $ \x -> case runEqM f x of | ||
r@(e :*: x') -> if e then runEqM g x' else r | ||
|
||
instance Monoid (EqM a) where | ||
mempty = EqM (True :*:) | ||
#if !MIN_VERSION_base(4,11,0) | ||
mappend = (<>) | ||
#endif | ||
|
||
newtype OrdM a = OrdM { runOrdM :: a -> StrictPair Ordering a } | ||
|
||
-- | Composes left-to-right, short-circuits on non-EQ | ||
instance Semigroup (OrdM a) where | ||
f <> g = OrdM $ \x -> case runOrdM f x of | ||
r@(o :*: x') -> case o of | ||
EQ -> runOrdM g x' | ||
_ -> r | ||
|
||
instance Monoid (OrdM a) where | ||
mempty = OrdM (EQ :*:) | ||
#if !MIN_VERSION_base(4,11,0) | ||
mappend = (<>) | ||
#endif |