tops<T extends Parentable<T>> function

Set<T> tops<T extends Parentable<T>>(
  1. Iterable<T> parentables
)

Get the top most components (any child that has an ancestor in the set should be pruned).

Implementation

Set<T> tops<T extends Parentable<T>>(Iterable<T> parentables) {
  var tips = <T>{};
  outerLoop:
  for (final item in parentables) {
    for (T? parent = item.parent; parent != null; parent = parent.parent) {
      if (parentables.contains(parent)) {
        continue outerLoop;
      }
    }
    tips.add(item);
  }
  return tips;
}