From 17c59f4b2e23914b2b7d32ecb12fa29ec110eb71 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 27 May 2009 21:09:47 +0100
Subject: [PATCH] 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).
---
 Ganeti/HTools/Node.hs    |  2 +-
 Ganeti/HTools/PeerMap.hs | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs
index c95f7f96d..68f8300bb 100644
--- a/Ganeti/HTools/Node.hs
+++ b/Ganeti/HTools/Node.hs
@@ -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)
diff --git a/Ganeti/HTools/PeerMap.hs b/Ganeti/HTools/PeerMap.hs
index 9c142e917..0f9af484f 100644
--- a/Ganeti/HTools/PeerMap.hs
+++ b/Ganeti/HTools/PeerMap.hs
@@ -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
-- 
GitLab