diff --git a/Data/IntMultiSet.hs b/Data/IntMultiSet.hs index 31cf684..25f649b 100644 --- a/Data/IntMultiSet.hs +++ b/Data/IntMultiSet.hs @@ -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 diff --git a/Data/MultiSet.hs b/Data/MultiSet.hs index 79fa726..315266f 100644 --- a/Data/MultiSet.hs +++ b/Data/MultiSet.hs @@ -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