Container: remove fromAssocList
authorIustin Pop <iustin@google.com>
Thu, 30 Dec 2010 10:18:30 +0000 (11:18 +0100)
committerIustin Pop <iustin@google.com>
Thu, 30 Dec 2010 13:56:42 +0000 (14:56 +0100)
Container.fromAssocList is just a re-export of IntMap.fromList; it
makes sense to remove it and simply export the original name, as it
needs just a bit of renaming in the rest of the code.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Balazs Lecz <leczb@google.com>

Ganeti/HTools/Cluster.hs
Ganeti/HTools/Container.hs
Ganeti/HTools/Loader.hs
Ganeti/HTools/QC.hs
Ganeti/HTools/Simu.hs

index 1e111f0..c3a1a26 100644 (file)
@@ -999,4 +999,4 @@ splitCluster nl il =
            let nidxs = map Node.idx nodes
                nodes' = zip nidxs nodes
                instances = Container.filter ((`elem` nidxs) . Instance.pNode) il
-           in (guuid, (Container.fromAssocList nodes', instances))) ngroups
+           in (guuid, (Container.fromList nodes', instances))) ngroups
index d24bb79..12d1978 100644 (file)
@@ -7,7 +7,7 @@ give the best performance for our workload.
 
 {-
 
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ module Ganeti.HTools.Container
      -- * Creation
     , IntMap.empty
     , IntMap.singleton
-    , fromAssocList
+    , IntMap.fromList
      -- * Query
     , IntMap.size
     , IntMap.null
@@ -69,10 +69,6 @@ find k = (IntMap.! k)
 add :: Key -> a -> Container a -> Container a
 add = IntMap.insert
 
--- | Create a map from an association list.
-fromAssocList :: [(Key, a)] -> Container a
-fromAssocList = IntMap.fromList
-
 -- | Add or update two elements of the map.
 addTwo :: Key -> a -> Key -> a -> Container a -> Container a
 addTwo k1 v1 k2 v2 = add k1 v1 . add k2 v2
index f011629..c17aba1 100644 (file)
@@ -119,7 +119,7 @@ assignIndices nodes =
   let (na, idx_node) =
           unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx)))
           . zip [0..] $ nodes
-  in (M.fromList na, Container.fromAssocList idx_node)
+  in (M.fromList na, Container.fromList idx_node)
 
 -- | For each instance, add its index to its primary and secondary nodes.
 fixNodes :: Node.List
index 1f55a6e..79600b8 100644 (file)
@@ -85,7 +85,7 @@ defGroup = flip Group.setIdx 0 $
                     Types.AllocPreferred
 
 defGroupList :: Group.List
-defGroupList = Container.fromAssocList [(Group.idx defGroup, defGroup)]
+defGroupList = Container.fromList [(Group.idx defGroup, defGroup)]
 
 defGroupAssoc :: Data.Map.Map String Types.Gdx
 defGroupAssoc = Data.Map.singleton (Group.uuid defGroup) (Group.idx defGroup)
@@ -325,7 +325,7 @@ prop_Container_findByName node othername =
                                              nn { Node.name = name,
                                                   Node.alias = alias }))
                $ zip names nodes
-      nl' = Container.fromAssocList nodes'
+      nl' = Container.fromList nodes'
       target = snd (nodes' !! fidx)
   in Container.findByName nl' (Node.name target) == Just target &&
      Container.findByName nl' (Node.alias target) == Just target &&
@@ -655,7 +655,7 @@ prop_Score_Zero node count =
      (Node.tDsk node > 0) && (Node.tMem node > 0)) ==>
     let fn = Node.buildPeers node Container.empty
         nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
-        nl = Container.fromAssocList nlst
+        nl = Container.fromList nlst
         score = Cluster.compCV nl
     -- we can't say == 0 here as the floating point errors accumulate;
     -- this should be much lower than the default score in CLI.hs
@@ -667,7 +667,7 @@ prop_CStats_sane node count =
      (Node.availDisk node > 0) && (Node.availMem node > 0)) ==>
     let fn = Node.buildPeers node Container.empty
         nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
-        nl = Container.fromAssocList nlst
+        nl = Container.fromList nlst
         cstats = Cluster.totalResources nl
     in Cluster.csAdsk cstats >= 0 &&
        Cluster.csAdsk cstats <= Cluster.csFdsk cstats
@@ -770,7 +770,7 @@ prop_ClusterCheckConsistency node inst =
       inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2)
       inst2 = Instance.setBoth inst (Node.idx node1) Node.noSecondary
       inst3 = Instance.setBoth inst (Node.idx node1) (Node.idx node3)
-      ccheck = Cluster.findSplitInstances nl' . Container.fromAssocList
+      ccheck = Cluster.findSplitInstances nl' . Container.fromList
   in null (ccheck [(0, inst1)]) &&
      null (ccheck [(0, inst2)]) &&
      (not . null $ ccheck [(0, inst3)])
@@ -849,7 +849,7 @@ prop_Loader_assignIndices nodes =
 -- | Checks that the number of primary instances recorded on the nodes
 -- is zero
 prop_Loader_mergeData ns =
-  let na = Container.fromAssocList $ map (\n -> (Node.idx n, n)) ns
+  let na = Container.fromList $ map (\n -> (Node.idx n, n)) ns
   in case Loader.mergeData [] [] []
          (Loader.emptyCluster {Loader.cdNodes = na}) of
     Types.Bad _ -> False
index f129a36..1515bd0 100644 (file)
@@ -82,8 +82,8 @@ parseData ndata = do
   let ktn = map (\(idx, n) -> (idx, Node.setIdx n idx))
             $ zip [1..] nodes'
       ktg = map (\g -> (Group.idx g, g)) groups
-  return (ClusterData (Container.fromAssocList ktg)
-                      (Container.fromAssocList ktn) Container.empty [])
+  return (ClusterData (Container.fromList ktg)
+                      (Container.fromList ktn) Container.empty [])
 
 -- | Builds the cluster data from node\/instance files.
 loadData :: [String] -- ^ Cluster description in text format