Solved

Compress data using C++

Posted on 2008-10-24
2
694 Views
Last Modified: 2013-12-14
Hi Experts,

I am new to C++ and need to come up with some sort of solution. Please see below:
The following data is a time series of integer values

int timeseries[32] = {67497, 67376, 67173, 67235, 67057, 67031, 66951,
66974, 67042, 67025, 66897, 67077, 67082, 67033, 67019, 67149, 67044, 67012,
67220, 67239, 66893, 66984, 66866, 66693, 66770, 66722, 66620, 66579, 66596,
66713, 66852, 66715};
 
The series might be, for example, the closing price of a stock each day over a 32 day period.

As stored above, the data will occupy 32 x sizeof(int) bytes = 128 bytes assuming 4 byte ints.

Using delta encoding  in need to write a function to compress, and a function to uncompress data like the above.
 
Can you help? Speedy response is very much appreciated!
0
Comment
Question by:motolanix1
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22797509
Homework?

since stock values use to have just little variations, you can calculate minimum value of all these, then calculate the deltas, so value can fit a 8 bits (1byte) or 16 bits variables (2bytes). Having determined the deltas and the required capacity, create an byte array with the required capacity plus five, by example:

compressed size = 32 x 2 + 5 = 69 bytes

then, at first byte, store the required capacity in bytes (1, 2 or 4), at the following 4-byte store the minimum value, and in the following byte the data itself.

0
 
LVL 11

Expert Comment

by:alexcohn
ID: 22806779
Many open source / free compression libraries are available. Maybe the simplest solution is described here: http://www.codeproject.com/KB/files/zip_utils.aspx.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now