You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following on from #172, adding insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k -> (Maybe a, Map k a) would be quite useful for avoiding multiple traversals of a map in various algorithms. An example I was working on recently was implementing the Misra-Gries summary for finding the most frequent elements in a streaming dataset:
misraGries::Ordk=>Int->Foldk (M.MapkInt)
misraGries n =Fold step (M.empty ::M.MapkInt) idwhere
step !old k =caseM.insertLookupWithKey (\_k n _ -> n+1) k 1 old of
(Just _prev, new) -> new
(Nothing, new)
|M.size new < n -> new
|otherwise->M.mapMaybe (\case1->Nothing; n ->Just (n-1)) old
I'd also like to have a HashMap based implementation but doing so involves several more traversals of the HashMap.
The text was updated successfully, but these errors were encountered:
Following on from #172, adding
insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k -> (Maybe a, Map k a)
would be quite useful for avoiding multiple traversals of a map in various algorithms. An example I was working on recently was implementing the Misra-Gries summary for finding the most frequent elements in a streaming dataset:I'd also like to have a HashMap based implementation but doing so involves several more traversals of the HashMap.
The text was updated successfully, but these errors were encountered: