From 2277a5b2388929e9448952816baa45655bcc516a Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 22 Feb 2014 10:20:09 -0800 Subject: [PATCH] Add difference, intersection, and union methods to RealSet. --- common/modules/base.jsm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 25376a26..a45a4070 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -395,6 +395,21 @@ RealSet.prototype.add = function RealSet_add(val) { return res; }; +RealSet.prototype.difference = function RealSet_difference(set) { + return RealSet(i for (i of this) if (!set.has(i))); +}; + +RealSet.prototype.intersection = function RealSet_intersection(set) { + return RealSet(i for (i of this) if (set.has(i))); +}; + +RealSet.prototype.union = function RealSet_union(set) { + let res = RealSet(this); + for (let item of set) + res.add(item); + return res; +}; + /** * Utility for managing sets of strings. Given an array, returns an * object with one key for each value thereof.