Skip to content
Snippets Groups Projects
Commit 17c59f4b authored by Iustin Pop's avatar Iustin Pop
Browse files

Remove unused parameters from PeerMap creation

We remove some unused arguments (added way back for compatibility with
Arrays, which we didn't use in the end). This makes the code clearer
(and doesn't need the Ndx type to be an instance of Num).
parent f9fc7a63
No related branches found
No related tags found
No related merge requests found
......@@ -154,7 +154,7 @@ buildPeers t il num_nodes =
(\i_idx -> let inst = Container.find i_idx il
in (Instance.pnode inst, Instance.mem inst))
(slist t)
pmap = PeerMap.accumArray (+) 0 (0, num_nodes - 1) mdata
pmap = PeerMap.accumArray (+) mdata
new_rmem = computeMaxRes pmap
new_failN1 = computeFailN1 new_rmem (f_mem t) (f_dsk t)
new_prem = (fromIntegral new_rmem) / (t_mem t)
......
......@@ -42,6 +42,7 @@ create _ = []
pmCompare :: (Key, Elem) -> (Key, Elem) -> Ordering
pmCompare a b = (compare `on` snd) b a
-- | Add or update (via a custom function) an element
addWith :: (Elem -> Elem -> Elem) -> Key -> Elem -> PeerMap -> PeerMap
addWith fn k v lst =
let r = lookup k lst
......@@ -50,12 +51,14 @@ addWith fn k v lst =
Nothing -> insertBy pmCompare (k, v) lst
Just o -> insertBy pmCompare (k, fn o v) (remove k lst)
accumArray :: (Elem -> Elem -> Elem) -> Elem -> (Key, Key) ->
[(Key, Elem)] -> PeerMap
accumArray fn _ _ lst =
-- | Create a PeerMap from an association list, with possible duplicates
accumArray :: (Elem -> Elem -> Elem) -- ^ function used to merge the elements
-> [(Key, Elem)] -- ^ source data
-> PeerMap -- ^ results
accumArray fn lst =
case lst of
[] -> empty
(k, v):xs -> addWith fn k v $ accumArray fn undefined undefined xs
(k, v):xs -> addWith fn k v $ accumArray fn xs
find :: Key -> PeerMap -> Elem
find k c = fromMaybe 0 $ lookup k c
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment