1 | 'use strict';
|
2 | var aSet = require('../internals/a-set');
|
3 | var SetHelpers = require('../internals/set-helpers');
|
4 | var size = require('../internals/set-size');
|
5 | var getSetRecord = require('../internals/get-set-record');
|
6 | var iterateSet = require('../internals/set-iterate');
|
7 | var iterateSimple = require('../internals/iterate-simple');
|
8 |
|
9 | var Set = SetHelpers.Set;
|
10 | var add = SetHelpers.add;
|
11 | var has = SetHelpers.has;
|
12 |
|
13 |
|
14 |
|
15 | module.exports = function intersection(other) {
|
16 | var O = aSet(this);
|
17 | var otherRec = getSetRecord(other);
|
18 | var result = new Set();
|
19 |
|
20 | if (size(O) > otherRec.size) {
|
21 | iterateSimple(otherRec.getIterator(), function (e) {
|
22 | if (has(O, e)) add(result, e);
|
23 | });
|
24 | } else {
|
25 | iterateSet(O, function (e) {
|
26 | if (otherRec.includes(e)) add(result, e);
|
27 | });
|
28 | }
|
29 |
|
30 | return result;
|
31 | };
|