Data::Omap

Perl module to implement ordered mappings
Download

Data::Omap Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Brad Baxter
  • Publisher web site:
  • http://search.cpan.org/~bbaxter/

Data::Omap Tags


Data::Omap Description

Perl module to implement ordered mappings Data::Omap is a Perl module that implements the Data::Omap class. Objects in this class are ordered mappings, i.e., they are hashes in which the key/value pairs are in order. This is defined in shorthand as !!omap in the YAML tag repository: http://yaml.org/type/omap.html.The keys in Data::Omap objects are unique, like regular hashes.A closely related class, Data::Pairs, implements the YAML !!pairs data type, http://yaml.org/type/pairs.html. Data::Pairs objects are also ordered sequences of key:value pairs but they allow duplicate keys.While ordered mappings are in order, they are not necessarily in a particular order, i.e., they are not necessarily sorted in any way. They simply have a predictable set order (unlike regular hashes whose key/value pairs are in no set order).By default, Data::Omap will add new key/value pairs at the end of the mapping, but you may request that they be merged in a particular order with the order() class method.However, even though Data::Omap will honor the requested order, it will not attempt to keep the mapping in that order. By passing position values to the set() and add() methods, you may insert new pairs anywhere in the mapping and Data::Omap will not complain.SYNOPSIS use Data::Omap; # Simple OO style my $omap = Data::Omap->new( ); $omap->set( a => 0 ); $omap->add( b2 => 2.5, 2 ); # insert at position 2 (between b and c) my $value = $omap->get_values( 'c' ); # 3 my @keys = $omap->get_keys(); # (a, b, b2, c) my @values = $omap->get_values(); # (0, 2, 2.5, 3) my @subset = $omap->get_values(qw(c b)); # (2, 3) (values are data-ordered) # Tied style my %omap; # recommend saving an object reference, too. my $omap = tie %omap, 'Data::Omap', ; $omap{ a } = 0; $omap->add( b2 => 2.5, 2 ); # there's no tied hash equivalent my $value = $omap{ c }; my @keys = keys %omap; # $omap->get_keys() is faster my @values = values %omap; # $omap->get_values() is faster my @slice = @omap{qw(c b)}; # (3, 2) (slice values are parameter-ordered) # Non-OO style use Data::Omap ':ALL'; my $omap = ; # new-ish, but not blessed omap_set( $omap, a => 0 ); # (pass omap as first parameter) omap_add( $omap, b2 => 2.5, 2 ); # insert at position 2 (between b and c) my $value = omap_get_values( $omap, 'c' ); # 3 my @keys = omap_get_keys( $omap ); # (a, b, b2, c) my @values = omap_get_values( $omap ); # (0, 2, 2.5, 3) my @subset = omap_get_values( $omap, qw(c b) ); # (2, 3) (values are data-ordered) Requirements: · Perl


Data::Omap Related Software