patch multiple -Z options

This commit is contained in:
Eric Coissac
2025-01-29 21:35:28 +01:00
parent 337954592d
commit 2452aef7a9
5 changed files with 44 additions and 13 deletions

View File

@ -196,3 +196,29 @@ func (set *TaxonSet) Contains(id *string) bool {
node := set.Get(id)
return node != nil
}
func (set *TaxonSet) Sort() *TaxonSlice {
if set == nil {
return nil
}
taxonomy := set.Taxonomy()
taxa := taxonomy.NewTaxonSlice(0, set.Len())
parent := make(map[*TaxNode]bool, set.Len())
pushed := true
for pushed {
pushed = false
for _, node := range set.set {
if !parent[node] && (parent[set.Get(node.parent).Node] ||
!set.Contains(node.parent)) {
pushed = true
taxa.slice = append(taxa.slice, node)
parent[node] = true
}
}
}
return taxa
}