From 1b0e583f90eab0140172d287a57bdaf465080235 Mon Sep 17 00:00:00 2001 From: Alejandro Duran Pallares Date: Mon, 18 Jan 2016 02:13:52 +0100 Subject: [PATCH 1/5] Create README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7abb29 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# multiset +## multiset haskell package + +Originally `Data.MultiSet` was not intended to be used with negative or zero occurences, having therefore unconsitent +behaviors if used that way. This fork modify `Data.MultiSet` to keep it consitent even when used whith negative or +zeros occurences. + + + + + From 7733879e85fdadbb36a6eafa2421d87eb0b87429 Mon Sep 17 00:00:00 2001 From: "Alejandro D.P" Date: Mon, 18 Jan 2016 02:42:34 +0100 Subject: [PATCH 2/5] remove README.md --- README.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index c7abb29..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# multiset -## multiset haskell package - -Originally `Data.MultiSet` was not intended to be used with negative or zero occurences, having therefore unconsitent -behaviors if used that way. This fork modify `Data.MultiSet` to keep it consitent even when used whith negative or -zeros occurences. - - - - - From 9104de438a1b312c7cdc73dde9abe499b302822f Mon Sep 17 00:00:00 2001 From: "Alejandro D.P" Date: Mon, 18 Jan 2016 02:51:09 +0100 Subject: [PATCH 3/5] Data.MultiSet to handle 0 and negative values --- Data/MultiSet.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Data/MultiSet.hs b/Data/MultiSet.hs index 79fa726..ba45ba8 100644 --- a/Data/MultiSet.hs +++ b/Data/MultiSet.hs @@ -283,7 +283,7 @@ deleteAll x = MS . Map.delete x . unMS deleteN :: Occur -> Occur -> Maybe Occur deleteN n m - | m <= n = Nothing + | m == n = Nothing | otherwise = Just (m - n) @@ -556,17 +556,17 @@ toAscOccurList = Map.toAscList . unMS -- | /O(n*log n)/. Create a multiset from a list of element\/occurence pairs. fromOccurList :: Ord a => [(a,Occur)] -> MultiSet a -fromOccurList = MS . Map.fromListWith (+) +fromOccurList = MS . Map.filter (/=0) . Map.fromListWith (+) -- | /O(n)/. Build a multiset from an ascending list of element\/occurence pairs in linear time. -- /The precondition (input list is ascending) is not checked./ fromAscOccurList :: Eq a => [(a,Occur)] -> MultiSet a -fromAscOccurList = MS . Map.fromAscListWith (+) +fromAscOccurList = MS . Map.filter (/=0) . Map.fromAscListWith (+) -- | /O(n)/. Build a multiset from an ascending list of elements\/occurence pairs where each elements appears only once. -- /The precondition (input list is strictly ascending) is not checked./ fromDistinctAscOccurList :: [(a,Occur)] -> MultiSet a -fromDistinctAscOccurList = MS . Map.fromDistinctAscList +fromDistinctAscOccurList = MS . Map.filter (/=0) . Map.fromDistinctAscList {-------------------------------------------------------------------- Map @@ -578,7 +578,7 @@ toMap = unMS -- | /O(n)/. Convert a 'Map' from elements to occurrences to a multiset. fromMap :: Ord a => Map a Occur -> MultiSet a -fromMap = MS . Map.filter (>0) +fromMap = MS . Map.filter (==0) -- | /O(1)/. Convert a 'Map' from elements to occurrences to a multiset. -- Assumes that the 'Map' contains only values larger than one. From 5a09e5572a99ecade10c230ab6c8298e82b365ff Mon Sep 17 00:00:00 2001 From: "Alejandro D.P" Date: Mon, 18 Jan 2016 02:55:17 +0100 Subject: [PATCH 4/5] Data.IntMultiSet to handle 0 and negative values --- Data/IntMultiSet.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Data/IntMultiSet.hs b/Data/IntMultiSet.hs index 31cf684..7f3a8a0 100644 --- a/Data/IntMultiSet.hs +++ b/Data/IntMultiSet.hs @@ -276,7 +276,7 @@ deleteAll x = MS . Map.delete x . unMS deleteN :: Int -> Int -> Maybe Int deleteN n m - | m <= n = Nothing + | m == n = Nothing | otherwise = Just (m - n) @@ -562,17 +562,17 @@ toAscOccurList = Map.toAscList . unMS -- | /O(n*min(n,W))/. Create a multiset from a list of element\/occurence pairs. fromOccurList :: [(Int,Int)] -> IntMultiSet -fromOccurList = MS . Map.fromListWith (+) +fromOccurList = MS . Map.filter (==0) . Map.fromListWith (+) -- | /O(n)/. Build a multiset from an ascending list of element\/occurence pairs in linear time. -- /The precondition (input list is ascending) is not checked./ fromAscOccurList :: [(Int,Int)] -> IntMultiSet -fromAscOccurList = MS . Map.fromAscListWith (+) +fromAscOccurList = MS . Map.filter (==0) . Map.fromAscListWith (+) -- | /O(n)/. Build a multiset from an ascending list of elements\/occurence pairs where each elements appears only once. -- /The precondition (input list is strictly ascending) is not checked./ fromDistinctAscOccurList :: [(Int,Int)] -> IntMultiSet -fromDistinctAscOccurList = MS . Map.fromDistinctAscList +fromDistinctAscOccurList = MS . Map.filter (==0) . Map.fromDistinctAscList {-------------------------------------------------------------------- Map @@ -584,7 +584,7 @@ toMap = unMS -- | /O(n)/. Convert an 'IntMap' from elements to occurrences to a multiset. fromMap :: IntMap Int -> IntMultiSet -fromMap = MS . Map.filter (>0) +fromMap = MS . Map.filter (==0) -- | /O(1)/. Convert an 'IntMap' from elements to occurrences to a multiset. -- Assumes that the 'IntMap' contains only values larger than one. From badf3ae48a6d4d5b95cbe4150845087fcd667c61 Mon Sep 17 00:00:00 2001 From: "Alejandro D.P" Date: Thu, 21 Jan 2016 15:12:47 +0100 Subject: [PATCH 5/5] Non positive occurrences are silently filtered. --- Data/IntMultiSet.hs | 10 +++++----- Data/MultiSet.hs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Data/IntMultiSet.hs b/Data/IntMultiSet.hs index 7f3a8a0..25f649b 100644 --- a/Data/IntMultiSet.hs +++ b/Data/IntMultiSet.hs @@ -276,7 +276,7 @@ deleteAll x = MS . Map.delete x . unMS deleteN :: Int -> Int -> Maybe Int deleteN n m - | m == n = Nothing + | m <= n = Nothing | otherwise = Just (m - n) @@ -562,17 +562,17 @@ toAscOccurList = Map.toAscList . unMS -- | /O(n*min(n,W))/. Create a multiset from a list of element\/occurence pairs. fromOccurList :: [(Int,Int)] -> IntMultiSet -fromOccurList = MS . Map.filter (==0) . Map.fromListWith (+) +fromOccurList = MS . Map.filter (>0) . Map.fromListWith (+) -- | /O(n)/. Build a multiset from an ascending list of element\/occurence pairs in linear time. -- /The precondition (input list is ascending) is not checked./ fromAscOccurList :: [(Int,Int)] -> IntMultiSet -fromAscOccurList = MS . Map.filter (==0) . Map.fromAscListWith (+) +fromAscOccurList = MS . Map.filter (>0) . Map.fromAscListWith (+) -- | /O(n)/. Build a multiset from an ascending list of elements\/occurence pairs where each elements appears only once. -- /The precondition (input list is strictly ascending) is not checked./ fromDistinctAscOccurList :: [(Int,Int)] -> IntMultiSet -fromDistinctAscOccurList = MS . Map.filter (==0) . Map.fromDistinctAscList +fromDistinctAscOccurList = MS . Map.filter (>0) . Map.fromDistinctAscList {-------------------------------------------------------------------- Map @@ -584,7 +584,7 @@ toMap = unMS -- | /O(n)/. Convert an 'IntMap' from elements to occurrences to a multiset. fromMap :: IntMap Int -> IntMultiSet -fromMap = MS . Map.filter (==0) +fromMap = MS . Map.filter (>0) -- | /O(1)/. Convert an 'IntMap' from elements to occurrences to a multiset. -- Assumes that the 'IntMap' contains only values larger than one. diff --git a/Data/MultiSet.hs b/Data/MultiSet.hs index ba45ba8..315266f 100644 --- a/Data/MultiSet.hs +++ b/Data/MultiSet.hs @@ -283,7 +283,7 @@ deleteAll x = MS . Map.delete x . unMS deleteN :: Occur -> Occur -> Maybe Occur deleteN n m - | m == n = Nothing + | m <= n = Nothing | otherwise = Just (m - n) @@ -556,17 +556,17 @@ toAscOccurList = Map.toAscList . unMS -- | /O(n*log n)/. Create a multiset from a list of element\/occurence pairs. fromOccurList :: Ord a => [(a,Occur)] -> MultiSet a -fromOccurList = MS . Map.filter (/=0) . Map.fromListWith (+) +fromOccurList = MS . Map.filter (>0) . Map.fromListWith (+) -- | /O(n)/. Build a multiset from an ascending list of element\/occurence pairs in linear time. -- /The precondition (input list is ascending) is not checked./ fromAscOccurList :: Eq a => [(a,Occur)] -> MultiSet a -fromAscOccurList = MS . Map.filter (/=0) . Map.fromAscListWith (+) +fromAscOccurList = MS . Map.filter (>0) . Map.fromAscListWith (+) -- | /O(n)/. Build a multiset from an ascending list of elements\/occurence pairs where each elements appears only once. -- /The precondition (input list is strictly ascending) is not checked./ fromDistinctAscOccurList :: [(a,Occur)] -> MultiSet a -fromDistinctAscOccurList = MS . Map.filter (/=0) . Map.fromDistinctAscList +fromDistinctAscOccurList = MS . Map.filter (>0) . Map.fromDistinctAscList {-------------------------------------------------------------------- Map @@ -578,7 +578,7 @@ toMap = unMS -- | /O(n)/. Convert a 'Map' from elements to occurrences to a multiset. fromMap :: Ord a => Map a Occur -> MultiSet a -fromMap = MS . Map.filter (==0) +fromMap = MS . Map.filter (>0) -- | /O(1)/. Convert a 'Map' from elements to occurrences to a multiset. -- Assumes that the 'Map' contains only values larger than one.