Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Data/IntMultiSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Data/MultiSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down