public static <V> FlatTreeNode<V> ofTree(final Tree<? extends V, ?> tree) {
		requireNonNull(tree);

		if (tree instanceof FlatTreeNode<?> ft && ft.isRoot()) {
			@SuppressWarnings("unchecked")
			final var result = (FlatTreeNode<V>)ft;
			return result;
		}

		final int size = tree.size();
		assert size >= 1;

		final var nodes = new Nodes(size);

		int childOffset = 1;
		int index = 0;

		for (var node : tree) {
			nodes.values[index] = node.value();
			nodes.childCounts[index] = node.childCount();
			nodes.childOffsets[index] = node.isLeaf() ? NULL_INDEX : childOffset;

			childOffset += node.childCount();
			++index;
		}
		assert index == size;

		return new FlatTreeNode<>(nodes);
	}
Create a new, immutable {@code FlatTreeNode} from the given {@code tree}.

@param tree the source tree
@param <V> the tree value types
@return a {@code FlatTreeNode} from the given {@code tree}
@throws NullPointerException if the given {@code tree} is {@code null}
jenetics.ext/src/main/java/io/jenetics/ext/util/FlatTreeNode.java