Implement CommonizerTarget isAncestorOf and isDescendentOf

This commit is contained in:
sebastian.sellmair
2021-03-26 10:05:17 +01:00
parent 108debdcc9
commit 35e1f8a520
3 changed files with 45 additions and 6 deletions
@@ -100,3 +100,15 @@ public val CommonizerTarget.level: Int
is SharedCommonizerTarget -> if (targets.isNotEmpty()) targets.maxOf { it.level } + 1 else 0
}
}
public infix fun CommonizerTarget.isAncestorOf(other: CommonizerTarget): Boolean {
if (this is SharedCommonizerTarget) {
return targets.any { it == other } || targets.any { it.isAncestorOf(other) }
}
return false
}
public infix fun CommonizerTarget.isDescendentOf(other: CommonizerTarget): Boolean {
return other.isAncestorOf(this)
}