|XP is just a number|
Extendable pairwise indexes - prior work?by pjf (Curate)
|on Apr 02, 2007 at 04:37 UTC||Need Help??|
pjf has asked for the
wisdom of the Perl Monks concerning the following question:
Update: My original post read X < Y; this was incorrect, and has been corrected to X > Y.
G'day learned monks,
In some of my recent work I needed to develop a fast and compact way of encoding information between pairs of entries in an list, where the tail of that list may grow (but never shrink) over time, and the ordering of the list otherwise remains fixed.
The resulting encoding states that information about the pair (X,Y) is stored in location X(X-1)/2 + Y where X > Y, and indexes start from zero. In my case I'm using this to index bitstrings, but it's equally valid for use in arrays.
My trouble is that I know that this is not a new encoding scheme, since the most modest amount of thought on the subject reveals it as an answer. Unfortunately, I'm having a hard time finding its true name, and hence whether there is an existing module on the CPAN, or if this is a candidate for a CPAN release.
Please note that this is a rather academic question about finding correct attribution and prior work, not one about implementation.
Perl Training Australia