Skip to content

Commit

Permalink
refactor: remove duplication of filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rade committed Nov 23, 2017
1 parent de22ef7 commit ef27d54
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,12 @@ type filterUnconnected struct {
// Transform implements Transformer
func (f filterUnconnected) Transform(input Nodes) Nodes {
connected := connected(input.Nodes)
output := report.Nodes{}
filtered := input.Filtered
for id, node := range input.Nodes {
if _, ok := connected[id]; ok || (f.onlyPseudo && !IsPseudoTopology(node)) {
output[id] = node
} else {
filtered++
}
}
// Deleted nodes also need to be cut as destinations in adjacency lists.
for id, node := range output {
newAdjacency := report.MakeIDList()
for _, dstID := range node.Adjacency {
if _, ok := output[dstID]; ok {
newAdjacency = newAdjacency.Add(dstID)
}
return FilterFunc(func(node report.Node) bool {
if _, ok := connected[node.ID]; ok || (f.onlyPseudo && !IsPseudoTopology(node)) {
return true
}
node.Adjacency = newAdjacency
output[id] = node
}
return Nodes{Nodes: output, Filtered: filtered}
return false
}).Transform(input)
}

// FilterUnconnected is a transformer that filters unconnected nodes
Expand Down

0 comments on commit ef27d54

Please sign in to comment.