Skip to content

Commit

Permalink
let Item type of IsList to be IntSet instead of [Int]
Browse files Browse the repository at this point in the history
  • Loading branch information
msakai committed Oct 20, 2021
1 parent 4a368ba commit 40bc620
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Data/DecisionDiagram/ZDD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import qualified Data.HashTable.Class as H
import qualified Data.HashTable.ST.Cuckoo as C
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.List (group, sortBy)
import Data.List (sortBy)
import Data.Proxy
import Data.Set (Set)
import qualified Data.Set as Set
Expand All @@ -113,14 +113,14 @@ newtype ZDD a = ZDD Node
deriving (Eq, Hashable, Show)

instance ItemOrder a => Exts.IsList (ZDD a) where
type Item (ZDD a) = [Int] -- Is it better to use IntSet?
type Item (ZDD a) = IntSet

fromList = fromListOfSortedList . map f
where
f :: [Int] -> [Int]
f = map head . group . sortBy (compareItem (Proxy :: Proxy a))
f :: IntSet -> [Int]
f = sortBy (compareItem (Proxy :: Proxy a)) . IntSet.toList

toList = fold' [] [[]] (\top lo hi -> lo <> map (top :) hi)
toList = fold' [] [IntSet.empty] (\top lo hi -> lo <> map (IntSet.insert top) hi)

zddNode :: Int -> Node -> Node -> Node
zddNode _ p0 F = p0
Expand Down
2 changes: 1 addition & 1 deletion test/TestZDD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ prop_toList_fromList =
forAll arbitrary $ \xss ->
let a :: ZDD o
a = Exts.fromList xss
f = Set.fromList . map IntSet.fromList
f = Set.fromList
in counterexample (show a) $ f (Exts.toList a) === f xss

prop_fromList_toList :: Property
Expand Down

0 comments on commit 40bc620

Please sign in to comment.