internal void scan_tree (short[] tree,// the tree to be scanned
int max_code // and its largest code of non zero frequency
){
int n; // iterates over all tree elements
int prevlen = -1; // last emitted length
int curlen; // length of current code
int nextlen = tree[0*2+1]; // length of next code
int count = 0; // repeat count of the current code
int max_count = 7; // max repeat count
int min_count = 4; // min repeat count
if (nextlen == 0){ max_count = 138; min_count = 3; }
tree[(max_code+1)*2+1] = -1; // guard
for(n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[(n+1)*2+1];
if(++count < max_count && curlen == nextlen) {
continue;
}
else if(count < min_count) {
bl_tree[curlen*2] += (short)count;
}
else if(curlen != 0) {
if(curlen != prevlen) bl_tree[curlen*2]++;
bl_tree[REP_3_6*2]++;
}
else if(count <= 10) {
bl_tree[REPZ_3_10*2]++;
}
else{
bl_tree[REPZ_11_138*2]++;
}
count = 0; prevlen = curlen;
if(nextlen == 0) {
max_count = 138; min_count = 3;
}
else if(curlen == nextlen) {
max_count = 6; min_count = 3;
}
else{
max_count = 7; min_count = 4;
}
}
}