diff --git a/hcdt.cabal b/hcdt.cabal index 2f61626..534a294 100644 --- a/hcdt.cabal +++ b/hcdt.cabal @@ -30,6 +30,8 @@ library build-depends: base >= 4.7 && < 5 , containers >= 0.6.4.1 , indexed-traversable >= 0.1.2 + , hashable >= 1.4.0.0 + , witherable >= 0.4 if impl(ghc >= 9.4) build-depends: system-cxx-std-lib == 1.0 elif os(darwin) || os(freebsd) diff --git a/src/Geometry/HCDT/Types.hs b/src/Geometry/HCDT/Types.hs index d60beea..4491073 100644 --- a/src/Geometry/HCDT/Types.hs +++ b/src/Geometry/HCDT/Types.hs @@ -1,6 +1,8 @@ {-# LANGUAGE InstanceSigs #-} + module Geometry.HCDT.Types where +import Data.Hashable (Hashable, hashWithSalt) import Data.IntMap.Strict (IntMap) import Data.List (sort) @@ -15,6 +17,8 @@ data Edge = Edge Int Int instance Eq Edge where (==) :: Edge -> Edge -> Bool Edge i j == Edge i' j' = (i == i' && j == j') || (i == j' && j == i') +instance Hashable Edge where + hashWithSalt s (Edge m1 m2) = hashWithSalt s (min m1 m2) `hashWithSalt` (max m1 m2) data Vertex = Vertex Double Double deriving (Show, Eq) diff --git a/src/Geometry/HCDT/Utils.hs b/src/Geometry/HCDT/Utils.hs index 8bf0d82..9110b2e 100644 --- a/src/Geometry/HCDT/Utils.hs +++ b/src/Geometry/HCDT/Utils.hs @@ -8,9 +8,9 @@ import Geometry.HCDT.Types ( Triangulation(_triangles), Edge(..), Triangle(..) ) import Data.Sequence as DS (Seq, fromList, (><), filter, deleteAt) import Data.Maybe (isNothing, fromJust) -import Data.Foldable (find, toList) +import Data.Foldable (find) import Data.Foldable.WithIndex (ifind) -import Data.List (nub) +import Witherable (hashNub) triangleEdges :: Triangle -> Seq Edge triangleEdges (Triangle i j k) = fromList [Edge i j, Edge j k, Edge i k] @@ -46,4 +46,4 @@ partitionEdges triangulation = (exEdges, inEdges) where edges = allEdges triangulation exEdges = DS.filter (isUnique edges) edges - inEdges = DS.fromList $ nub $ toList $ DS.filter (not . isUnique edges) edges \ No newline at end of file + inEdges = hashNub $ DS.filter (not . isUnique edges) edges \ No newline at end of file