[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] set theory methods by Fredrik Olofsson




I think these methods should be removed or rewritten.
The following methods are not referenced anywhere in the current classes. There is already a Set class for doing these things which is more efficient.
The names of these methods don't match the names in Set.
These methods modify the receiver, which is generally not a good programming practice for functional operations like these.



	// set theory methods by Fredrik Olofsson <f@xxxxxxxxxxxxxxxxxxx>
// union - the set of all elements that are either in A or in B or in both
	union { | aCollection |
		^if(aCollection.size > this.size) {
			aCollection.reject({ | item | this.includes(item) }).addAll(this)
		}{
			this.reject({ | item |
				aCollection.includes(item)
			}).addAll(aCollection)
		}
	}
	//   in both sets A and B
	intersection { | aCollection |
		^this.select { | item | aCollection.includes(item) }
	}
	//  in A but not in B
	difference { | aCollection | ^this.removeAll(aCollection) }
	//  in either A or B but not in both
	symmetricDifference { | aCollection |
		var c;
		c=this.copy;
		this.removeAll(aCollection);
		aCollection.removeAll(c);
		^this.addAll(aCollection)
	}
	//  true if every element in A is also contained in B
	isSubset { | aCollection | ^aCollection.includesAll(this) }

--
--- james mccartney   james@xxxxxxxxxxxxxx   <http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language