in reply to Perl Drag Racing - sum/delta list

I'm probably missing something but it seems to me you are making life hard by calculating that running total or whatever it is?

Why not just store the original first value and the deltas?

#! perl -w use strict; sub decode { my $val; return map { $val += $_ } @_; } my @input = qw( 1000 1 -21 44 -1 ); my @output = decode @input; print "@output", $/; __END__ C:\test>190239 1000 1001 980 1024 1023

What's this about a "crooked mitre"? I'm good at woodwork!

Replies are listed 'Best First'.
Re: Re: Perl Drag Racing - sum/delta list
by John M. Dlugosz (Monsignor) on Aug 16, 2002 at 15:04 UTC
    Why? It's for a compression archive format. I'm renovating my design and have the following (re "solid packing of small files"):

    The total size of a packet is already known. (thus the total size). If this is a concatenation of subpackets, we need to know where to separate them back out. Instead of putting the length of the subpacket before each, it offers better compression to put this "index" data elsewhere and not "contaminate" the data with values that are not in its normal range. Also, there is an elegance factor of uniformity about putting this index in its own field, not mixed throughout.

    So, how to store the index? The delta-from-previous is smaller than a simple list of lengths, because it can use a shorter encoding form if the sizes are similar. But since the total size is already known, we only need the deltas of all except one, and can leave out one value.

    —John