Mike Wong > Table-ParentChild > Table::ParentChild

Download:
Table-ParentChild-0.05.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  

NAME ^

Table::ParentChild - Fast lookup for Parent-Child relationships

SYNOPSIS ^

  use Table::ParentChild;
  my $table = new Table::ParentChild( \@relationships );

  my @parents  = $table->parent_lookup( $child_id );
  my @children = $table->child_lookup( $parent_id );
  my $quantity = $table->quantity_lookup( $parent_id, $child_id );

  # Alternatively, given a $child_id...

  my $parent   = $table->parent_lookup( $child_id );
  my @parents  = keys %$parent;

  foreach my $parent_id ( @parents ) {
    my $quantity = $parent->{ $parent_id };
    print "There are $quantity $child_id in $parent_id\n";
  }

  # Or, given a $parent_id...

  my $child    = $table->child_lookup( $parent_id );
  my @children = keys %$child;

  foreach my $child_id ( @children ) {
    my $quantity = $child->{ $child_id };
    print "There are $quantity $child_id in $parent_id\n";
  }

DESCRIPTION ^

Table::ParentChild implements a cross-linked list in two dimensions. It is ideal for describing the parent-child relationships of large numbers of entities. For maximum speed, Table::ParentChild uses hashes to get access to the table row/column headers, and then traverses a linked- list written in XS. The emphasis of development was on speed first, small memory footprint second, ease-of-use third, and flexibility be damned :^)>.

To populate a table, simply build an array of arrays. The first element in the sub-array is the id of the parent. The second element of the sub-array is the id of the child. The third (and optional) element of the sub-array is the quantity. Table::ParentChild will automatically build appropriate headers for the table and populate the table, returning a table object for your lookup pleasure.

Be forewarned that ids are implemented as unsigned long integers and quantities are implemented as floating point values. The values you feed the table will be coerced into the appropriate data type, which may cause a failure in translation of the data.

EXPORT

AUTHOR ^

Mike Wong <mike_w3@pacbell.net>

Copyright (c) 2002, All Rights Reserved

This software is free software and may be redistributed and/or modified under the same terms as Perl itself.

SEE ALSO ^

perl(1).

syntax highlighting: