1Set::Tiny(3)          User Contributed Perl Documentation         Set::Tiny(3)
2
3
4

NAME

6       Set::Tiny - Simple sets of strings
7

VERSION

9       Version 0.04
10

SYNOPSIS

12           use Set::Tiny;
13
14           my $s1 = Set::Tiny->new(qw( a b c ));
15           my $s2 = Set::Tiny->new(qw( b c d ));
16
17           my $u  = $s1->union($s2);
18           my $i  = $s1->intersection($s2);
19           my $s  = $s1->symmetric_difference($s2);
20
21           print $u->as_string; # (a b c d)
22           print $i->as_string; # (b c)
23           print $s->as_string; # (a d)
24
25           print "i is a subset of s1"   if $i->is_subset($s1);
26           print "u is a superset of s1" if $u->is_superset($s1);
27
28           # or using the shorter initializer:
29
30           use Set::Tiny qw( set );
31
32           my $s1 = set(qw( a b c ));
33           my $s2 = set([1, 2, 3]);
34

DESCRIPTION

36       Set::Tiny is a thin wrapper around regular Perl hashes to perform often
37       needed set operations, such as testing two sets of strings for
38       equality, or checking whether one is contained within the other.
39
40       For a more complete implementation of mathematical set theory, see
41       Set::Scalar. For sets of arbitrary objects, see Set::Object.
42
43   Why Set::Tiny?
44       Convenience
45           Set::Tiny aims to provide a convenient interface to commonly used
46           set operations, which you would usually implement using regular
47           hashes and a couple of "for" loops (in fact, that's exactly what
48           Set::Tiny does).
49
50       Speed
51           The price in performance you pay for this convenience when using a
52           full-featured set implementation like Set::Scalar is way too high
53           if you don't actually need the advanced functionality it offers.
54           Run examples/benchmark.pl for a (non-representative) comparison
55           between different "Set::" modules.
56
57       Ease of use
58           Set::Object offers better performance than Set::Scalar, but needs a
59           C compiler to install. Set::Tiny has no dependencies and contains
60           no C code.
61

EXPORTABLE FUNCTIONS

63   set( [list or arrayref] )
64       If you request it, Set::Tiny can export a function "set()", which lets
65       you create a Set::Tiny instance in a more compact form.
66
67       Unlike the constructor, this function also accepts the set elements as
68       an array reference.
69
70       If you pass an existing Set::Tiny to the initializer, it creates a
71       clone of the set and returns that.
72

METHODS

74       Note that all methods that expect a list of set elements stringify
75       their arguments before inserting them into the set.
76
77   new( [list] )
78       Class method. Returns a new Set::Tiny object, initialized with the
79       strings in list, or the empty set if list is empty.
80
81   clone
82   copy
83       Returns a new set with the same elements as this one.
84
85   insert( [list] )
86       Inserts the elements in list into the set.
87
88   delete( [list] )
89   remove( [list] )
90       Removes the elements in list from the set. Elements that are not
91       members of the set are ignored.
92
93   invert( [list] )
94       For each element in list, if it is already a member of the set, deletes
95       it from the set, else insert it into the set.
96
97   clear
98       Removes all elements from the set.
99
100   as_string
101       Returns a string representation of the set.
102
103   elements
104   members
105       Returns the (unordered) list of elements.
106
107   size
108       Returns the number of elements.
109
110   has( [list] )
111   contains( [list] )
112       Returns true if all of the elements in list are members of the set. If
113       list is empty, returns true.
114
115   element( [string] )
116   member( [string] )
117       Returns the string if it is contained in the set.
118
119   is_null
120   is_empty
121       Returns true if the set is the empty set.
122
123   union( set )
124       Returns a new set containing both the elements of this set and set.
125
126   intersection( set )
127       Returns a new set containing the elements that are present in both this
128       set and set.
129
130   intersection2( set )
131       Like "intersection()", but orders the sets by size before comparing
132       their elements. This results in a small overhead for small, evenly
133       sized sets, but a large speedup when comparing bigger (~ 100 elements)
134       and very unevenly sized sets.
135
136   difference( set )
137       Returns a new set containing the elements of this set with the elements
138       of set removed.
139
140   unique( set )
141   symmetric_difference( set )
142       Returns a new set containing the elements that are present in either
143       this set or set, but not in both.
144
145   is_equal( set )
146       Returns true if this set contains the same elements as set.
147
148   is_disjoint( set )
149       Returns true if this set has no elements in common with set. Note that
150       the empty set is disjoint to any other set.
151
152   is_properly_intersecting( set )
153       Returns true if this set has elements in common with set, but both also
154       contain elements that they have not in common with each other.
155
156   is_proper_subset( set )
157       Returns true if this set is a proper subset of set.
158
159   is_proper_superset( set )
160       Returns true if this set is a proper superset of set.
161
162   is_subset( set )
163       Returns true if this set is a subset of set.
164
165   is_superset( set )
166       Returns true if this set is a superset of set.
167

AUTHOR

169       Stanis Trendelenburg, "<trendels at cpan.org>"
170

CREDITS

172       Thanks to Adam Kennedy for advice on how to make this module "Tiny".
173

BUGS

175       Please report any bugs or feature requests to "bug-set-tiny at
176       rt.cpan.org", or through the web interface at
177       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Set-Tiny>.  I will be
178       notified, and then you'll automatically be notified of progress on your
179       bug as I make changes.
180
182       Copyright 2009 Stanis Trendelenburg, all rights reserved.
183
184       This program is free software; you can redistribute it and/or modify it
185       under the same terms as Perl itself.
186

SEE ALSO

188       Set::Scalar, Set::Object
189
190
191
192perl v5.28.0                      2016-03-04                      Set::Tiny(3)
Impressum