The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::Hash::Interpolate - tied mathematical interpolation/extrapolation

SYNOPSIS

   use Tie::Hash::Interpolate;

   tie my %lut, 'Tie::Hash::Interpolate', extrapolate => 'linear';

   $lut{3} = 4;
   $lut{5} = 6;

   print $lut{4};  ## prints 5
   print $lut{6};  ## prints 7

DESCRIPTION

Tie::Hash::Interpolate provides a mechanism for using a hash as a lookup table for interpolated and extrapolated values.

After your hash is tied, insert your known key-value pairs. If you then fetch a value that is not a key, an interpolation or extrapolation will be performed as necessary.

OPTIONS

Options can be passed to tie after the Tie::Hash::Interpolate name is given. They are passed as key-value pairs. The supported options are:

extrapolate

   tie my %lut, 'Tie::Hash::Interpolate', extrapolate => 'fatal';

This option controls the behavior of the tied hash when a key is requested outside the range of known keys. Valid extrapolate values include:

  • linear (default)

    extrapolate linearly based on the two nearest points

  • constant

    keep the nearest value constant rather than extrapolating

  • fatal

    throw a fatal exception

  • undef

    return undef

TO DO

- support multiple dimenstions
- support autovivification of tied hashes
- set a per-instance mode for insertion or lookup
- be smarter (proximity based direction) about searching when doing interpolation

AUTHOR

Daniel B. Boorstein, <danboo@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2004 by Daniel B. Boorstein

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.