--- | For each instance, add its index to its primary and secondary nodes
-fixNodes :: [(Int, Node.Node)]
- -> [(Int, Instance.Instance)]
- -> [(Int, Node.Node)]
-fixNodes nl il =
- foldl' (\accu (idx, inst) ->
- let
- assocEqual = (\ (i, _) (j, _) -> i == j)
- pdx = Instance.pnode inst
- sdx = Instance.snode inst
- pold = fromJust $ lookup pdx accu
- pnew = Node.setPri pold idx
- 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
- ) nl il
-
--- | Compute the longest common suffix of a NameList list that
--- | starts with a dot
+-- | Assoc element comparator
+assocEqual :: (Eq a) => (a, b) -> (a, b) -> Bool
+assocEqual = (==) `on` fst
+
+-- | For each instance, add its index to its primary and secondary nodes.
+fixNodes :: [(Ndx, Node.Node)]
+ -> Instance.Instance
+ -> [(Ndx, Node.Node)]
+fixNodes accu inst =
+ let
+ pdx = Instance.pNode inst
+ sdx = Instance.sNode inst
+ pold = fromJust $ lookup pdx accu
+ pnew = Node.setPri pold 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 inst
+ ac3 = deleteBy assocEqual (sdx, sold) ac2
+ in (sdx, snew):ac3
+ else ac2
+
+-- | Remove non-selected tags from the exclusion list
+filterExTags :: [String] -> Instance.Instance -> Instance.Instance
+filterExTags tl inst =
+ let old_tags = Instance.tags inst
+ new_tags = filter (\tag -> any (`isPrefixOf` tag) tl)
+ old_tags
+ in inst { Instance.tags = new_tags }
+
+-- | Update the movable attribute
+updateMovable :: [String] -> Instance.Instance -> Instance.Instance
+updateMovable exinst inst =
+ if Instance.sNode inst == Node.noSecondary ||
+ Instance.name inst `elem` exinst
+ then Instance.setMovable inst False
+ else inst
+
+-- | Compute the longest common suffix of a list of strings that
+-- | starts with a dot.