in reply to Re^2: Unpack Fail to Decompress String?
in thread Unpack Fail to Decompress String?

string length +1 modulo 4 is the same as the number of significant characters in the last byte. I.e. that is an implementation detail I left out on purpose.

If you mean comparision for equality, then putting the count into the first byte will be a lot faster for 75% of different-length strings and not much slower for same-length strings. Only if you want to know the first position at which they differ is the last byte better.

The advantage I see for last byte is that you can more easily append or cut from the end of the compressed string

  • Comment on Re^3: Unpack Fail to Decompress String?

Replies are listed 'Best First'.
Re^4: Unpack Fail to Decompress String?
by gone2015 (Deacon) on Jan 09, 2009 at 19:11 UTC

    Sure. If you're only interested in equality, then having the length component at the front will help -- unless the strings are generally the same length, in which case it makes things worse.

    For an "alphabetic" comparision the length is only significant if the strings are equal up to the end of shorter, so I reckon the trick is to put the length information at the far end.