private static void writeMetrics(Node node, PrintStream out) {
        Stack<Node> stack = new Stack<Node>();
        stack.push(node);
        int nodes = 0;
        int consumedStrings = 0;
        int bucketStrings = 0;
        int bucketSpace = 0;
        int nonEmptyBuckets = 0;
        int smallest = Integer.MAX_VALUE;
        int largest = Integer.MIN_VALUE;
        while (!stack.isEmpty()) {
            node = stack.pop();
            nodes++;
            for (char c = 0; c < ALPHABET; c++) {
                int count = node.size(c);
                if (count < 0) {
                    stack.push((Node) node.get(c));
                } else {
                    // Only consider non-empty buckets, as there will
                    // always be empty buckets.
                    if (count > 0) {
                        if (c == 0) {
                            int no_of_buckets = (count / THRESHOLDMINUSONE) + 1;
                            Object[] nb = (Object[]) node.get(c);
                            for (int k = 1; k <= no_of_buckets; k++) {
                                int no_elements_in_bucket;
                                if (k == no_of_buckets) {
                                    no_elements_in_bucket = count % THRESHOLDMINUSONE;
                                } else {
                                    no_elements_in_bucket = THRESHOLDMINUSONE;
                                }
                                bucketSpace += nb.length;
                                nb = (Object[]) nb[no_elements_in_bucket];
                            }
                            consumedStrings += count;
                        } else {
                            CharSequence[] cs = (CharSequence[]) node.get(c);
                            bucketSpace += cs.length;
                            bucketStrings += count;
                        }
                        if (count < smallest) {
                            smallest = count;
                        }
                        nonEmptyBuckets++;
                    }
                    if (count > largest) {
                        largest = count;
                    }
                }
            }
        }
        out.format("Trie nodes: %d\n", nodes);
        out.format("Total buckets: %d\n", nonEmptyBuckets);
        out.format("Bucket strings: %d\n", bucketStrings);
        out.format("Consumed strings: %d\n", consumedStrings);
        out.format("Smallest bucket: %d\n", smallest);
        out.format("Largest bucket: %d\n", largest);
        long sum = consumedStrings + bucketStrings;
        out.format("Average bucket: %d\n", sum / nonEmptyBuckets);
        out.format("Bucket capacity: %d\n", bucketSpace);
        double usage = ((double) sum * 100) / (double) bucketSpace;
        out.format("Usage ratio: %.2f\n", usage);
    }