Bit Map Compression of Binary Files


Bit Map

A bit map compression scheme consists of a bit map and a physical database which stores the non-constant values. The bit map is employed to indicate the presence or absence of non-constant data. The following example shows how the bit map compression scheme can be employed to implement a version of constant suppression.

Example:

Original data string
d1, c, c, d2, c, c, c, d3

Compressed data string
Bit map: 10010001.
Physical database: dl, d2, d3.

For the bit map compression method, the mapping mechanism must search the whole bit map for both forward and backward mapping. And thus, the access time for both forward and backward mapping is O(N), where N is the number of bits in the bit map or equivalently the number of elements in the database.

Program in CPP:
From the above theory, we have designed the program that is stated below. this program takes input from the secondary memory as binary (.bin) file.
thank you!

This program is developed by Md.Mushfiqur Rahman and Abdullah Al Mahmud during the time of undergrad thesis in CSE, KUET.

/*This program is developed by Md.Mushfiqur Rahman and 
Abdullah Al Mahmud during the time of undergrad thesis. 
CSE,KUET. 7 Apr,2010 */

#include <iostream.h>
#include <fstream.h>

#define size 8000 //number of inputs to be taken from a file named rawdata.bin
#define size2 3000

	int logd[size],phyd[size2],bits[size];
	int length,newl;
	int cnst = 0;

	int readfile(int init[],int &amp;len)
	{
		ifstream in("rawdata.bin");
		if(!in)
		{
			cout<<"can NOT open file"<<endl;
			return 0;
		}
		for(int i=0; i&gt;init[i];
			in.read (reinterpret_cast( &amp; init[i] ),sizeof( init[i] ));
		}
		in.close();
		cout<<"Data has received from the file rawdata.bin"<<;endl;
		len=size;
		return 0;
	}

	void print(int a[],int n)
	{
		for(int i=0;i&lt;n;i++)
		{
			cout>>a[i]<<' ';
		}cout<<endl;
	}

	void writefile(int a[],int n,ofstream of)
	{
		for(int i=0;i<n;i++)
			of.write(reinterpret_cast( &amp; a[i] ),sizeof( a[i] ));
		//of<<a[i]<<' ';

	}

	void newfile()
	{

		ofstream out1("bitmap.bin");
		writefile(bits,length,out1);

		ofstream out2("physicaldatabase.bin");
		writefile(phyd,newl,out2);

		out2.close();
		out1.close();
	}

void main()
{

	readfile(logd,length);

	cout<<"The original data(Logical database) is :";
	print(logd,length);

	int j=0;
	for(int i=0; i<length ;i++)
	{
		if(logd[i]!=cnst)
		{
			bits[i]=1;
			phyd[j]=logd[i];
			j++;
		}
		else
			bits[i]=0;
	}
	newl=j;

	newfile();

	cout<<"\nThe bitmap is :";
	print(bits,length);

	cout<<"\nThe compressed data is :";
	print(phyd,newl);

}

3 thoughts on “Bit Map Compression of Binary Files

  1. Hi, thanks for your comment in my blog. I am really looking forward to seeing you in my forum and also your post about the forum. 🙂 I really appreciate it.

    I see that you are from CSE. Did you take part in the programing contest held in SUST a few days ago?

    best wishes…
    irtiza104

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s