Commit d71d0a1d authored by Iustin Pop's avatar Iustin Pop
Browse files

Take the foldl out of Loader.fixNodes

Currently Loader.fixNodes is foldl' with a complicated function. It
makes more sense to take foldl' out of this function (and put it into
the caller) and let fixNodes be only this internal function.
parent 41c3b292
......@@ -95,29 +95,24 @@ assocEqual = (==) `on` fst
-- | For each instance, add its index to its primary and secondary nodes.
fixNodes :: [(Ndx, Node.Node)]
-> [(Idx, Instance.Instance)]
-> (Idx, Instance.Instance)
-> [(Ndx, Node.Node)]
fixNodes =
foldl' (\accu (idx, inst) ->
let
pdx = Instance.pnode inst
sdx = Instance.snode inst
pold = fromJust $ lookup pdx accu
pnew = Node.setPri pold idx
pnew' = Node.addCpus pnew (Instance.vcpus inst)
ac1 = deleteBy assocEqual (pdx, pold) accu
ac2 = (pdx, pnew'):ac1
in
if sdx /= Node.noSecondary then
let
sold = fromJust $ lookup sdx accu
snew = Node.setSec sold idx
ac3 = deleteBy assocEqual (sdx, sold) ac2
ac4 = (sdx, snew):ac3
in ac4
else
ac2
)
fixNodes accu (idx, inst) =
let
pdx = Instance.pnode inst
sdx = Instance.snode inst
pold = fromJust $ lookup pdx accu
pnew = Node.setPri pold idx
pnew' = Node.addCpus pnew (Instance.vcpus inst)
ac1 = deleteBy assocEqual (pdx, pold) accu
ac2 = (pdx, pnew'):ac1
in
if sdx /= Node.noSecondary
then let sold = fromJust $ lookup sdx accu
snew = Node.setSec sold idx
ac3 = deleteBy assocEqual (sdx, sold) ac2
in (sdx, snew):ac3
else ac2
-- | Compute the longest common suffix of a list of strings that
-- | starts with a dot.
......@@ -141,7 +136,7 @@ mergeData :: (Node.AssocList,
-> Result (Node.List, Instance.List, String)
mergeData (nl, il) = do
let
nl2 = fixNodes nl il
nl2 = foldl' fixNodes nl il
il3 = Container.fromAssocList il
nl3 = Container.fromAssocList
(map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment