DDNet documentation
Toggle main menu visibility
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
6
class
CHuffman
7
{
8
enum
9
{
10
HUFFMAN_EOF_SYMBOL
= 256,
11
12
HUFFMAN_MAX_SYMBOLS
=
HUFFMAN_EOF_SYMBOL
+ 1,
13
HUFFMAN_MAX_NODES
=
HUFFMAN_MAX_SYMBOLS
* 2 - 1,
14
15
HUFFMAN_LUTBITS
= 10,
16
HUFFMAN_LUTSIZE
= (1 <<
HUFFMAN_LUTBITS
),
17
HUFFMAN_LUTMASK
= (
HUFFMAN_LUTSIZE
- 1)
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
36
CNode
m_aNodes
[
HUFFMAN_MAX_NODES
];
37
CNode
*
m_apDecodeLut
[
HUFFMAN_LUTSIZE
];
38
CNode
*
m_pStartNode
;
39
int
m_NumNodes
;
40
41
void
SetBitsRecursive
(
CNode
*pNode,
int
Bits,
unsigned
Depth);
42
void
ConstructTree
(
const
unsigned
*pFrequencies);
43
44
public
:
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
CHuffman::CNode
Definition
huffman.h:21
CHuffman::CNode::m_NumBits
unsigned m_NumBits
Definition
huffman.h:25
CHuffman::CNode::m_Symbol
unsigned char m_Symbol
Definition
huffman.h:31
CHuffman::CNode::m_aLeaves
unsigned short m_aLeaves[2]
Definition
huffman.h:28
CHuffman::CNode::m_Bits
unsigned m_Bits
Definition
huffman.h:24
CHuffman
Definition
huffman.h:7
CHuffman::m_NumNodes
int m_NumNodes
Definition
huffman.h:39
CHuffman::Decompress
int Decompress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const
Definition
huffman.cpp:225
CHuffman::ms_aFreqTable
static const unsigned ms_aFreqTable[HUFFMAN_MAX_SYMBOLS]
Definition
huffman.h:11
CHuffman::m_pStartNode
CNode * m_pStartNode
Definition
huffman.h:38
CHuffman::ConstructTree
void ConstructTree(const unsigned *pFrequencies)
Definition
huffman.cpp:52
CHuffman::m_aNodes
CNode m_aNodes[HUFFMAN_MAX_NODES]
Definition
huffman.h:36
CHuffman::Compress
int Compress(const void *pInput, int InputSize, void *pOutput, int OutputSize) const
Definition
huffman.cpp:130
CHuffman::Init
void Init()
Definition
huffman.cpp:95
CHuffman::m_apDecodeLut
CNode * m_apDecodeLut[HUFFMAN_LUTSIZE]
Definition
huffman.h:37
CHuffman::HUFFMAN_LUTMASK
@ HUFFMAN_LUTMASK
Definition
huffman.h:17
CHuffman::HUFFMAN_MAX_NODES
@ HUFFMAN_MAX_NODES
Definition
huffman.h:13
CHuffman::HUFFMAN_LUTBITS
@ HUFFMAN_LUTBITS
Definition
huffman.h:15
CHuffman::HUFFMAN_LUTSIZE
@ HUFFMAN_LUTSIZE
Definition
huffman.h:16
CHuffman::HUFFMAN_MAX_SYMBOLS
@ HUFFMAN_MAX_SYMBOLS
Definition
huffman.h:12
CHuffman::HUFFMAN_EOF_SYMBOL
@ HUFFMAN_EOF_SYMBOL
Definition
huffman.h:10
CHuffman::SetBitsRecursive
void SetBitsRecursive(CNode *pNode, int Bits, unsigned Depth)
Definition
huffman.cpp:38
src
engine
shared
huffman.h
Generated by
1.18.0