diff options
Diffstat (limited to 'src/Data/BEncode/BDict.hs')
-rw-r--r-- | src/Data/BEncode/BDict.hs | 17 |
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 | |||
81 | singleton k v = Cons k v Nil | 83 | singleton k v = Cons k v Nil |
82 | {-# INLINE singleton #-} | 84 | {-# INLINE singleton #-} |
83 | 85 | ||
86 | -- | /O(1)/. Is the dictionary empty? | ||
87 | null :: BDictMap a -> Bool | ||
88 | null Nil = True | ||
89 | null _ = False | ||
90 | {-# INLINE null #-} | ||
91 | |||
92 | -- | /O(n)/. Is the key a member of the dictionary? | ||
93 | member :: BKey -> BDictMap a -> Bool | ||
94 | member 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. |
85 | lookup :: BKey -> BDictMap a -> Maybe a | 102 | lookup :: BKey -> BDictMap a -> Maybe a |
86 | lookup x = go | 103 | lookup x = go |