Skip to content

Commit

Permalink
use hashNub
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Oct 31, 2023
1 parent b55e6b4 commit 89443a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions hcdt.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Geometry/HCDT/Types.hs
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/Geometry/HCDT/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
inEdges = hashNub $ DS.filter (not . isUnique edges) edges

0 comments on commit 89443a7

Please sign in to comment.