internal void send_tree (short[] tree,// the tree to be sent
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; }
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) {
do { send_code(curlen, bl_tree); } while (--count != 0);
}
else if(curlen != 0){
if(curlen != prevlen){
send_code(curlen, bl_tree); count--;
}
send_code(REP_3_6, bl_tree);
send_bits(count-3, 2);
}
else if(count <= 10){
send_code(REPZ_3_10, bl_tree);
send_bits(count-3, 3);
}
else{
send_code(REPZ_11_138, bl_tree);
send_bits(count-11, 7);
}
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;
}
}
}