OK, this is similar to sebastiani's contest, except there are no rules on what type of compression you use. The target is a txt file in ascii format.
Best compression within a reasonable time limit wins.
Implement your compression as a function that accepts a pointer to a zero terminated string consisting of the entire text of War and Peace as input and a dereferenced pointer (pointer to a pointer) where it should place the output. The function must also return the number of bytes used in the output. Below is an example declaration -
Implement your decompressor as a function that takes a pointer to an array containing the compressed data, the size of the array, and returns a pointer to the decompressed output, which must be zero terminated. An example is below -Code:unsigned long abachler_compress(char* Input , unsigned char** Ouput);
Rules -Code:char* abachler_decompress(unsigned char* Input , unsigned long InputSize);
Must be written in C++, C code is fine as long as it compiles as C++.
No use of global variables.
No use of the file system.
All code must be yours, no use of 3rd party compression libraries or API calls.
If your function crashes the application for any reason you lose.
Inline assembly is fine as long as it does not jump outside the assembly block.
Runtime is limited to 1 hour maximum on a Pentium 4 3.2 GHz with HT and 2GB ram.
You may use threads.
All submissions must be made by 23:59CST (-6 GMT) on 9/30/2009
The following is the main() function that will test the application I highly suggest you use this exact code for testing as no modifications will be made to accommodate anyones code. -
Code:#include <malloc.h>
#include <stdio.h>
#define SIZE_OF_WAR_AND_PEACE 0 // will be actual size of the file
unsigned long abachler_compress(char* Input , unsigned char** Ouput);
char* abachler_decompress(unsigned char* Input , unsigned long InputSize);
int main(){
FILE* pFile = fopen("warandpeace.txt" , "r+b");
char* pRandomVariableName = (char*)malloc(SIZE_OF_WAR_AND_PEACE);
fread(pRandomVariableName , 1 , SIZE_OF_WAR_AND_PEACE , pFile);
fclose(pFile);
unsigned char* pCompressed;
unsigned long DataSize = abachler_compress(pRandomVariableName , &pCompressed);
// compressed data may be copied to a new array at this point
char* pDecompressed = abachler_decompress(pCompressed , DataSize);
return 0;
}