Solved

Compress data using C++

Posted on 2008-10-24
2
690 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

747 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

14 Experts available now in Live!

Get 1:1 Help Now