Created
July 25, 2014 12:29
-
-
Save davidxifeng/154f1342851e6dcda076 to your computer and use it in GitHub Desktop.
data structure for fast merge-insert
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
import qualified Data.HashSet as HS | |
import Data.Hashable | |
-- 2014-07-25 20:27:29 | |
-- TODO custom HashSet with special ``insert`` ``fromListWith`` ... | |
data Test = A Int | B Double | C Char | D | |
deriving (Show) | |
instance Eq Test where | |
A _ == A _ = True | |
B _ == B _ = True | |
C _ == C _ = True | |
D == D = True | |
_ == _ = False | |
instance Hashable Test where | |
hash v = | |
case v of | |
A _ -> 1 | |
B _ -> 2 | |
C _ -> 3 | |
D -> 4 | |
t :: HS.HashSet Test | |
t = HS.fromList | |
[ A 1 | |
, B 2.5 | |
, B 3 | |
, C 'H' | |
, D | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment