Skip to content

Instantly share code, notes, and snippets.

@davidxifeng
Created July 25, 2014 12:29
Show Gist options
  • Save davidxifeng/154f1342851e6dcda076 to your computer and use it in GitHub Desktop.
Save davidxifeng/154f1342851e6dcda076 to your computer and use it in GitHub Desktop.
data structure for fast merge-insert
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