common: more pathscale compile fixes
[supercollider.git] / Help / Collections / IdentityBag.html
blobb2abdc2c6429605956d6cd0bee306f2a0f94237a
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #001bb9}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #982316}
22 p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
23 p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0025b2}
24 p.p15 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Helvetica; min-height: 11.0px}
25 span.s1 {font: 12.0px Helvetica}
26 span.s2 {color: #000000}
27 span.s3 {color: #0000ff}
28 span.s4 {color: #0000bf}
29 span.s5 {color: #0025b2}
30 span.s6 {color: #007300}
31 span.s7 {color: #982316}
32 span.Apple-tab-span {white-space:pre}
33 </style>
34 </head>
35 <body>
36 <p class="p1"><b>IdentityBag<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b><span class="s1"><b>counted set</b></span></p>
37 <p class="p2"><br></p>
38 <p class="p3"><span class="s2"><b>Inherits from: </b><a href="../Core/Object.html"><b>Object</b></a></span><b> : </b><a href="Collection.html"><b>Collection</b></a><b> </b><span class="s2"><b>: </b><a href="Bag.html"><span class="s3"><b>Bag</b></span></a></span></p>
39 <p class="p2"><br></p>
40 <p class="p4">An IdentityBag is an unordered collection of objects.<span class="Apple-converted-space">  </span>In some languages it is referred to as a counted set.<span class="Apple-converted-space">  </span>A Bag keeps track of the number of times objects are inserted and requires that objects be removed the same number of times. There is only one instance of an object in a Bag even if the object has been added to the Bag multiple times (test is for <b>identity</b>).</p>
41 <p class="p2"><br></p>
42 <p class="p4">The contents of a IdentityBag are unordered. You must not depend on the order of items in a set.</p>
43 <p class="p2"><br></p>
44 <p class="p2"><br></p>
45 <p class="p5"><b>Adding and Removing:</b></p>
46 <p class="p2"><br></p>
47 <p class="p4"><b>add(anObject)</b></p>
48 <p class="p2"><br></p>
49 <p class="p4">Add anObject to the Bag. A Bag may contain multiple entries of the same object.</p>
50 <p class="p6"><br></p>
51 <p class="p7"><span class="s4">IdentityBag</span>[1, 2, 3].add(4);</p>
52 <p class="p8"><br></p>
53 <p class="p7"><span class="s4">IdentityBag</span>[1, 2, 3].add(3);</p>
54 <p class="p8"><br></p>
55 <p class="p9"><span class="s4">IdentityBag</span><span class="s2">[</span>"abc"<span class="s2">, </span>"def"<span class="s2">, </span>"ghi"<span class="s2">].add(</span>"jkl"<span class="s2">);</span></p>
56 <p class="p8"><br></p>
57 <p class="p9"><span class="s4">IdentityBag</span><span class="s2">[</span>"abc"<span class="s2">, </span>"def"<span class="s2">, </span>"ghi"<span class="s2">].add(</span>"def"<span class="s2">);</span></p>
58 <p class="p2"><br></p>
59 <p class="p4"><b>remove(anObject)</b></p>
60 <p class="p2"><br></p>
61 <p class="p4">Remove anObject from the IdentityBag.</p>
62 <p class="p2"><br></p>
63 <p class="p10"><span class="s5">IdentityBag</span>[1, 2, 3].remove(3);</p>
64 <p class="p6"><br></p>
65 <p class="p4"><b>contents</b></p>
66 <p class="p6"><br></p>
67 <p class="p4">Returns the dictionary that stores the objects in pairs (obj -&gt; numberOfObjects)</p>
68 <p class="p2"><br></p>
69 <p class="p7"><span class="s4">IdentityBag</span>[<span class="s6">\a</span>, <span class="s6">\b</span>, <span class="s6">\c</span>, <span class="s6">\c</span>].contents;</p>
70 <p class="p6"><br></p>
71 <p class="p11"><br></p>
72 <p class="p5"><b>Iteration:</b></p>
73 <p class="p2"><br></p>
74 <p class="p4"><b>do(function)</b></p>
75 <p class="p2"><br></p>
76 <p class="p4">Evaluates function for each item in the IdentityBag.</p>
77 <p class="p4">The function is passed two arguments, the item and an integer index.</p>
78 <p class="p2"><br></p>
79 <p class="p10"><span class="s5">IdentityBag</span>[1, 2, 3, 300].do({ <span class="s5">arg</span> item, i; item.postln });</p>
80 <p class="p2"><br></p>
81 <p class="p2"><br></p>
82 <p class="p11"><br></p>
83 <p class="p5"><b>Difference between Bag and IdentityBag:</b></p>
84 <p class="p6"><br></p>
85 <p class="p12">// the two strings are equal, but not identical</p>
86 <p class="p9">"something"<span class="s2"> == </span>"something"<span class="s2">; </span><span class="s7">// true</span></p>
87 <p class="p9">"something"<span class="s2"> === </span>"something"<span class="s2"> </span><span class="s7">// false</span></p>
88 <p class="p13"><br></p>
89 <p class="p10">a = <span class="s5">Bag</span>.new;</p>
90 <p class="p9"><span class="s2">a.add(</span>"something"<span class="s2">);</span></p>
91 <p class="p9"><span class="s2">a.add(</span>"something"<span class="s2">);</span></p>
92 <p class="p12"><span class="s2">a.contents; </span>// only one object in the bag really</p>
93 <p class="p13"><br></p>
94 <p class="p14"><span class="s2">a = </span>IdentityBag<span class="s2">.new;</span></p>
95 <p class="p9"><span class="s2">a.add(</span>"something"<span class="s2">);</span></p>
96 <p class="p9"><span class="s2">a.add(</span>"something"<span class="s2">);</span></p>
97 <p class="p12"><span class="s2">a.contents; </span>// two objects in the bag</p>
98 <p class="p15"><br></p>
99 </body>
100 </html>