summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-08-11 18:00:57 -0400
committerjoe <joe@jerkface.net>2017-08-11 18:00:57 -0400
commitcf6007bcd3c64a83b9892d45ba1908ef729890ab (patch)
tree7850e303fe35025e5b183d39ca0d7835ca9ce7cd /src/Data
parent1d4651428baf4a0c45e35fc909407e2d64d7da0b (diff)
MinMaxPSQ, takeView is useful for syncing with another data structure.
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/MinMaxPSQ.hs11
1 files changed, 11 insertions, 0 deletions
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
81 | null q = q 81 | null q = q
82 | otherwise = take n $ deleteMax q 82 | otherwise = take n $ deleteMax q
83 83
84-- | Like 'take', except it provides a list deleted bindings.
85takeView :: (PSQKey k, Ord p) => Int -> MinMaxPSQ' k p v -> ( [Binding' k p v], MinMaxPSQ' k p v )
86takeView !n !q | (size q <= n) = ([], q)
87 | null q = ([], q)
88 | otherwise = let Just (x,q') = maxView q
89 (xs,q'') = takeView n q'
90 ys = x:xs
91 in (ys, ys `seq` q'')
92
93
94
84lookup' :: (PSQKey k, Ord p) => k -> MinMaxPSQ' k p v -> Maybe (p, v) 95lookup' :: (PSQKey k, Ord p) => k -> MinMaxPSQ' k p v -> Maybe (p, v)
85lookup' k (MinMaxPSQ q _) = PSQ.lookup k q 96lookup' k (MinMaxPSQ q _) = PSQ.lookup k q