private Map<Annotation, Annotation> removeAnnotationsThatPointToInvalidSpanNodes() {
        Map<Annotation, Annotation> removedAnnotations = new IdentityHashMap<Annotation, Annotation>();

        Iterator<Annotation> annotationIt = iterator();
        while (annotationIt.hasNext()) {
            Annotation a = annotationIt.next();
            if (a.hasSpanNode() && !a.isSpanNodeValid()) {
                a.setSpanNode(null);
                a.setFieldValue(null);
                removedAnnotations.put(a, a);
                annotationIt.remove();
            }
        }
        return removedAnnotations;
    }
Ensures consistency of the tree in case SpanNodes have been removed, and there are still
Annotations pointing to them. This method has a maximum upper bound of O(3nm), where n is the
total number of Annotations, and m is the number of SpanNodes that had been removed from the tree.
The lower bound is Omega(n), if no SpanNodes had been removed from the tree.
document/src/main/java/com/yahoo/document/annotation/SpanTree.java