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

Object::KVC::Set - Set calculations on Object::KVC::Hash objects

SYNOPSIS

  use Object::KVC::Set;
  use Object::KVC::Hash;
  
  my $object_1 = Object::KVC::Hash->new();
  $object_1->set( "id", Object::KVC::String->new("id1234") );
  
  my $object_n = Object::KVC::Hash->new();    
  $object_n->set( "id", Object::KVC::String->new("id1234") );

  my $set1 = Object::KVC::Set->new();
  my $set2 = Object::KVC::Set->new();

  $set1->add( $object_1 );
  $set2->add( $object_n );

  my $intersection = $set1->intersection($set2);

  foreach my $object ( $intersection->iter() ) {
      print $object->get("id")->as_string() if ( $object->has_defined("id") );
      print "\n";
  }

DESCRIPTION

List based Set calculations on a set of Object::KVC::Hash objects.

METHODS

new()

The constructor.

  my $set = Object::KVC::Set->new();

No arguments.

add( <object> )

Add a new Object::KVC::Hash object to the Set.

  $set->add( $object ); 

iter()

Returns 'ARRAY' of the Set members.

  my @objects = $set->iter();

size()

Returns integer value of the Set cardinality.

  my $set_size = $set1->size();

equals( $set<Object::KVC::Set> )

Returns true if both sets are the same size and every object in this Set has an equal object in the other Set.

  $set1->equals($set2);

contains( $set<Object::KVC::Set> or $object<Object::KVC::Hash> )

Returns true if objects in this Set 'contains' every object in the other Set.

  $set1->contains( $set2 );

Returns true if an object in this Set 'contains' the other object.

  $set1->contains( $object );

includes( $set<Object::KVC::Set> or $other<Object::KVC::Hash> )

Returns true if objects in this Set 'matches' every object in the other Set.

  $set1->includes( $set2 );

Returns true if an object in this Set 'matches' the other object.

  $set1->includes( $object );

difference( $set<Object::KVC::Set> )

Returns a Set with the relative complement, which is the set of objects in self, but not in other.

  $set1->difference( $set2 );

disjoint( $set<Object::KVC::Set> )

Returns true if the Sets are disjoint.

  $set1->disjoint( $set2 );

intersects( $set<Object::KVC::Set> )

Returns true if the Sets intersect.

  $set1->intersects( $set2 );

intersection( $set<Object::KVC::Set> )

Returns a Set containing the objects which exist in both Sets.

  $intersection = $set1->intersection( $set2 );

union( $set<Object::KVC::Set> )

Returns a Set containing all the objects which exist in both Sets.

  $union = $set1->union( $set2 );

COPYRIGHT AND LICENSE

Object::KVC::Set Copyright (C) 2012 Trystan Johnson

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.