diff options
Diffstat (limited to 'src/Data/MinMaxPSQ.hs')
-rw-r--r-- | src/Data/MinMaxPSQ.hs | 3 |
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 | |||
55 | maxView (MinMaxPSQ nq xq) = fmap (\(k :-> Down p, xq') -> (k :-> p, MinMaxPSQ (PSQ.delete k nq) xq')) | 55 | maxView (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. | ||
58 | insertTake :: (PSQKey k, Ord p) => Int -> k -> p -> MinMaxPSQ k p -> MinMaxPSQ k p | 60 | insertTake :: (PSQKey k, Ord p) => Int -> k -> p -> MinMaxPSQ k p -> MinMaxPSQ k p |
59 | insertTake n k p q = take n $ insert k p q | 61 | insertTake n k p q = take n $ insert k p q |
60 | 62 | ||
63 | -- | Truncate the 'MinMaxPSQ' to the given number of lowest priority elements. | ||
61 | take :: (PSQKey k, Ord p) => Int -> MinMaxPSQ k p -> MinMaxPSQ k p | 64 | take :: (PSQKey k, Ord p) => Int -> MinMaxPSQ k p -> MinMaxPSQ k p |
62 | take !n !q | (size q <= n) = q | 65 | take !n !q | (size q <= n) = q |
63 | | null q = q | 66 | | null q = q |