Hello,

I need an implementation of a sparse array. If the searched key/index does not exist, it needs to return the immediately higher and immediately lower keys/indexes. I also need it to be able to nest to any depth.

I am trying to implement this using a hash coupled with an array containing the keys in sorted order. This can then be packaged as a tied array. I also want to get clever with the search on the hash keys stored in the array. Provision for a user-defined subroutine to return interpolated values is also possible.

But I am wondering if someone has not written something like it already. CPAN searches have failed so far.

Any comments on ways to improve my implementation will also be greatly appreciated.

Thanks

----

(Please YELL if updating the original post is not the done thing.)

Thanks everyone - much food for thought and some very interesting modules.

I will take GrandFather's advice and post the code when ready. For now, I am updating just to state the motivation for the effort.

The original thought was to create a structure for storage and querying of large data sets from experiments having multiple input variables and a single result from each run. The input variables could be reals, integers or even strings(to accommodate categories). For now, I am presuming the output to be a real.

Not only should we be able to return results for the previously loaded combinations(like any db can) but, once 'enough' data is fed in, we should also return approximate results for combinations with intermediate values (for numeric variables) through interpolation.

One can use simple linear interpolation, allow the user to supply some subroutine based on her/his knowledge of the data or get fancy w/ non-linear regression, even try to derive an equation from the data.

But fancy for later. Just the data structure for now.


In reply to Sparse Array by rajaguha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.