Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -95,29 +95,24 @@ assocEqual = (==) `on` fst ...@@ -95,29 +95,24 @@ assocEqual = (==) `on` fst
-- | For each instance, add its index to its primary and secondary nodes. -- | For each instance, add its index to its primary and secondary nodes.
fixNodes :: [(Ndx, Node.Node)] fixNodes :: [(Ndx, Node.Node)]
-> [(Idx, Instance.Instance)] -> (Idx, Instance.Instance)
-> [(Ndx, Node.Node)] -> [(Ndx, Node.Node)]
fixNodes = fixNodes accu (idx, inst) =
foldl' (\accu (idx, inst) -> let
let pdx = Instance.pnode inst
pdx = Instance.pnode inst sdx = Instance.snode inst
sdx = Instance.snode inst pold = fromJust $ lookup pdx accu
pold = fromJust $ lookup pdx accu pnew = Node.setPri pold idx
pnew = Node.setPri pold idx pnew' = Node.addCpus pnew (Instance.vcpus inst)
pnew' = Node.addCpus pnew (Instance.vcpus inst) ac1 = deleteBy assocEqual (pdx, pold) accu
ac1 = deleteBy assocEqual (pdx, pold) accu ac2 = (pdx, pnew'):ac1
ac2 = (pdx, pnew'):ac1 in
in if sdx /= Node.noSecondary
if sdx /= Node.noSecondary then then let sold = fromJust $ lookup sdx accu
let snew = Node.setSec sold idx
sold = fromJust $ lookup sdx accu ac3 = deleteBy assocEqual (sdx, sold) ac2
snew = Node.setSec sold idx in (sdx, snew):ac3
ac3 = deleteBy assocEqual (sdx, sold) ac2 else ac2
ac4 = (sdx, snew):ac3
in ac4
else
ac2
)
-- | Compute the longest common suffix of a list of strings that -- | Compute the longest common suffix of a list of strings that
-- | starts with a dot. -- | starts with a dot.
...@@ -141,7 +136,7 @@ mergeData :: (Node.AssocList, ...@@ -141,7 +136,7 @@ mergeData :: (Node.AssocList,
-> Result (Node.List, Instance.List, String) -> Result (Node.List, Instance.List, String)
mergeData (nl, il) = do mergeData (nl, il) = do
let let
nl2 = fixNodes nl il nl2 = foldl' fixNodes nl il
il3 = Container.fromAssocList il il3 = Container.fromAssocList il
nl3 = Container.fromAssocList nl3 = Container.fromAssocList
(map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2) (map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment