public void Compact() { min = (check.Length - alphabetSize) / 2; max = min; //$TODO: Sort the states in size order. The hope is that smaller states // will fit in the gaps between the big ones. for (int i = 0; i != states.Length; ++i) { FitState(i); } // Start with min and end with max: int pre = states.Length * alphabetSize; int post = (max - min) * 2 + states.Length; Debug.WriteLine("table would have been: " + pre); Debug.WriteLine("table is now: " + post + ", (" + post * 100.0 / (double) pre + "%)"); restates = new Regexp.State[basePos.Length]; for (int i = 0; i < basePos.Length; ++i) { restates[i] = new Regexp.State(); restates[i].BasePosition = basePos[i] - min; restates[i].Accepts = states[i].Accepts; Debug.WriteLine( string.Format( "s{0}{1} base:{2}", i, restates[i].Accepts?" (acc)":"", restates[i].BasePosition)); } int [] checkNew = new int[max-min]; int [] nextNew = new int[max-min]; for (int j = 0, i = min; i < max; ++i, ++j) { checkNew[j] = check[i]; nextNew[j] = next[i]; } check = checkNew; next = nextNew; }