Safe HaskellNone



Module abstracting the peer map implementation.

This is abstracted separately since the speed of peermap updates can be a significant part of the total runtime, and as such changing the implementation should be easy in case it's needed.


Type definitions

type Key = Ndx Source #

Our key type.

type Elem = Int Source #

Our element type.

type PeerMap = [(Key, Elem)] Source #

The definition of a peer map.

Initialization functions

empty :: PeerMap Source #

Create a new empty map.

pmCompare :: (Key, Elem) -> (Key, Elem) -> Ordering Source #

Our reverse-compare function.

addWith :: (Elem -> Elem -> Elem) -> Key -> Elem -> PeerMap -> PeerMap Source #

Add or update (via a custom function) an element.

accumArray Source #


:: (Elem -> Elem -> Elem)

function used to merge the elements

-> [(Key, Elem)]

source data

-> PeerMap


Create a PeerMap from an association list, with possible duplicates.

Basic operations

find :: Key -> PeerMap -> Elem Source #

Returns either the value for a key or zero if not found.

add :: Key -> Elem -> PeerMap -> PeerMap Source #

Add an element to a peermap, overwriting the previous value.

remove :: Key -> PeerMap -> PeerMap Source #

Remove an element from a peermap.

maxElem :: PeerMap -> Elem Source #

Find the maximum element.

Since this is a sorted list, we just get the value at the head of the list, or zero for a null list

sumElems :: PeerMap -> Elem Source #

Sum of all peers.