bencoding-0.4.3.0: A library for encoding and decoding of BEncode data.

Portabilityportable
Stabilitystable
Maintainerpxqr.sta@gmail.com
Safe HaskellSafe-Inferred

Data.BEncode.BDict

Contents

Description

This module defines a simple key/value list ordered by keys which both faster and more suitable for bencode dictionaries than just [(k,v)].

Synopsis

Documentation

data BDictMap a Source

BDictMap is an ascending list of key/value pairs sorted by keys.

Constructors

Cons !BKey a !(BDictMap a) 
Nil 

Instances

Construction

empty :: BDictMap aSource

O(1). The empty dicionary.

singleton :: BKey -> a -> BDictMap aSource

O(1). Dictionary of one key-value pair.

Query

null :: BDictMap a -> BoolSource

O(1). Is the dictionary empty?

member :: BKey -> BDictMap a -> BoolSource

O(n). Is the key a member of the dictionary?

lookup :: BKey -> BDictMap a -> Maybe aSource

O(n). Lookup the value at a key in the dictionary.

Combine

union :: BDictMap a -> BDictMap a -> BDictMap aSource

O(n + m). Merge two dictionaries by taking pair from both given dictionaries. Dublicated keys are not filtered.

Traversal

map :: (a -> b) -> BDictMap a -> BDictMap bSource

O(n). Map a function over all values in the dictionary.

bifoldMap :: Monoid m => (BKey -> a -> m) -> BDictMap a -> mSource

O(n). Map each key/value pair to a monoid and fold resulting sequnce using mappend.

Conversion

fromAscList :: [(BKey, a)] -> BDictMap aSource

O(n). Build a dictionary from a list of key/value pairs where the keys are in ascending order.

toAscList :: BDictMap a -> [(BKey, a)]Source

O(n). Convert the dictionary to a list of key/value pairs where the keys are in ascending order.