diff options
author | joe <joe@jerkface.net> | 2017-08-11 18:00:57 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-08-11 18:00:57 -0400 |
commit | cf6007bcd3c64a83b9892d45ba1908ef729890ab (patch) | |
tree | 7850e303fe35025e5b183d39ca0d7835ca9ce7cd /src/Data/MinMaxPSQ.hs | |
parent | 1d4651428baf4a0c45e35fc909407e2d64d7da0b (diff) |
MinMaxPSQ, takeView is useful for syncing with another data structure.
Diffstat (limited to 'src/Data/MinMaxPSQ.hs')
-rw-r--r-- | src/Data/MinMaxPSQ.hs | 11 |
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. | ||
85 | takeView :: (PSQKey k, Ord p) => Int -> MinMaxPSQ' k p v -> ( [Binding' k p v], MinMaxPSQ' k p v ) | ||
86 | takeView !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 | |||
84 | lookup' :: (PSQKey k, Ord p) => k -> MinMaxPSQ' k p v -> Maybe (p, v) | 95 | lookup' :: (PSQKey k, Ord p) => k -> MinMaxPSQ' k p v -> Maybe (p, v) |
85 | lookup' k (MinMaxPSQ q _) = PSQ.lookup k q | 96 | lookup' k (MinMaxPSQ q _) = PSQ.lookup k q |