summaryrefslogtreecommitdiff
path: root/includes/js/dojox/collections/Set.js
blob: 6796c1d284648155d07c24ea66a747974b635e90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
if(!dojo._hasResource["dojox.collections.Set"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.collections.Set"] = true;
dojo.provide("dojox.collections.Set");
dojo.require("dojox.collections.ArrayList");

(function(){
	var dxc=dojox.collections;
	dxc.Set=new (function(){
		function conv(arr){
			if(arr.constructor==Array){
				return new dojox.collections.ArrayList(arr);	//	dojox.collections.ArrayList
			}
			return arr;		//	dojox.collections.ArrayList
		}
		this.union = function(/* array */setA, /* array */setB){
			//	summary
			//	Return the union of the two passed sets.
			setA=conv(setA);
			setB=conv(setB);
			var result = new dojox.collections.ArrayList(setA.toArray());
			var e = setB.getIterator();
			while(!e.atEnd()){
				var item=e.get();
				if(!result.contains(item)){
					result.add(item);
				}
			}
			return result;	//	dojox.collections.ArrayList
		};
		this.intersection = function(/* array */setA, /* array */setB){
			//	summary
			//	Return the intersection of the two passed sets.
			setA=conv(setA);
			setB=conv(setB);
			var result = new dojox.collections.ArrayList();
			var e = setB.getIterator();
			while(!e.atEnd()){
				var item=e.get();
				if(setA.contains(item)){
					result.add(item);
				}
			}
			return result;	//	dojox.collections.ArrayList
		};
		this.difference = function(/* array */setA, /* array */setB){
			//	summary
			//	Returns everything in setA that is not in setB.
			setA=conv(setA);
			setB=conv(setB);
			var result = new dojox.collections.ArrayList();
			var e=setA.getIterator();
			while(!e.atEnd()){
				var item=e.get();
				if(!setB.contains(item)){
					result.add(item);
				}
			}
			return result;	//	dojox.collections.ArrayList
		};
		this.isSubSet = function(/* array */setA, /* array */setB) {
			//	summary
			//	Returns if set B is a subset of set A.
			setA=conv(setA);
			setB=conv(setB);
			var e = setA.getIterator();
			while(!e.atEnd()){
				if(!setB.contains(e.get())){
					return false;	//	boolean
				}
			}
			return true;	//	boolean
		};
		this.isSuperSet = function(/* array */setA, /* array */setB){
			//	summary
			//	Returns if set B is a superset of set A.
			setA=conv(setA);
			setB=conv(setB);
			var e = setB.getIterator();
			while(!e.atEnd()){
				if(!setA.contains(e.get())){
					return false;	//	boolean
				}
			}
			return true;	//	boolean
		};
	})();
})();

}