/// <summary>
                /// Runs next() through the entire terms dict,
                ///  computing aggregate statistics.
                /// </summary>
                public Stats ComputeBlockStats()
                {
                    Stats stats = new Stats(OuterInstance.OuterInstance.Segment, OuterInstance.fieldInfo.Name);
                    if (OuterInstance.Index != null)
                    {
                        stats.IndexNodeCount = OuterInstance.Index.NodeCount;
                        stats.IndexArcCount = OuterInstance.Index.ArcCount;
                        stats.IndexNumBytes = OuterInstance.Index.SizeInBytes();
                    }

                    CurrentFrame = StaticFrame;
                    FST<BytesRef>.Arc<BytesRef> arc;
                    if (OuterInstance.Index != null)
                    {
                        arc = OuterInstance.Index.GetFirstArc(Arcs[0]);
                        // Empty string prefix must have an output in the index!
                        Debug.Assert(arc.Final);
                    }
                    else
                    {
                        arc = null;
                    }

                    // Empty string prefix must have an output in the
                    // index!
                    CurrentFrame = PushFrame(arc, OuterInstance.RootCode, 0);
                    CurrentFrame.FpOrig = CurrentFrame.Fp;
                    CurrentFrame.LoadBlock();
                    ValidIndexPrefix = 0;

                    stats.StartBlock(CurrentFrame, !(CurrentFrame.IsLastInFloor));

                    while (true)
                    {
                        // Pop finished blocks
                        while (CurrentFrame.NextEnt == CurrentFrame.EntCount)
                        {
                            stats.EndBlock(CurrentFrame);
                            if (!CurrentFrame.IsLastInFloor)
                            {
                                CurrentFrame.LoadNextFloorBlock();
                                stats.StartBlock(CurrentFrame, true);
                            }
                            else
                            {
                                if (CurrentFrame.Ord == 0)
                                {
                                    goto allTermsBreak;
                                }
                                long lastFP = CurrentFrame.FpOrig;
                                CurrentFrame = Stack[CurrentFrame.Ord - 1];
                                Debug.Assert(lastFP == CurrentFrame.LastSubFP);
                                // if (DEBUG) {
                                //   System.out.println("  reset validIndexPrefix=" + validIndexPrefix);
                                // }
                            }
                        }

                        while (true)
                        {
                            if (CurrentFrame.Next())
                            {
                                // Push to new block:
                                CurrentFrame = PushFrame(null, CurrentFrame.LastSubFP, Term_Renamed.Length);
                                CurrentFrame.FpOrig = CurrentFrame.Fp;
                                // this is a "next" frame -- even if it's
                                // floor'd we must pretend it isn't so we don't
                                // try to scan to the right floor frame:
                                CurrentFrame.IsFloor = false;
                                //currentFrame.hasTerms = true;
                                CurrentFrame.LoadBlock();
                                stats.StartBlock(CurrentFrame, !CurrentFrame.IsLastInFloor);
                            }
                            else
                            {
                                stats.Term(Term_Renamed);
                                break;
                            }
                        }
                        //allTermsContinue:;
                    }
                allTermsBreak:

                    stats.Finish();

                    // Put root frame back:
                    CurrentFrame = StaticFrame;
                    if (OuterInstance.Index != null)
                    {
                        arc = OuterInstance.Index.GetFirstArc(Arcs[0]);
                        // Empty string prefix must have an output in the index!
                        Debug.Assert(arc.Final);
                    }
                    else
                    {
                        arc = null;
                    }
                    CurrentFrame = PushFrame(arc, OuterInstance.RootCode, 0);
                    CurrentFrame.Rewind();
                    CurrentFrame.LoadBlock();
                    ValidIndexPrefix = 0;
                    Term_Renamed.Length = 0;

                    return stats;
                }