FP::HashSet - set operations for hash tables
use FP::Equal 'is_equal'; use FP::HashSet; # ":all"; my $A= array_to_hashset ["a","b","c"]; my $B= array_to_hashset ["a","c","d"]; is_equal hashset_to_array hashset_union($A,$B), ["a","b","c","d"]; is_equal hashset_to_array hashset_intersection($A,$B), ["a","c"]; is_equal hashset_to_array hashset_difference($A,$B), ["b"]; ok not hashset_is_subset($B,$A); ok hashset_is_subset(+{b=>1},$A); is hashset_size($A), 3; ok not hashset_empty($A); ok hashset_empty(+{}); #hashset_keys_unsorted($A) # ("a","b","c") or in another sort order; # *keys* not values, hence always strings. is_equal [hashset_keys ($A)], [("a","b","c")]; # (always sorted) # a la diff tool: is_equal hashset_diff($A,$B), +{ b=>"-", d=>"+" }; # to treat a hashset as a function: my $f= hashset_to_predicate ($A); ok $f->("a");
Hashsets are hash tables that are expected to have keys representing the values unambiguously (FP::Array::array_to_hashset will just use the stringification).
Note that hashset_to_array will use the *values* of the hashes, not the keys.
To install PXML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PXML
CPAN shell
perl -MCPAN -e shell install PXML
For more information on module installation, please visit the detailed CPAN module installation guide.