Presents
FS Assignment 2
ENCODE
Blagwa
Intro
FS Assignment 2
ENCODE
By :
TA’S Notes :
2
Index
• Intro 2
• Index 3
• Problem Statement 4
• Overall System 6
• System Requirements 6
• UML 6
• How to Use 7
• Take care 7
• System under the microscope 8
• File Reader 8
• File Writer 9
• InBuf 10
• OutBuf 11
• File Statistics 12
• Huffman Encoding Tree Builder xx
• Huffman Encode xx
• Huffman Decode xx
• Some ideas along the way 13
• Bad 13
• Good .. BUT 13
3
Problem
Statement
To compress a file, you have to collect statistics for the file and
find whether it is more economical to code it using the fixed
code OR to use another Huffman code according to the new
statistics and store the code in the compressed file. Your output
is the compressed file, compression ratio and the code used to
compress the file. To display the code, it must be in the
following format:
Byte Original Code New Code
65 01000001 10001
66 01000010 101101
67 01000011 01000
4
Problem
Statement
5
Overall
System
Requirements
6
Overall
System
How To Use
Take Care
• That is a beta version with many bugs
• The program wasn’t tested sufficiently
• Big file take a lot of time
7
System Under
Microscope
File Reader
8
System Under
Microscope
File Writer
9
System Under
Microscope
InBuf
Class InBuf (An input bit like buffer) to accumilate data inside it
and retrieve from it bit by bit
parameters :
inputCharacterBuffer -> File Reader (character like
buffer) to read from the input file
bitsDataStorage -> unsigned character (data storage
for the bits) to accumulate the bits and
retrieve from bit by bit
Index -> integer (pointer) points to where is the next
bit to be retrieved from
Behaviors :
InBuf Constructor 1 =>
parameters -> Character pointer input file name
Actions ->Creates new File Reader and sets the
pointer index to the start
InBuf Constructor 2 =>
parameters -> File Reader in Pointer
Actions -> set inputCharacterBuffer to in and sets
the pointer index to the start
~InBuf Destructor =>
Actions -> deletes inputCharacterBuffer
readBit =>
Action -> if index points to the end => get new data f
rom file reader and reset the index pointer
Retrieve next bit
return -> boolean to indicate weather it read 1 or 0
10
System Under
Microscope
OutBuf
11
System Under
Microscope
File Statistics
FileStatistics
It is a class to count up the occurrences(probabilities)
for each character in the input file
Constructor
Allocate the memory for the 2 maps
Distructor
Deallocate the memory of the 2 maps
Some getters
print
print the statistics of each byte in the input file
printing format :
number => weight
Do the statistics
BY reading the file and incrementing the occurrences
of the data
12
Ideas along
the Way
BAD
13