Solved

Compress data using C++

Posted on 2008-10-24
2
702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server 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.

707 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