From 6dc960bc02331d652c7bcb96c391811beb8fdfae Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sat, 14 Mar 2009 12:41:13 +0100
Subject: [PATCH] Move a function around in hbal.hs

This just reorders some functions for a more logical ordering.
---
 src/hbal.hs | 82 ++++++++++++++++++++++++++---------------------------
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/hbal.hs b/src/hbal.hs
index b425f9265..2a27b39ea 100644
--- a/src/hbal.hs
+++ b/src/hbal.hs
@@ -45,47 +45,6 @@ defaultOptions  = Options
  , optVerbose   = 0
  }
 
-{- | Start computing the solution at the given depth and recurse until
-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
-             -> Int              -- ^ Max node name len
-             -> Int              -- ^ Max instance name len
-             -> [[String]]       -- ^ Current command list
-             -> Bool             -- ^ Wheter to be silent
-             -> IO (Cluster.Table, [[String]]) -- ^ The resulting table and
-                                               -- commands
-iterateDepth ini_tbl max_rounds ktn kti nmlen imlen cmd_strs oneline =
-    let Cluster.Table ini_nl ini_il ini_cv ini_plc = ini_tbl
-        all_inst = Container.elems ini_il
-        node_idx = Container.keys ini_nl
-        fin_tbl = Cluster.checkMove node_idx ini_tbl all_inst
-        (Cluster.Table _ _ fin_cv fin_plc) = fin_tbl
-        ini_plc_len = length ini_plc
-        fin_plc_len = length fin_plc
-        allowed_next = (max_rounds < 0 || length fin_plc < max_rounds)
-    in
-      do
-        let
-            (sol_line, cmds) = Cluster.printSolutionLine ini_il ktn kti
-                               nmlen imlen (head fin_plc) fin_plc_len
-            upd_cmd_strs = cmds:cmd_strs
-        unless (oneline || fin_plc_len == ini_plc_len) $ do
-          putStrLn sol_line
-          hFlush stdout
-        (if fin_cv < ini_cv then -- this round made success, try deeper
-             if allowed_next
-             then iterateDepth fin_tbl max_rounds ktn kti
-                  nmlen imlen upd_cmd_strs oneline
-             -- don't go deeper, but return the better solution
-             else return (fin_tbl, upd_cmd_strs)
-         else
-             return (ini_tbl, cmd_strs))
-
 -- | Options list and functions
 options :: [OptDescr (Options -> Options)]
 options =
@@ -128,6 +87,47 @@ parseOpts argv =
       where header = printf "hbal %s\nUsage: hbal [OPTION...]"
                      Version.version
 
+{- | Start computing the solution at the given depth and recurse until
+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
+             -> Int              -- ^ Max node name len
+             -> Int              -- ^ Max instance name len
+             -> [[String]]       -- ^ Current command list
+             -> Bool             -- ^ Wheter to be silent
+             -> IO (Cluster.Table, [[String]]) -- ^ The resulting table and
+                                               -- commands
+iterateDepth ini_tbl max_rounds ktn kti nmlen imlen cmd_strs oneline =
+    let Cluster.Table ini_nl ini_il ini_cv ini_plc = ini_tbl
+        all_inst = Container.elems ini_il
+        node_idx = Container.keys ini_nl
+        fin_tbl = Cluster.checkMove node_idx ini_tbl all_inst
+        (Cluster.Table _ _ fin_cv fin_plc) = fin_tbl
+        ini_plc_len = length ini_plc
+        fin_plc_len = length fin_plc
+        allowed_next = (max_rounds < 0 || length fin_plc < max_rounds)
+    in
+      do
+        let
+            (sol_line, cmds) = Cluster.printSolutionLine ini_il ktn kti
+                               nmlen imlen (head fin_plc) fin_plc_len
+            upd_cmd_strs = cmds:cmd_strs
+        unless (oneline || fin_plc_len == ini_plc_len) $ do
+          putStrLn sol_line
+          hFlush stdout
+        (if fin_cv < ini_cv then -- this round made success, try deeper
+             if allowed_next
+             then iterateDepth fin_tbl max_rounds ktn kti
+                  nmlen imlen upd_cmd_strs oneline
+             -- don't go deeper, but return the better solution
+             else return (fin_tbl, upd_cmd_strs)
+         else
+             return (ini_tbl, cmd_strs))
+
 -- | Main function.
 main :: IO ()
 main = do
-- 
GitLab