in reply to Re^7: Producing a list of offsets efficiently
in thread Producing a list of offsets efficiently
Okay. Thanks for that.
assign undef to a spot that is twice as far ....
Is this better/prefereable to assigning to $#array?
For instance if you break the 400,000 array into building 400 arrays of 1000 elements that you then push together, you'll find the same amortized constant coming into play both in building 1000 element arrays and in building the 400,000 element array. So instead of eliminating that overhead, you're now paying twice the overhead!
That's where the AoA idea came up. Effectively making my index a two level affair and reducing the reallocations by only building (and probably preallocating) 400 arrays of 1000 elements rather than 1 of 400,000. The zeroth element of each of the 400 arrays would be an absolute value, but the other 999 would be relative to that base. Hence adjustments required to insert or delete affect (upto) 999 elements in the subarray affected + (upto) 400 absolute base values rather than 400,000 absolute values each time.
If performance is a problem it might save effort to have the data packed into a long string.
And that the final piece in the puzzle. packing the relative values into strings reduces the number of scalers by 3 orders. For most purposes, offsets (line lengths) can be packed into 8 bits reducing memory consuption further. By wrapping an exception eval around the packing and looking for "Character in 'C' format wrapped in pack" errors, I can detect if a line goes over 255 chars with the penalty of re-indexing to use 'n' if it happens. Ditto 'n' _> 'N'.
Moving to Inline:C or XS is an option if needed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Producing a list of offsets efficiently
by tilly (Archbishop) on May 30, 2005 at 07:53 UTC | |
by BrowserUk (Patriarch) on May 30, 2005 at 08:11 UTC |