1 | define(["./_base", "./ArrayList"], function(dxc, ArrayList){ |
---|
2 | /*===== |
---|
3 | var dxc = dojox.collections; |
---|
4 | =====*/ |
---|
5 | dxc.Set=new (function(){ |
---|
6 | function conv(arr){ |
---|
7 | if(arr.constructor==Array){ |
---|
8 | return new ArrayList(arr); // dojox.collections.ArrayList |
---|
9 | } |
---|
10 | return arr; // dojox.collections.ArrayList |
---|
11 | } |
---|
12 | this.union = function(/* array */setA, /* array */setB){ |
---|
13 | // summary |
---|
14 | // Return the union of the two passed sets. |
---|
15 | setA=conv(setA); |
---|
16 | setB=conv(setB); |
---|
17 | var result = new ArrayList(setA.toArray()); |
---|
18 | var e = setB.getIterator(); |
---|
19 | while(!e.atEnd()){ |
---|
20 | var item=e.get(); |
---|
21 | if(!result.contains(item)){ |
---|
22 | result.add(item); |
---|
23 | } |
---|
24 | } |
---|
25 | return result; // dojox.collections.ArrayList |
---|
26 | }; |
---|
27 | this.intersection = function(/* array */setA, /* array */setB){ |
---|
28 | // summary |
---|
29 | // Return the intersection of the two passed sets. |
---|
30 | setA=conv(setA); |
---|
31 | setB=conv(setB); |
---|
32 | var result = new ArrayList(); |
---|
33 | var e = setB.getIterator(); |
---|
34 | while(!e.atEnd()){ |
---|
35 | var item=e.get(); |
---|
36 | if(setA.contains(item)){ |
---|
37 | result.add(item); |
---|
38 | } |
---|
39 | } |
---|
40 | return result; // dojox.collections.ArrayList |
---|
41 | }; |
---|
42 | this.difference = function(/* array */setA, /* array */setB){ |
---|
43 | // summary |
---|
44 | // Returns everything in setA that is not in setB. |
---|
45 | setA=conv(setA); |
---|
46 | setB=conv(setB); |
---|
47 | var result = new ArrayList(); |
---|
48 | var e=setA.getIterator(); |
---|
49 | while(!e.atEnd()){ |
---|
50 | var item=e.get(); |
---|
51 | if(!setB.contains(item)){ |
---|
52 | result.add(item); |
---|
53 | } |
---|
54 | } |
---|
55 | return result; // dojox.collections.ArrayList |
---|
56 | }; |
---|
57 | this.isSubSet = function(/* array */setA, /* array */setB) { |
---|
58 | // summary |
---|
59 | // Returns if set B is a subset of set A. |
---|
60 | setA=conv(setA); |
---|
61 | setB=conv(setB); |
---|
62 | var e = setA.getIterator(); |
---|
63 | while(!e.atEnd()){ |
---|
64 | if(!setB.contains(e.get())){ |
---|
65 | return false; // boolean |
---|
66 | } |
---|
67 | } |
---|
68 | return true; // boolean |
---|
69 | }; |
---|
70 | this.isSuperSet = function(/* array */setA, /* array */setB){ |
---|
71 | // summary |
---|
72 | // Returns if set B is a superset of set A. |
---|
73 | setA=conv(setA); |
---|
74 | setB=conv(setB); |
---|
75 | var e = setB.getIterator(); |
---|
76 | while(!e.atEnd()){ |
---|
77 | if(!setA.contains(e.get())){ |
---|
78 | return false; // boolean |
---|
79 | } |
---|
80 | } |
---|
81 | return true; // boolean |
---|
82 | }; |
---|
83 | })(); |
---|
84 | return dxc.Set; |
---|
85 | }); |
---|