Solved

# Compress data using C++

Posted on 2008-10-24
Medium Priority
707 Views
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
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

LVL 55

Accepted Solution

Jaime Olivares earned 1500 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

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

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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
###### Suggested Courses
Course of the Month9 days, left to enroll