44
44
{ bits-=(bit+1); break; } \
47
/* Size in uint16 of a Huffman tree for byte compression of 256 byte values. */
47
/* Size in uint16_t of a Huffman tree for byte compression of 256 byte values. */
48
48
#define OFFSET_TABLE_SIZE 512
50
50
static uint read_huff_table(MI_BIT_BUFF *bit_buff,MI_DECODE_TREE *decode_tree,
51
uint16 **decode_table,uchar **intervall_buff,
53
static void make_quick_table(uint16 *to_table,uint16 *decode_table,
51
uint16_t **decode_table,uchar **intervall_buff,
53
static void make_quick_table(uint16_t *to_table,uint16_t *decode_table,
54
54
uint *next_free,uint value,uint bits,
56
static void fill_quick_table(uint16 *table,uint bits, uint max_bits,
56
static void fill_quick_table(uint16_t *table,uint bits, uint max_bits,
58
static uint copy_decode_table(uint16 *to_pos,uint offset,
59
uint16 *decode_table);
60
static uint find_longest_bitstream(uint16 *table, uint16 *end);
58
static uint copy_decode_table(uint16_t *to_pos,uint offset,
59
uint16_t *decode_table);
60
static uint find_longest_bitstream(uint16_t *table, uint16_t *end);
61
61
static void (*get_unpack_function(MI_COLUMNDEF *rec))(MI_COLUMNDEF *field,
136
136
uint i,trees,huff_tree_bits,rec_reflength,length;
137
uint16 *decode_table,*tmp_buff;
137
uint16_t *decode_table,*tmp_buff;
138
138
ulong elements,intervall_length;
139
139
uchar *disk_cache;
140
140
uchar *intervall_buff;
198
198
This segment will be reallocated after construction of the tables.
200
200
length=(uint) (elements*2+trees*(1 << myisam_quick_table_bits));
201
if (!(share->decode_tables=(uint16*)
202
my_malloc((length + OFFSET_TABLE_SIZE) * sizeof(uint16) +
201
if (!(share->decode_tables=(uint16_t*)
202
my_malloc((length + OFFSET_TABLE_SIZE) * sizeof(uint16_t) +
203
203
(uint) (share->pack.header_length - sizeof(header)),
204
204
MYF(MY_WME | MY_ZEROFILL))))
235
235
&intervall_buff,tmp_buff))
237
237
/* Reallocate the decoding tables to the used size. */
238
decode_table=(uint16*)
238
decode_table=(uint16_t*)
239
239
my_realloc((uchar*) share->decode_tables,
240
240
(uint) ((uchar*) decode_table - (uchar*) share->decode_tables),
241
241
MYF(MY_HOLD_ON_ERROR));
245
245
share->decode_tables=decode_table;
246
246
for (i=0 ; i < trees ; i++)
247
247
share->decode_trees[i].table=ADD_TO_PTR(share->decode_trees[i].table,
251
251
/* Fix record-ref-length for keys */
254
254
for (i=0 ; i < share->base.keys ; i++)
256
256
MI_KEYDEF *keyinfo= &share->keyinfo[i];
257
keyinfo->keylength+= (uint16) diff_length;
258
keyinfo->minlength+= (uint16) diff_length;
259
keyinfo->maxlength+= (uint16) diff_length;
260
keyinfo->seg[keyinfo->keysegs].length= (uint16) rec_reflength;
257
keyinfo->keylength+= (uint16_t) diff_length;
258
keyinfo->minlength+= (uint16_t) diff_length;
259
keyinfo->maxlength+= (uint16_t) diff_length;
260
keyinfo->seg[keyinfo->keysegs].length= (uint16_t) rec_reflength;
262
262
if (share->ft2_keyinfo.seg)
264
264
MI_KEYDEF *ft2_keyinfo= &share->ft2_keyinfo;
265
ft2_keyinfo->keylength+= (uint16) diff_length;
266
ft2_keyinfo->minlength+= (uint16) diff_length;
267
ft2_keyinfo->maxlength+= (uint16) diff_length;
265
ft2_keyinfo->keylength+= (uint16_t) diff_length;
266
ft2_keyinfo->minlength+= (uint16_t) diff_length;
267
ft2_keyinfo->maxlength+= (uint16_t) diff_length;
305
305
static uint read_huff_table(MI_BIT_BUFF *bit_buff, MI_DECODE_TREE *decode_tree,
306
uint16 **decode_table, uchar **intervall_buff,
306
uint16_t **decode_table, uchar **intervall_buff,
309
309
uint min_chr,elements,char_bits,offset_bits,size,intervall_length,table_bits,
310
310
next_free_offset;
313
313
if (!get_bits(bit_buff,1))
342
342
if (get_bit(bit_buff))
344
*ptr= (uint16) get_bits(bit_buff,offset_bits);
344
*ptr= (uint16_t) get_bits(bit_buff,offset_bits);
345
345
if ((ptr + *ptr >= end) || !*ptr)
351
*ptr= (uint16) (IS_CHAR + (get_bits(bit_buff,char_bits) + min_chr));
351
*ptr= (uint16_t) (IS_CHAR + (get_bits(bit_buff,char_bits) + min_chr));
353
353
skip_to_next_byte(bit_buff);
431
static void make_quick_table(uint16 *to_table, uint16 *decode_table,
431
static void make_quick_table(uint16_t *to_table, uint16_t *decode_table,
432
432
uint *next_free_offset, uint value, uint bits,
442
442
Remaining left Huffman tree segment starts behind quick table.
443
443
Remaining right Huffman tree segment starts behind left segment.
445
to_table[value]= (uint16) *next_free_offset;
445
to_table[value]= (uint16_t) *next_free_offset;
447
447
Re-construct the remaining Huffman tree segment at
448
448
next_free_offset in to_table.
519
static void fill_quick_table(uint16 *table, uint bits, uint max_bits,
519
static void fill_quick_table(uint16_t *table, uint bits, uint max_bits,
525
525
Bits 1..8 of value represent the decoded byte value.
552
552
next free offset from to_pos.
555
static uint copy_decode_table(uint16 *to_pos, uint offset,
556
uint16 *decode_table)
555
static uint copy_decode_table(uint16_t *to_pos, uint offset,
556
uint16_t *decode_table)
558
558
uint prev_offset= offset;
578
578
if (!(*decode_table & IS_CHAR))
580
580
/* Set a pointer to the next free target node. */
581
to_pos[prev_offset+1]=(uint16) (offset-prev_offset-1);
581
to_pos[prev_offset+1]=(uint16_t) (offset-prev_offset-1);
582
582
/* Copy the right hand subtree to the entry of that node. */
583
583
offset=copy_decode_table(to_pos,offset,decode_table+ *decode_table);
615
615
>= OFFSET_TABLE_SIZE Error, broken tree. It does not end before 'end'.
618
static uint find_longest_bitstream(uint16 *table, uint16 *end)
618
static uint find_longest_bitstream(uint16_t *table, uint16_t *end)
623
623
if (!(*table & IS_CHAR))
625
uint16 *next= table + *table;
625
uint16_t *next= table + *table;
626
626
if (next > end || next == table)
628
628
return OFFSET_TABLE_SIZE;
771
771
uchar *to, uchar *end)
773
773
if (get_bit(bit_buff))
774
bzero((char*) to,(uint) (end-to));
774
memset((char*) to, 0, (uint) (end-to));
777
777
end-=rec->space_length_bits;
778
778
decode_bytes(rec,bit_buff,to,end);
779
bzero((char*) end,rec->space_length_bits);
779
memset((char*) end, 0, rec->space_length_bits);
786
786
if (get_bit(bit_buff))
787
bzero((char*) to,(uint) (end-to));
787
memset((char*) to, 0, (uint) (end-to));
789
789
decode_bytes(rec,bit_buff,to,end);
795
795
if (get_bit(bit_buff))
796
bfill((uchar*) to,(end-to),' ');
796
memset((uchar*) to, ' ', (end-to));
798
798
decode_bytes(rec,bit_buff,to,end);
816
816
if (to+spaces != end)
817
817
decode_bytes(rec,bit_buff,to,end-spaces);
818
bfill((uchar*) end-spaces,spaces,' ');
818
memset((uchar*) end-spaces, ' ', spaces);
821
821
decode_bytes(rec,bit_buff,to,end);
836
836
if (to+spaces != end)
837
837
decode_bytes(rec,bit_buff,to,end-spaces);
838
bfill((uchar*) end-spaces,spaces,' ');
838
memset((uchar*) end-spaces, ' ', spaces);
841
841
decode_bytes(rec,bit_buff,to,end);
848
848
if (get_bit(bit_buff))
849
bfill((uchar*) to,(end-to),' ');
849
memset((uchar*) to, ' ', (end-to));
852
852
if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
857
857
if (to+spaces != end)
858
858
decode_bytes(rec,bit_buff,to,end-spaces);
859
bfill((uchar*) end-spaces,spaces,' ');
859
memset((uchar*) end-spaces, ' ', spaces);
872
872
if (to+spaces != end)
873
873
decode_bytes(rec,bit_buff,to,end-spaces);
874
bfill((uchar*) end-spaces,spaces,' ');
874
memset((uchar*) end-spaces, ' ', spaces);
877
877
static void uf_space_prespace_selected(MI_COLUMNDEF *rec, MI_BIT_BUFF *bit_buff,
889
889
bit_buff->error=1;
892
bfill((uchar*) to,spaces,' ');
892
memset((uchar*) to, ' ', spaces);
893
893
if (to+spaces != end)
894
894
decode_bytes(rec,bit_buff,to+spaces,end);
910
910
bit_buff->error=1;
913
bfill((uchar*) to,spaces,' ');
913
memset((uchar*) to, ' ', spaces);
914
914
if (to+spaces != end)
915
915
decode_bytes(rec,bit_buff,to+spaces,end);
926
926
if (get_bit(bit_buff))
927
bfill((uchar*) to,(end-to),' ');
927
memset((uchar*) to, ' ', (end-to));
930
930
if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
932
932
bit_buff->error=1;
935
bfill((uchar*) to,spaces,' ');
935
memset((uchar*) to, ' ', spaces);
936
936
if (to+spaces != end)
937
937
decode_bytes(rec,bit_buff,to+spaces,end);
947
947
bit_buff->error=1;
950
bfill((uchar*) to,spaces,' ');
950
memset((uchar*) to, ' ', spaces);
951
951
if (to+spaces != end)
952
952
decode_bytes(rec,bit_buff,to+spaces,end);
958
958
end-=rec->space_length_bits;
959
959
decode_bytes(rec,bit_buff,(uchar*) to,end);
960
bzero((char*) end,rec->space_length_bits);
960
memset((char*) end, 0, rec->space_length_bits);
963
963
static void uf_constant(MI_COLUMNDEF *rec,
983
983
MI_BIT_BUFF *bit_buff __attribute__((unused)),
984
984
uchar *to, uchar *end)
986
bzero((char*) to,(uint) (end-to));
986
memset((char*) to, 0, (uint) (end-to));
989
989
static void uf_blob(MI_COLUMNDEF *rec, MI_BIT_BUFF *bit_buff,
990
990
uchar *to, uchar *end)
992
992
if (get_bit(bit_buff))
993
bzero((uchar*) to,(end-to));
993
memset((uchar*) to, 0, (end-to));
996
996
ulong length=get_bits(bit_buff,rec->space_length_bits);
998
998
if (bit_buff->blob_pos+length > bit_buff->blob_end)
1000
1000
bit_buff->error=1;
1001
bzero((uchar*) to,(end-to));
1001
memset((uchar*) to, 0, (end-to));
1004
1004
decode_bytes(rec,bit_buff,bit_buff->blob_pos,bit_buff->blob_pos+length);
1005
1005
_my_store_blob_length((uchar*) to,pack_length,length);
1006
memcpy_fixed((char*) to+pack_length,(char*) &bit_buff->blob_pos,
1006
memcpy((char*) to+pack_length,(char*) &bit_buff->blob_pos,
1008
1008
bit_buff->blob_pos+=length;