DDNet documentation
Loading...
Searching...
No Matches
huffman.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_SHARED_HUFFMAN_H
4#define ENGINE_SHARED_HUFFMAN_H
5
7{
8 enum
9 {
11
14
18 };
19
20 class CNode
21 {
22 public:
23 // symbol
24 unsigned m_Bits;
25 unsigned m_NumBits;
26
27 // don't use pointers for this. shorts are smaller so we can fit more data into the cache
28 unsigned short m_aLeaves[2];
29
30 // what the symbol represents
31 unsigned char m_Symbol;
32 };
33
34 static const unsigned ms_aFreqTable[HUFFMAN_MAX_SYMBOLS];
35
40
41 void SetBitsRecursive(CNode *pNode, int Bits, unsigned Depth);
42 void ConstructTree(const unsigned *pFrequencies);
43
44public:
45 /*
46 Function: Init
47 Inits the compressor/decompressor.
48
49 Remarks:
50 - Does no allocation whatsoever.
51 - You don't have to call any cleanup functions when you are done with it.
52 */
53 void Init();
54
55 /*
56 Function: Compress
57 Compresses a buffer and outputs a compressed buffer.
58
59 Parameters:
60 pInput - Buffer to compress
61 InputSize - Size of the buffer to compress
62 pOutput - Buffer to put the compressed data into
63 OutputSize - Size of the output buffer
64
65 Returns:
66 Returns the size of the compressed data. Negative value on failure.
67 */
68 int Compress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const;
69
70 /*
71 Function: Decompress
72 Decompresses a buffer
73
74 Parameters:
75 pInput - Buffer to decompress
76 InputSize - Size of the buffer to decompress
77 pOutput - Buffer to put the uncompressed data into
78 OutputSize - Size of the output buffer
79
80 Returns:
81 Returns the size of the uncompressed data. Negative value on failure.
82 */
83 int Decompress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const;
84};
85#endif // ENGINE_SHARED_HUFFMAN_H
Definition huffman.h:21
unsigned m_NumBits
Definition huffman.h:25
unsigned char m_Symbol
Definition huffman.h:31
unsigned short m_aLeaves[2]
Definition huffman.h:28
unsigned m_Bits
Definition huffman.h:24
Definition huffman.h:7
int m_NumNodes
Definition huffman.h:39
int Decompress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const
Definition huffman.cpp:210
static const unsigned ms_aFreqTable[HUFFMAN_MAX_SYMBOLS]
Definition huffman.h:10
CNode * m_pStartNode
Definition huffman.h:38
void ConstructTree(const unsigned *pFrequencies)
Definition huffman.cpp:51
CNode m_aNodes[HUFFMAN_MAX_NODES]
Definition huffman.h:36
int Compress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const
Definition huffman.cpp:129
void Init()
Definition huffman.cpp:94
CNode * m_apDecodeLut[HUFFMAN_LUTSIZE]
Definition huffman.h:37
@ HUFFMAN_LUTMASK
Definition huffman.h:17
@ HUFFMAN_MAX_NODES
Definition huffman.h:13
@ HUFFMAN_LUTBITS
Definition huffman.h:15
@ HUFFMAN_LUTSIZE
Definition huffman.h:16
@ HUFFMAN_MAX_SYMBOLS
Definition huffman.h:12
@ HUFFMAN_EOF_SYMBOL
Definition huffman.h:10
void SetBitsRecursive(CNode *pNode, int Bits, unsigned Depth)
Definition huffman.cpp:37