Commits

Doug Burke committed 488223f

ToRDF: change around the Hashable instance for RDFLabel

Comments (0)

Files changed (1)

 import qualified Data.Text.Lazy as LT
 import qualified Data.Text.Lazy.IO as LT
 
-import Data.Hashable (Hashable(..))
+import Data.Hashable (Hashable(..), combine)
 import qualified Data.HashSet as HS
 
 import Control.Applicative (Applicative(..), (<$>))
                                   , siocreply_of, sioclinks_to )
 import Swish.RDF.Vocabulary.FOAF (foafname, foafhomepage, foafstatus)
 import Swish.RDF.Vocabulary.DublinCore (dctcreated, dctpublisher, dctreferences)
-import Swish.Utils.Namespace (makeScopedName)
+import Swish.Utils.Namespace (ScopedName, getScopeURI, makeScopedName)
 
 import Network.URI (URI, parseURI)
 
   hashWithSalt s (Arc a b c) = s `hashWithSalt` a `hashWithSalt` b `hashWithSalt` c
 -}
 
+instance Hashable URI where
+  -- lazy instance
+  hash = hash . show
+  
+instance Hashable ScopedName where
+  hash = hash . getScopeURI 
+
 instance Hashable RDFLabel where
 
-  -- lazy instance writing; this may not be the best choice
-  -- for URIs with/without a Namespace - e.g. really want
-  -- the URI serialization to be the underlying URI not 
-  -- something like foo:bar.
-  --
-  hashWithSalt s = hashWithSalt s . show
-
+  hash (Res sn)  = 23 `combine` hash sn
+  hash (Lit l u) = 25 `combine` hash l `hashWithSalt` hash u
+  hash (Blank b) = 27 `combine` hash b
+  hash (Var s)   = 29 `combine` hash s
+  hash NoNode    = 1
+  
 strToInt :: Int -> String -> Int
 strToInt b = foldl' (\cval nval -> cval * b + nval) 0 . map digitToInt