Solved

Compress data using C++

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
populate value from mongo db in java 98 390
What xml editor to use. 8 101
Best free Visio Editor? 2 237
Unable to open debugger port in Intellij idea 6 465
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: …
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 columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

733 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