default Optional<T> sharedAncestor(final T node) {
		requireNonNull(node);

		T ancestor = null;
		if (node.identical(this)) {
			ancestor = self();
		} else {
			final int level1 = level();
			final int level2 = node.level();

			T node1;
			T node2;
			int diff;
			if (level2 > level1) {
				diff = level2 - level1;
				node1 = node;
				node2 = self();
			} else {
				diff = level1 - level2;
				node1 = self();
				node2 = node;
			}

			while (diff > 0 && node1 != null) {
				node1 = node1.parent().orElse(null);
				--diff;
			}

			do {
				if (node1 != null && node1.identical(node2)) {
					ancestor = node1;
				}
				node1 = node1 != null
					? node1.parent().orElse(null)
					: null;
				node2 = node2.parent().orElse(null);
			} while (node1 != null && node2 != null && ancestor == null);
		}

		return Optional.ofNullable(ancestor);
	}
Returns the nearest common ancestor to this node and the given {@code node}.
A node is considered an ancestor of itself.

@param node {@code node} to find common ancestor with
@return nearest ancestor common to this node and the given {@code node},
        or {@link Optional#empty()} if no common ancestor exists.
@throws NullPointerException if the given {@code node} is {@code null}
jenetics.ext/src/main/java/io/jenetics/ext/util/Tree.java