private void GenerateMTFValues()

in src/ICSharpCode.SharpZipLib/BZip2/BZip2OutputStream.cs [1715:1828]


		private void GenerateMTFValues()
		{
			char[] yy = new char[256];
			int i, j;
			char tmp;
			char tmp2;
			int zPend;
			int wr;
			int EOB;

			MakeMaps();
			EOB = nInUse + 1;

			for (i = 0; i <= EOB; i++)
			{
				mtfFreq[i] = 0;
			}

			wr = 0;
			zPend = 0;
			for (i = 0; i < nInUse; i++)
			{
				yy[i] = (char)i;
			}

			for (i = 0; i <= last; i++)
			{
				char ll_i;

				ll_i = unseqToSeq[block[zptr[i]]];

				j = 0;
				tmp = yy[j];
				while (ll_i != tmp)
				{
					j++;
					tmp2 = tmp;
					tmp = yy[j];
					yy[j] = tmp2;
				}
				yy[0] = tmp;

				if (j == 0)
				{
					zPend++;
				}
				else
				{
					if (zPend > 0)
					{
						zPend--;
						while (true)
						{
							switch (zPend % 2)
							{
								case 0:
									szptr[wr] = (short)BZip2Constants.RunA;
									wr++;
									mtfFreq[BZip2Constants.RunA]++;
									break;

								case 1:
									szptr[wr] = (short)BZip2Constants.RunB;
									wr++;
									mtfFreq[BZip2Constants.RunB]++;
									break;
							}
							if (zPend < 2)
							{
								break;
							}
							zPend = (zPend - 2) / 2;
						}
						zPend = 0;
					}
					szptr[wr] = (short)(j + 1);
					wr++;
					mtfFreq[j + 1]++;
				}
			}

			if (zPend > 0)
			{
				zPend--;
				while (true)
				{
					switch (zPend % 2)
					{
						case 0:
							szptr[wr] = (short)BZip2Constants.RunA;
							wr++;
							mtfFreq[BZip2Constants.RunA]++;
							break;

						case 1:
							szptr[wr] = (short)BZip2Constants.RunB;
							wr++;
							mtfFreq[BZip2Constants.RunB]++;
							break;
					}
					if (zPend < 2)
					{
						break;
					}
					zPend = (zPend - 2) / 2;
				}
			}

			szptr[wr] = (short)EOB;
			wr++;
			mtfFreq[EOB]++;

			nMTF = wr;
		}