summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-09-30 06:46:33 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-09-30 06:46:33 +0400
commitedc81ffee27e489453cbd599f9ec95a3071ddb5a (patch)
treefcdee1d1b8e843ad46af79f7cdf7097a6e2c29cb
parent845a3e953ff2ccfe69ae934e1b1d80122363e336 (diff)
Add a couple of functions to BDict
-rw-r--r--src/Data/BEncode/BDict.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Data/BEncode/BDict.hs b/src/Data/BEncode/BDict.hs
index 4ff5caa..d1d5215 100644
--- a/src/Data/BEncode/BDict.hs
+++ b/src/Data/BEncode/BDict.hs
@@ -17,6 +17,8 @@ module Data.BEncode.BDict
17 , Data.BEncode.BDict.singleton 17 , Data.BEncode.BDict.singleton
18 18
19 -- * Query 19 -- * Query
20 , Data.BEncode.BDict.null
21 , Data.BEncode.BDict.member
20 , Data.BEncode.BDict.lookup 22 , Data.BEncode.BDict.lookup
21 23
22 -- * Combine 24 -- * Combine
@@ -81,6 +83,21 @@ singleton :: BKey -> a -> BDictMap a
81singleton k v = Cons k v Nil 83singleton k v = Cons k v Nil
82{-# INLINE singleton #-} 84{-# INLINE singleton #-}
83 85
86-- | /O(1)/. Is the dictionary empty?
87null :: BDictMap a -> Bool
88null Nil = True
89null _ = False
90{-# INLINE null #-}
91
92-- | /O(n)/. Is the key a member of the dictionary?
93member :: BKey -> BDictMap a -> Bool
94member key = go
95 where
96 go Nil = False
97 go (Cons k _ xs)
98 | k == key = True
99 | otherwise = go xs
100
84-- | /O(n)/. Lookup the value at a key in the dictionary. 101-- | /O(n)/. Lookup the value at a key in the dictionary.
85lookup :: BKey -> BDictMap a -> Maybe a 102lookup :: BKey -> BDictMap a -> Maybe a
86lookup x = go 103lookup x = go