1 | /** |
---|
2 | * @file Huffman.h |
---|
3 | * @author Sheng Di |
---|
4 | * @date Aug., 2016 |
---|
5 | * @brief Header file for the exponential segment constructor. |
---|
6 | * (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
7 | * See COPYRIGHT in top-level directory. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef _Huffman_H |
---|
11 | #define _Huffman_H |
---|
12 | |
---|
13 | #ifdef __cplusplus |
---|
14 | extern "C" { |
---|
15 | #endif |
---|
16 | |
---|
17 | //Note: when changing the following settings, intvCapacity in sz.h should be changed as well. |
---|
18 | //#define allNodes 131072 |
---|
19 | //#define stateNum 65536 |
---|
20 | |
---|
21 | typedef struct node_t { |
---|
22 | struct node_t *left, *right; |
---|
23 | size_t freq; |
---|
24 | char t; //in_node:0; otherwise:1 |
---|
25 | unsigned int c; |
---|
26 | } *node; |
---|
27 | |
---|
28 | typedef struct HuffmanTree { |
---|
29 | int stateNum; |
---|
30 | int allNodes; |
---|
31 | struct node_t* pool; |
---|
32 | node *qqq, *qq; //the root node of the HuffmanTree is qq[1] |
---|
33 | int n_nodes; //n_nodes is for compression |
---|
34 | int qend; |
---|
35 | unsigned long **code; |
---|
36 | unsigned char *cout; |
---|
37 | int n_inode; //n_inode is for decompression |
---|
38 | } HuffmanTree; |
---|
39 | |
---|
40 | HuffmanTree* createHuffmanTree(int stateNum); |
---|
41 | HuffmanTree* createDefaultHuffmanTree(); |
---|
42 | |
---|
43 | node new_node(HuffmanTree *huffmanTree, size_t freq, unsigned int c, node a, node b); |
---|
44 | node new_node2(HuffmanTree *huffmanTree, unsigned int c, unsigned char t); |
---|
45 | void qinsert(HuffmanTree *huffmanTree, node n); |
---|
46 | node qremove(HuffmanTree *huffmanTree); |
---|
47 | void build_code(HuffmanTree *huffmanTree, node n, int len, unsigned long out1, unsigned long out2); |
---|
48 | void init(HuffmanTree *huffmanTree, int *s, size_t length); |
---|
49 | void encode(HuffmanTree *huffmanTree, int *s, size_t length, unsigned char *out, size_t *outSize); |
---|
50 | void decode(unsigned char *s, size_t targetLength, node t, int *out); |
---|
51 | void pad_tree_uchar(HuffmanTree* huffmanTree, unsigned char* L, unsigned char* R, unsigned int* C, unsigned char* t, unsigned int i, node root); |
---|
52 | void pad_tree_ushort(HuffmanTree* huffmanTree, unsigned short* L, unsigned short* R, unsigned int* C, unsigned char* t, unsigned int i, node root); |
---|
53 | void pad_tree_uint(HuffmanTree* huffmanTree, unsigned int* L, unsigned int* R, unsigned int* C, unsigned char* t, unsigned int i, node root); |
---|
54 | unsigned int convert_HuffTree_to_bytes_anyStates(HuffmanTree* huffmanTree, int nodeCount, unsigned char** out); |
---|
55 | void unpad_tree_uchar(HuffmanTree* huffmanTree, unsigned char* L, unsigned char* R, unsigned int* C, unsigned char *t, unsigned int i, node root); |
---|
56 | void unpad_tree_ushort(HuffmanTree* huffmanTree, unsigned short* L, unsigned short* R, unsigned int* C, unsigned char* t, unsigned int i, node root); |
---|
57 | void unpad_tree_uint(HuffmanTree* huffmanTree, unsigned int* L, unsigned int* R, unsigned int* C, unsigned char* t, unsigned int i, node root); |
---|
58 | node reconstruct_HuffTree_from_bytes_anyStates(HuffmanTree *huffmanTree, unsigned char* bytes, int nodeCount); |
---|
59 | |
---|
60 | void encode_withTree(HuffmanTree* huffmanTree, int *s, size_t length, unsigned char **out, size_t *outSize); |
---|
61 | void decode_withTree(HuffmanTree* huffmanTree, unsigned char *s, size_t targetLength, int *out); |
---|
62 | |
---|
63 | void SZ_ReleaseHuffman(HuffmanTree* huffmanTree); |
---|
64 | |
---|
65 | #ifdef __cplusplus |
---|
66 | } |
---|
67 | #endif |
---|
68 | |
---|
69 | #endif |
---|