0

I am writing a program in C for file compression. The method i am trying to use involves doing math on the file as if it were one long number. Can anyone recommend a bignum library that would not try to do all of that in ram, but rather let me do math with file pointers. any help would be appreciated, thanks in advance.

Mobius
  • 2,871
  • 1
  • 19
  • 29
  • 1
    Even assuming such a thing existed, how would you "compress" a number? Say I give you the number 3412533 decimal, what can you do with it? – Blindy Sep 05 '10 at 19:28
  • "doing math on the file as if it were one long number" sounds like a bad idea! What method is this? – Oliver Charlesworth Sep 05 '10 at 19:29
  • Not to mention that numbers drop leading zeroes that can be significant in binary files. – Blindy Sep 05 '10 at 19:30
  • Not to mention how many digits it will have for a 1MB file : D – rano Sep 05 '10 at 19:35
  • 2
    See http://en.wikipedia.org/wiki/Arithmetic_encoding -- what the OP wants to do is sensible and actually quite effective. – zwol Sep 05 '10 at 19:45
  • That still won't work with leading zeroes. – Blindy Sep 05 '10 at 20:00
  • @Blindy: Shouldn't be too hard. If one stores the file size separately it's trivial to get the original file. – Georg Schölly Sep 05 '10 at 20:04
  • 1
    @Zack: Right, but even arithmetic coding isn't going to require you to "do math" on the entire number in one go. – Oliver Charlesworth Sep 05 '10 at 20:18
  • the coding method is really my problem, if you want to know about that i can tell you, but i don't know if it works yet, and i want to test it on files. it requires doing huge math the answer of which is the original file. i could also write this library, i just didn't want to reproduce already existant libraries. – Mobius Sep 06 '10 at 09:57
  • I doubt such a thing exists. Perhaps you can adapt something like GMP to use memory-mapped files, I don't know. Depending on which "math" operations you want to do, such a thing will likely be hopelessly slow. Nevertheless, the GNU Multiprecision (GMP) library can use advanced techniques like FFT multiplication for really huge operands. If GMP is inadequate for you, you will likely have to write your own. – President James K. Polk Sep 06 '10 at 22:10
  • ok so i am writing it. Addition works!, now multiplication, can anyone give me any helpful ideas on how to calculate the overflow form long long unsigned a * long long unsigned b – Mobius Sep 22 '10 at 13:51

1 Answers1

1

I doubt such a library exists. You could try mmap()ing the files in memory and see if you can do it that way.

CAFxX
  • 28,060
  • 6
  • 41
  • 66