-
Notifications
You must be signed in to change notification settings - Fork 1
/
compressor.h
53 lines (41 loc) · 1.61 KB
/
compressor.h
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
#ifndef __COMPRESSOR_H__
#define __COMPRESSOR_H__
#include <iostream>
#include <string>
using namespace std;
class Encode
{
public:
Encode() {};
~Encode() {};
/* Compress:
----------------------------------------------------
Compress the source text into result.
This function is responsible for allocating result.
The caller is responsible for freeing result.
Compress returns the length of the result.
---------------------------------------------------- */
unsigned int Compress( const string &source, unsigned char *& result );
/* Decompress:
----------------------------------------------------
Decompress codedText with the given length into a
string. Returns the decoded text as a string.
Assumes codedText is not null, length > 0.
---------------------------------------------------- */
string Decompress( unsigned char * codedText, unsigned int length );
private:
/* SetBit:
----------------------------------------------------
Set the k-th bit of the unsigned char (data) to 1.
Assumes data is initially 0.
Examples:
SetBit( 0, data ) --> data = 0000 0001
SetBit( 1, data ) --> data = 0000 0010
SetBit( 2, data ) --> data = 0000 0100
---------------------------------------------------- */
void SetBit( unsigned int k, unsigned char * data )
{
(* data) |= ( 1 << k );
}
};
#endif