in reply to Re^6: URL string compression?
in thread URL string compression?
Can you use a number for the subject code and the athor code? If you used the following packing:
Year 2 bytes (0..65535) subject code 2 bytes(?) (0..65535) author code 2 bytes(?) (0..65535) chemicals: 2 bytes per (0..65535)
That allows you to have up to 11 chemicals. It's possible to do better (by using bits which aren't an even number of bytes), but you lose efficiency.
If the above is ok, let me know and I'll code it tonight.
If the above is not sufficient, let me know more precise ranges for the year, the subject codes, the author codes and chemical codes.
Update: Promised code:
sub encode_base32 { ... based on encode_base64 ... } sub decode_base32 { ... based on decode_base64 ... } sub compress_data { my ($year, $subject, $author, @chemicals) = @_; carp(...) if $year < 0 || $year > 65535; carp(...) if $subject < 0 || $subject > 65535; carp(...) if $author < 0 || $author > 65535; carp(...) if @chemicals > 11; carp(...) if grep { $_ == 65535 } @chemicals; push(@chemicals, (65535)x(11-@chemicals)); return pack('n*', $year, $subject, $author, @chemicals); } sub decompress_data { my ($data) = @_; my ($year, $subject, $author, @chemicals) = unpack('n*', $data); @chemicals = grep { $_ != 65535 } @chemicals; return ($year, $subject, $author, @chemicals); } $file_name = encode_base32(compress_data(...)); (...) = decompress_data(decode_base32($file_name));
Untested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: URL string compression?
by BrowserUk (Patriarch) on Feb 14, 2006 at 02:50 UTC | |
by ikegami (Patriarch) on Feb 14, 2006 at 05:14 UTC |