0

Possible Duplicate:
Text packing algorithm

The setup: I have a bunch of strings which should be put into an (one-dimensional) array, and which are accessed with an offset and a string length.

The problem: Find an algorithm to store those strings as efficiently as possible.

Example: Consider the three strings foo, foobar, and array. The most compact form would be foobarray: foo gets accessed with offset 0 and length 3 (0,3) , foobar with (0,6), and array with (4,5).

Note that the access of the array with offset and length is mandatory (this is actually the method how the data in the `name' table of an OpenType font is stored).

I'm quite sure that solutions already exist, but I'm probably missing the right keyword to find them in the internet.

Please advise.

Community
  • 1
  • 1
lemzwerg
  • 772
  • 7
  • 15
  • 4
    gzip has been around forever. – Chris Gessler Mar 17 '12 at 20:58
  • 1
    I think this is the same problem, and it has an answer: http://stackoverflow.com/questions/845324/text-packing-algorithm – Kevin Reid Mar 17 '12 at 21:14
  • gzip, huffman, etc... are all lossless compression methods. The compression asked for in here is lossy - so there *could* be an algorithm that perform better then these. – amit Mar 17 '12 at 21:15
  • Yep, that's it, thanks a lot! If I still have questions I'll do follow-ups in the other stackoverflow question thread. – lemzwerg Mar 17 '12 at 21:19

0 Answers0