patch multiple -Z options

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

No files matched your search

+26
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
}