for (int i = 0; i < lengths.length - 1; i++) { for (int j = i + 1; j < lengths.length; j++) { if (lengths[j] < lengths[i] || (lengths[j] == lengths[i] && codeValues[j] < codeValues[i])) { int tmp; tmp = lengths[j]; lengths[j] = lengths[i]; lengths[i] = tmp; tmp = codeValues[j]; codeValues[j] = codeValues[i]; codeValues[i] = tmp;
int codeValuesTemp; for (int k = 0; k < 16; k++) { for (int h = incs[k], i = h; i < lengths.length; i++) { int v = lengths[i]; codeValuesTemp = codeValues[i]; int j = i; while (j >= h && (lengths[j - h] > v || (lengths[j - h] == v && codeValues[j - h] > codeValuesTemp))) { lengths[j] = lengths[j - h]; codeValues[j] = codeValues[j - h]; j -= h;
private void generateTable(int[] lengths) {	// Sort the values. Primary key is code size. Secondary key is value.	for (int i = 0; i < lengths.length - 1; i++) {		for (int j = i + 1; j < lengths.length; j++) {			if (lengths[j] < lengths[i]				|| (lengths[j] == lengths[i]				&& codeValues[j] < codeValues[i]))			{				int tmp;				tmp = lengths[j];				lengths[j] = lengths[i];				lengths[i] = tmp;				tmp = codeValues[j];				codeValues[j] = codeValues[i];				codeValues[i] = tmp;			}		}	}	// These values in these arrays correspond to the elements of the	// "values" array. The Huffman code for codeValues[N] is codes[N]	// and the length of the code is lengths[N].	int[] codes = new int[lengths.length];	int lastLength = 0;	int code = 0;	for (int i = 0; i < lengths.length; i++) {		while (lastLength != lengths[i]) {			lastLength++;			code <<= 1;		}		if (lastLength != 0) {			codes[i] = code;			code++;		}	}		int last = 0;	for (int i = 0; i < lengths.length; i++) {		if (last != lengths[i]) {			last = lengths[i];			codeLengthInfo[last - 1].baseIndex = i;			codeLengthInfo[last - 1].min = codes[i];		}		if (last != 0) codeLengthInfo[last - 1].max = codes[i];	}}