-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuff.c
88 lines (77 loc) · 1.6 KB
/
huff.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char data_t;
typedef enum {
LEAF,
INTERNAL,
PARENT,
EMPTY
} status_t;
typedef enum {
FIND_i,
FIND_j,
COMBINE
} stage_t;
typedef struct {
data_t data;
unsigned int count;
status_t status : 8;
} bucket_t;
int main(int argc, char* argv[]){
return 0;
}
//assumption:
//function in put is pointer to a bukect_t array with number of elements
//bucket_t contains data, and sorted count, with status set to leaf node
//return is pointer to an array of node leaf depth (corresponding to bitcode length)
//buckets is assume to be B = [0,1,..,n-1]. where n elements is stored.
bucket_t* encode(bucket_t* buckets, size_t n){
assert(n >= 2);
/* find smallest value as B[i] */
stage_t stage = FIND_i;
unsigned int i = 0;
unsigned int j = 0;
unsigned int probe = 1;
while(probe) <= n-2){
/* linear search i */
if(stage == FIND_i){
/* update candidate i */
if(buckets[i].count > buckets[probe].count){
i = probe;
probe++;
}
/* found i */
else if(buckets[probe].count > buckets[i].count){
stage = FIND_j;
probe = j;
}
/* */
else {
continue;
}
}
/* linear search j */
if(stage == FIND_j){
/* skip i */
if(probe == i || buckets[probe].status == EMPTY){
probe++;
}
/* update candidate j */
else if(buckets[j].count > buckets[probe].count){
j = probe;
probe++;
}
/* found j */
else if(buckets[probe].count > buckets[j].count){
stage = FIND_i;
stage = combine(buckets, i, j);
}
else {
continue;
}
}
}
return;
}
combine(bucket_t* val1, bucket_t* val2){
}