summaryrefslogtreecommitdiff
path: root/src/Data/MinMaxPSQ.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/MinMaxPSQ.hs')
-rw-r--r--src/Data/MinMaxPSQ.hs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/Data/MinMaxPSQ.hs b/src/Data/MinMaxPSQ.hs
index f41da4a4..f385f258 100644
--- a/src/Data/MinMaxPSQ.hs
+++ b/src/Data/MinMaxPSQ.hs
@@ -55,9 +55,12 @@ maxView :: (PSQKey k, Ord p) => MinMaxPSQ k p -> Maybe (Binding k p, MinMaxPSQ k
55maxView (MinMaxPSQ nq xq) = fmap (\(k :-> Down p, xq') -> (k :-> p, MinMaxPSQ (PSQ.delete k nq) xq')) 55maxView (MinMaxPSQ nq xq) = fmap (\(k :-> Down p, xq') -> (k :-> p, MinMaxPSQ (PSQ.delete k nq) xq'))
56 $ PSQ.minView xq 56 $ PSQ.minView xq
57 57
58-- | Maintains a bounded 'MinMaxPSQ' by deleting the maximum element if the
59-- insertion would cause the queue to have too many elements.
58insertTake :: (PSQKey k, Ord p) => Int -> k -> p -> MinMaxPSQ k p -> MinMaxPSQ k p 60insertTake :: (PSQKey k, Ord p) => Int -> k -> p -> MinMaxPSQ k p -> MinMaxPSQ k p
59insertTake n k p q = take n $ insert k p q 61insertTake n k p q = take n $ insert k p q
60 62
63-- | Truncate the 'MinMaxPSQ' to the given number of lowest priority elements.
61take :: (PSQKey k, Ord p) => Int -> MinMaxPSQ k p -> MinMaxPSQ k p 64take :: (PSQKey k, Ord p) => Int -> MinMaxPSQ k p -> MinMaxPSQ k p
62take !n !q | (size q <= n) = q 65take !n !q | (size q <= n) = q
63 | null q = q 66 | null q = q