|
4 | 4 |
|
5 | 5 | =SUBTITLE Unordered collections of unique and weighted objects in Perl 6
|
6 | 6 |
|
| 7 | +=head1 Introduction |
| 8 | +
|
| 9 | +The six collection classes are L<Set|/type/Set>, L<SetHash|/typ[e/SetHash>, |
| 10 | +L<Bag|/type/Bag>, L<BagHash|/type/BagHash>, L<Mix|/type/Mix> and |
| 11 | +L<MixHash:/type/MixHash>. They all share similar semantics. |
| 12 | +
|
7 | 13 | In a nutshell, these classes hold, in general, unordered collections of
|
8 | 14 | objects, much like an L<object hash|hashmap#index-entry-object_hash>.
|
9 | 15 | The L<QuantHash|/type/QuantHash> role is the role that is implemented by all
|
10 | 16 | of these classes: therefore they are also referenced as C<QuantHash>es.
|
11 | 17 |
|
| 18 | +C<Set> and C<SetHash> also implement the L<Setty|/type/Setty> role, |
| 19 | +C<Bag> and C<BagHash> implement the L<Baggy|/type/Baggy> role, C<Mix> and |
| 20 | +C<MixHash> implement the L<Mixy|/type/Mixy> role (which itself implements |
| 21 | +the C<Baggy> role). |
| 22 | +
|
12 | 23 | Sets only consider if objects in the collection are present or not, bags can
|
13 | 24 | hold several objects of the same kind, and mixes also allow fractional (and
|
14 | 25 | negative) weights. The regular versions are immutable, the I<Hash> versions
|
15 | 26 | are mutable.
|
16 | 27 |
|
17 |
| -Let's elaborate on that. If you want to collect objects in a container buti |
18 |
| -you do not care about the order of these objects, Perl 6 provides the |
19 |
| -I<unordered> collection types L<Set|/type/Set>, |
20 |
| -L<SetHash|/type/SetHash>, L<Bag|/type/Bag>, L<BagHash|/type/BagHash>, |
21 |
| -L<Mix|/type/Mix>, and L<MixHash|/type/MixHash>. Being unordered, these |
22 |
| -containers can be more efficient than L<Lists|/type/List> for looking up |
| 28 | +Let's elaborate on that. If you want to collect objects in a container but |
| 29 | +you do not care about the order of these objects, Perl 6 provides these |
| 30 | +I<unordered> collection types. Being unordered, these containers can be more |
| 31 | +efficient than L<Lists|/type/List> or L<Arrays|/type/Array> for looking up |
23 | 32 | elements or dealing with repeated items.
|
24 | 33 |
|
25 | 34 | On the other hand, if you want to get the contained objects (elements)
|
@@ -49,12 +58,6 @@ Use the mutable variants L<SetHash|/type/SetHash>, L<BagHash|/type/BagHash>,
|
49 | 58 | and L<MixHash|/type/MixHash> if you want to add or remove elements after the
|
50 | 59 | container has been constructed.
|
51 | 60 |
|
52 |
| -The six collection classes C<Set>, C<SetHash>, C<Bag>, C<BagHash>, C<Mix>, |
53 |
| -C<MixHash>, all share similar semantics. C<Set> and C<SetHash> implement |
54 |
| -the L<Setty|/type/Setty> role, C<Bag> and C<BagHash> implement the |
55 |
| -L<Baggy|/type/Baggy> role, C<Mix> and C<MixHash> implement the |
56 |
| -L<Mixy|/type/Mixy> role (which implements the C<Baggy> role). |
57 |
| -
|
58 | 61 | For one thing, as far as they are concerned, identical objects refer to the
|
59 | 62 | same element – where identity is determined using the L<WHICH|/routine/WHICH>
|
60 | 63 | method (i.e. the same way that the L<===> operator checks identity). For value
|
|
0 commit comments