Set::Tiny(3)
π NAME π
Set::Tiny β Simple sets of strings. This is the Set::Tiny(3) manual page, bestie, and it is lowkey iconic for staying tiny.
β¨ SYNOPSIS β¨
okay so here's the whole group-chat demo β literally copy-paste exact code:
use Set::Tiny;
my $s1 = Set::Tiny->new(qw( a b c ));
my $s2 = Set::Tiny->new(qw( b c d ));
my $u = $s1->union($s2);
my $i = $s1->intersection($s2);
my $s = $s1->symmetric_difference($s2);
print $u->as_string; # (a b c d)
print $i->as_string; # (b c)
print $s->as_string; # (a d)
print "i is a subset of s1" if $i->is_subset($s1);
print "u is a superset of s1" if $u->is_superset($s1);
# or using the shorter initializer:
use Set::Tiny qw( set );
my $s1 = set(qw( a b c ));
my $s2 = set([1, 2, 3]);
πΈ DESCRIPTION πΈ
Set::Tiny is a thin wrapper around regular Perl hashes to perform often needed set operations, such as testing two sets of strings for equality, or checking whether one is contained within the other. It's giving convenience without the whole full-featured-set-kingdom π
For a more complete implementation of mathematical set theory, see Set::Scalar. For sets of arbitrary objects, see Set::Object.
β¨ Why Set::Tiny? β¨
π Convenience
Set::Tiny aims to provide a convenient interface to commonly used set operations, which you would usually implement using regular hashes and a couple of for loops (in fact, that's exactly what Set::Tiny does). No cap.
π¦ Speed
The price in performance you pay for this convenience when using a full-featured set implementation like Set::Scalar is way too high if you don't actually need the advanced functionality it offers. Run examples/benchmark.pl for a (non-representative) comparison between different Set:: modules.
π Ease of use
Set::Object offers better performance than Set::Scalar, but needs a C compiler to install. Set::Tiny has no dependencies and contains no C code.
π EXPORTABLE FUNCTIONS π
π§ set( [list or arrayref] )
If you request it, Set::Tiny can export a function set(), which lets you create a Set::Tiny instance in a more compact form.
Unlike the constructor, this function also accepts the set elements as an array reference.
If you pass an existing Set::Tiny to the initializer, it creates a clone of the set and returns that.
π METHODS π
Note that all methods that expect a list of set elements stringify their arguments before inserting them into the set. Stringification said, periodt.
new( [list] )β Class method. Returns a newSet::Tinyobject, initialized with the strings in list, or the empty set if list is empty.clone,copyβ Returns a new set with the same elements as this one.insert( [list] )β Inserts the elements in list into the set.delete( [list] ),remove( [list] )β Removes the elements in list from the set. Elements that are not members of the set are ignored.invert( [list] )β For each element in list, if it is already a member of the set, deletes it from the set, else insert it into the set.clearβ Removes all elements from the set.as_stringβ Returns a string representation of the set.elements,membersβ Returns the (unordered) list of elements.sizeβ Returns the number of elements.has( [list] ),contains( [list] )β Returns true if all of the elements in list are members of the set. If list is empty, returns true.element( [string] ),member( [string] )β Returns the string if it is contained in the set.is_null,is_emptyβ Returns true if the set is the empty set.union( set )β Returns a new set containing both the elements of this set and set.intersection( set )β Returns a new set containing the elements that are present in both this set and set.intersection2( set )β Likeintersection(), but orders the sets by size before comparing their elements. This results in a small overhead for small, evenly sized sets, but a large speedup when comparing bigger (~ 100 elements) and very unevenly sized sets.difference( set )β Returns a new set containing the elements of this set with the elements of set removed.unique( set ),symmetric_difference( set )β Returns a new set containing the elements that are present in either this set or set, but not in both.is_equal( set )β Returns true if this set contains the same elements as set.is_disjoint( set )β Returns true if this set has no elements in common with set. Note that the empty set is disjoint to any other set.is_properly_intersecting( set )β Returns true if this set has elements in common with set, but both also contain elements that they have not in common with each other.is_proper_subset( set )β Returns true if this set is a proper subset of set.is_proper_superset( set )β Returns true if this set is a proper superset of set.is_subset( set )β Returns true if this set is a subset of set.is_superset( set )β Returns true if this set is a superset of set.
π AUTHOR π
Stanis Trendelenburg, <trendels at cpan.org> π«Ά
π CREDITS π
Thanks to Adam Kennedy for advice on how to make this module "Tiny".
π¦ SEE ALSO π¦
Set::Scalar
π BUGS π
Please report any bugs or feature requests on the bugtracker website <https://github.com/haarg/Set-Tiny/issues>.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
π CONTRIBUTORS π
Alberto Manuel BrandΓ£o SimΓ΅es <ambs@cpan.org>Alceu Rodrigues de Freitas Junior <glasswalk3r@yahoo.com.br>brian greenfield <briang@cpan.org>Graham Knop <haarg@haarg.org>Ricky Morse <remorse@mgh.harvard.edu>Stanis Trendelenburg <stanis.trendelenburg@gmail.com>
π AUTHOR π
Stanis Trendelenburg <trendels@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Stanis Trendelenburg.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π That's the wholeSet::Tiny(3)page, bestie β straight fromperl v5.42.0, dated2024-08-21. Now go make some tiny little sets slay. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Set-Tiny 0.60.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms