src/lib/collections/hash-set.js
function (other) {
        assertNotNull(other);

        // intersection of anything with empty set is empty set, so return if count is 0
        if (this.count() === 0) {
            return;
        }

        var c = collectionCount(other);

        if (c !== -1) {
            if (c === 0) {
                this.clear();
                return;
            }

            // If other is a HashSet, it has unique elements according to its equality comparer,
            // but if they're using different equality comparers, then assumption of uniqueness
            // will fail. So first check if other is a hashset using the same equality comparer;
            // intersect is a lot faster if we can assume uniqueness.

            if (areEqualityComparersEqual(this, other)) {
                var arr = this.table.entries(true),
                    item;

                c = this.count();

                while (c-- > 0) {
                    item = arr[c];
                    if (!other.contains(item)) {
                        this.table.remove(item);
                    }
                }

                return;
            }
        }

        this.intersectWith(new HashSet(other, this.compare));
    }
function (other) {
        assertNotNull(other);

        // intersection of anything with empty set is empty set, so return if count is 0
        if (this.count() === 0) {
            return;
        }

        var c = collectionCount(other);

        if (c !== -1) {
            if (c === 0) {
                this.clear();
                return;
            }

            // If other is a HashSet, it has unique elements according to its equality comparer,
            // but if they're using different equality comparers, then assumption of uniqueness
            // will fail. So first check if other is a hashset using the same equality comparer;
            // intersect is a lot faster if we can assume uniqueness.

            if (areEqualityComparersEqual(this, other)) {
                var arr = this.table.entries(true),
                    item;

                c = this.count();

                while (c-- > 0) {
                    item = arr[c];
                    if (!other.contains(item)) {
                        this.table.remove(item);
                    }
                }

                return;
            }
        }

        this.intersectWith(new HashSet(other, this.compare));
    }
function ( other ) { assertNotNull ( other ) ; // intersection of anything with empty set is empty set, so return if count is 0 if ( this . count ( ) === 0 ) { return ; } var c = collectionCount ( other ) ; if ( c !== - 1 ) { if ( c === 0 ) { this . clear ( ) ; return ; } // If other is a HashSet, it has unique elements according to its equality comparer, // but if they're using different equality comparers, then assumption of uniqueness // will fail. So first check if other is a hashset using the same equality comparer; // intersect is a lot faster if we can assume uniqueness. if ( areEqualityComparersEqual ( this , other ) ) { var arr = this . table . entries ( true ) , item ; c = this . count ( ) ; while ( c -- > 0 ) { item = arr [ c ] ; if ( ! other . contains ( item ) ) { this . table . remove ( item ) ; } } return ; } } this . intersectWith ( new HashSet ( other , this . compare ) ) ; }
Modifies the current set so that it contains only elements that are also in a specified collection.
@param {Iterable} other The collection to compare to the current set.
Modifies the current set so that it contains only elements that are also in a specified collection .