︙ | | | ︙ | |
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFOutOfMemoryException.h"
static struct of_huffman_tree *
newTree(void)
{
struct of_huffman_tree *tree;
tree = of_alloc(1, sizeof(*tree));
tree->leaves[0] = tree->leaves[1] = NULL;
tree->value = 0xFFFF;
return tree;
}
static void
|
|
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#import "OFOutOfMemoryException.h"
static struct of_huffman_tree *
newTree(void)
{
struct of_huffman_tree *tree;
tree = OFAllocMemory(1, sizeof(*tree));
tree->leaves[0] = tree->leaves[1] = NULL;
tree->value = 0xFFFF;
return tree;
}
static void
|
︙ | | | ︙ | |
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
uint_fast8_t maxBit = 0;
@try {
for (uint16_t i = 0; i < count; i++) {
uint_fast8_t length = lengths[i];
if OF_UNLIKELY (length > maxBit) {
lengthCount = of_realloc(lengthCount,
length + 1, sizeof(uint16_t));
nextCode = of_realloc(nextCode,
length + 1, sizeof(uint16_t));
for (uint_fast8_t j = maxBit + 1; j <= length;
j++) {
lengthCount[j] = 0;
nextCode[j] = 0;
}
|
|
|
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
uint_fast8_t maxBit = 0;
@try {
for (uint16_t i = 0; i < count; i++) {
uint_fast8_t length = lengths[i];
if OF_UNLIKELY (length > maxBit) {
lengthCount = OFResizeMemory(lengthCount,
length + 1, sizeof(uint16_t));
nextCode = OFResizeMemory(nextCode,
length + 1, sizeof(uint16_t));
for (uint_fast8_t j = maxBit + 1; j <= length;
j++) {
lengthCount[j] = 0;
nextCode[j] = 0;
}
|
︙ | | | ︙ | |
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
for (uint16_t i = 0; i <= maxCode; i++) {
uint8_t length = lengths[i];
if (length > 0)
insertTree(tree, nextCode[length]++, length, i);
}
} @finally {
free(lengthCount);
free(nextCode);
}
return tree;
}
struct of_huffman_tree *
of_huffman_tree_construct_single(uint16_t value)
|
|
|
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
for (uint16_t i = 0; i <= maxCode; i++) {
uint8_t length = lengths[i];
if (length > 0)
insertTree(tree, nextCode[length]++, length, i);
}
} @finally {
OFFreeMemory(lengthCount);
OFFreeMemory(nextCode);
}
return tree;
}
struct of_huffman_tree *
of_huffman_tree_construct_single(uint16_t value)
|
︙ | | | ︙ | |
122
123
124
125
126
127
128
129
130
|
void
of_huffman_tree_release(struct of_huffman_tree *tree)
{
for (uint_fast8_t i = 0; i < 2; i++)
if OF_LIKELY (tree->leaves[i] != NULL)
of_huffman_tree_release(tree->leaves[i]);
free(tree);
}
|
|
|
122
123
124
125
126
127
128
129
130
|
void
of_huffman_tree_release(struct of_huffman_tree *tree)
{
for (uint_fast8_t i = 0; i < 2; i++)
if OF_LIKELY (tree->leaves[i] != NULL)
of_huffman_tree_release(tree->leaves[i]);
OFFreeMemory(tree);
}
|