From cf6007bcd3c64a83b9892d45ba1908ef729890ab Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 11 Aug 2017 18:00:57 -0400 Subject: MinMaxPSQ, takeView is useful for syncing with another data structure. --- src/Data/MinMaxPSQ.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/Data/MinMaxPSQ.hs b/src/Data/MinMaxPSQ.hs index a6329175..2b3b17b5 100644 --- a/src/Data/MinMaxPSQ.hs +++ b/src/Data/MinMaxPSQ.hs @@ -81,5 +81,16 @@ take !n !q | (size q <= n) = q | null q = q | otherwise = take n $ deleteMax q +-- | Like 'take', except it provides a list deleted bindings. +takeView :: (PSQKey k, Ord p) => Int -> MinMaxPSQ' k p v -> ( [Binding' k p v], MinMaxPSQ' k p v ) +takeView !n !q | (size q <= n) = ([], q) + | null q = ([], q) + | otherwise = let Just (x,q') = maxView q + (xs,q'') = takeView n q' + ys = x:xs + in (ys, ys `seq` q'') + + + lookup' :: (PSQKey k, Ord p) => k -> MinMaxPSQ' k p v -> Maybe (p, v) lookup' k (MinMaxPSQ q _) = PSQ.lookup k q -- cgit v1.2.3