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::TimeSeries - Convenient hash tyng for time series data.

SYNOPSIS

    use Tie::TimeSeries;

    # Using with tie()
    tie %data, 'Tie::TimeSeries';
    $data{ time() } = [ 0.14, 0.06, 0.01 ];

    %data = ();
    $data{1361970900} = 10;
    $data{1361971200} = 20;
    $data{1361971500} = 30;
    $,=',';
    print values %data;                 # 10,20,30

    $data{1361971050} = 5;
    print values %data;                 # 10,5,20,30

    # OO
    $data = Tie::TimeSeries->new(
        1361970900 => 10,
        1361971200 => 20,
        1361971500 => 30,
    );
    print $data->values();              # 10,20,30
    $data->store( 1361971050 => 15 );
    print $data->values();              # 15,20,30
    $data->store( 1361971800 => 40 );
    print $data->values();              # 15,20,30,40

DESCRIPTION

When using time series data like throughput, statistics or so, this module is convenient that key will be sorted automatically. And this also is able to provide instance for OO using.

STANDARD TIE HASH

There are standard interfaces usage with tie().

    tie %yourhash, 'Tie::TimeSeries' [, $time => $value [, ... ]]

On this way, use %yourhash as regular Perl hashes, but keys and values will be stored in order internally.

With several arguments given, initialization stores them. $time must be integer number. $value can be any type of scalar.

OBJECTIVE USAGE

This modules provides object instance and methods.

CONSTRUCTOR

    $tied = tie %yourhash, 'Tie::TimeSeries' [, $time => $value [, ... ]]
    $tied = Tie::TimeSeries->new( $time => $value [, ... ] );

Call method new() to get instance or get return value of tie().

METHODS

fetch()

Method fetch() will fetch a value bound specified key.

    $tied->fetch( $time [, ... ] );
    $tied->fetch( \@keys_array );

store()

Method store() will store keys of time and values to the object.

    $tied->store( $time => $value [, ... ] );
    $tied->store( \%pairs_hash );

delete()

Method delete() will remove key and value from the object.

    $tied->delete( $time [, ... ] );
    $tied->delete( \@keys_array );

And this method will return deleted value(s).

exists()

Method exists() returns boolean value.

    $tied->exists( $time );

keys()

Method keys() returns keys list of the object.

    $tied->keys();

values()

Method values() returns values list of the object.

    $tied->values();

iterate()

Method iterate() execute a routine for each keys and values.

    $tied->iterate(\&subroutine);

Given subroutine will call by iterator with two argument, key and value.

    # Iterator example
    $obj->iterate(sub {
        ($key, $val) = @_;
        $obj->{$key} = $val * 100;
    });

SEE ALSO

See <Tie::IxHash> - The great module brings many hints to this module.

AUTHOR

Takahiro Onodera, <ong at garakuta.net>

LICENSE AND COPYRIGHT

Copyright 2010 T.Onodera.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.