From 740ec0044cedd19d44c8a15d4849844370bd86d9 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sat, 21 Mar 2009 22:00:22 +0100 Subject: [PATCH] Add a separate type for the [(Int, String)] list This is added for better readability, since this is very often used in declarations. --- Ganeti/HTools/Cluster.hs | 21 ++++++++++++--------- hbal.hs | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index b44cc3b62..788288ead 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -10,6 +10,7 @@ module Ganeti.HTools.Cluster -- * Types NodeList , InstanceList + , NameList , Placement , Solution(..) , Table(..) @@ -45,6 +46,8 @@ import Ganeti.HTools.Utils type NodeList = Container.Container Node.Node type InstanceList = Container.Container Instance.Instance +-- | The type used to hold idx-to-name mappings +type NameList = [(Int, String)] -- | A separate name for the cluster score type type Score = Double @@ -584,8 +587,8 @@ computeMoves i a b c d = {-| Converts a placement to string format -} printSolutionLine :: InstanceList - -> [(Int, String)] - -> [(Int, String)] + -> NameList + -> NameList -> Int -> Int -> Placement @@ -619,8 +622,8 @@ formatCmds cmd_strs = {-| Converts a solution to string format -} printSolution :: InstanceList - -> [(Int, String)] - -> [(Int, String)] + -> NameList + -> NameList -> [Placement] -> ([String], [[String]]) printSolution il ktn kti sol = @@ -633,7 +636,7 @@ printSolution il ktn kti sol = zip sol [1..] -- | Print the node list. -printNodes :: [(Int, String)] -> NodeList -> String +printNodes :: NameList -> NodeList -> String printNodes ktn nl = let snl = sortBy (compare `on` Node.idx) (Container.elems nl) snl' = map (\ n -> ((fromJust $ lookup (Node.idx n) ktn), n)) snl @@ -719,9 +722,9 @@ fixNodes nl il = ac3 = (pdx, pnew):(sdx, snew):ac2 in ac3) nl il --- | Compute the longest common suffix of a [(Int, String)] list that +-- | Compute the longest common suffix of a NameList list that -- | starts with a dot -longestDomain :: [(Int, String)] -> String +longestDomain :: NameList -> String longestDomain [] = "" longestDomain ((_,x):xs) = let @@ -733,7 +736,7 @@ longestDomain ((_,x):xs) = "" $ filter (isPrefixOf ".") (tails x) -- | Remove tails from the (Int, String) lists -stripSuffix :: String -> [(Int, String)] -> [(Int, String)] +stripSuffix :: String -> NameList -> NameList stripSuffix suffix lst = let sflen = length suffix in map (\ (key, name) -> (key, take ((length name) - sflen) name)) lst @@ -744,7 +747,7 @@ loadData :: String -- ^ Node data in text format -> String -- ^ Instance data in text format -> (Container.Container Node.Node, Container.Container Instance.Instance, - String, [(Int, String)], [(Int, String)]) + String, NameList, NameList) loadData ndata idata = let {- node file: name mem disk -} diff --git a/hbal.hs b/hbal.hs index 40cedd54d..3eec60bb5 100644 --- a/hbal.hs +++ b/hbal.hs @@ -104,8 +104,8 @@ we find a valid solution or we exceed the maximum depth. -} iterateDepth :: Cluster.Table -- ^ The starting table -> Int -- ^ Remaining length - -> [(Int, String)] -- ^ Node idx to name list - -> [(Int, String)] -- ^ Inst idx to name list + -> Cluster.NameList -- ^ Node idx to name list + -> Cluster.NameList -- ^ Inst idx to name list -> Int -- ^ Max node name len -> Int -- ^ Max instance name len -> [[String]] -- ^ Current command list -- GitLab