protected Iterator<DR> orderedIterator(Q query) {
		return new PeekableIterator<DR>() {
			Comparator<NS> boundsComparator =
				query != null ? query.getBoundsComparator() : getDefaultBoundsComparator();
			Comparator<? super DBTreeRecord<?, ? extends NS>> recordComparator =
				Comparator.comparing(DBTreeRecord::getBounds, boundsComparator);
			PriorityQueue<DBTreeRecord<?, ? extends NS>> queue =
				new PriorityQueue<>(recordComparator);

			{
				descend(root);
			}

			private DR next;
			private boolean soughtNext;

			private void checkSoughtNext() {
				if (!soughtNext) {
					next = findNext();
					soughtNext = true;
				}
			}

			private void descend(NR nr) {
				queue.addAll(getChildrenOf(nr));
			}

			private DR findNext() {
				while (true) {
					DBTreeRecord<?, ? extends NS> rec = queue.poll();
					if (rec == null) {
						return null;
					}
					if (query != null && query.terminateEarlyNode(rec.getBounds())) {
						return null;
					}
					if (rec instanceof DBTreeDataRecord) {
						@SuppressWarnings("unchecked")
						DR dr = (DR) rec;
						if (query != null && !query.testData(dr.getShape())) {
							continue;
						}
						return dr;
					}
					assert rec instanceof DBTreeNodeRecord;
					@SuppressWarnings("unchecked")
					NR nr = (NR) rec;
					if (query != null && query.testNode(nr.getShape()) != QueryInclusion.NONE) {
						descend(nr);
					}
					continue;
				}
			}

			@Override
			public boolean hasNext() {
				checkSoughtNext();
				return next != null;
			}

			@Override
			public DR peek() throws NoSuchElementException {
				checkSoughtNext();
				if (next == null) {
					throw new NoSuchElementException();
				}
				return next;
			}

			@Override
			public DR next() {
				checkSoughtNext();
				soughtNext = false;
				return next;
			}
		};
	}
Called when a node is finished being visited.

This only applies to nodes into which the visitor descends. The visitor will finish a
node in one of three ways: 1) The node's children have all been visited. 2) The visitor
returned {@link VisitResult#TERMINATE} while visiting a descendant. 3) The visitor
returned {@link VisitResult#ASCEND} while visiting a child.

This method may return any result except {@link VisitResult#DESCEND}. If the visitor is
terminating, the return value of this method is ignored.

@param parent the parent of this node, or {@code null} when visiting the root
@param n the node currently being visited
@param inclusion the original inclusion of the query before descending
@return a directive for how the visitor should proceed
Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/spatial/AbstractConstraintsTree.java