Java BitSet isSubset(BitSet bits1, BitSet bits2)

Here you can find the source of isSubset(BitSet bits1, BitSet bits2)

Description

True if all bits set in first bitset are also set in second.

License

Apache License

Declaration

public static boolean isSubset(BitSet bits1, BitSet bits2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
*   Copyright 2014 Analog Devices, Inc.//from ww w.j a va 2 s .  co m
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
********************************************************************************/

import java.util.BitSet;

public class Main {
    /**
     * True if all bits set in first bitset are also set in second.
     * @since 0.08
     */
    public static boolean isSubset(BitSet bits1, BitSet bits2) {
        int index = -1;
        while (true) {
            if (0 > (index = bits1.nextSetBit(++index)))
                break;
            if (!bits2.get(index))
                return false;
        }

        return true;
    }
}

Related

  1. intToBitSet(int value)
  2. invertInPlace(BitSet bs, int n)
  3. isEmptySet(BitSet setToTest)
  4. isHammingDistanceOne(BitSet a, BitSet b)
  5. isSet(int n, BitSet... sets)
  6. isSubset(BitSet subsetToTest, BitSet supersetToTest)
  7. isSubSet(BitSet x, BitSet y)
  8. longFrom(final BitSet bitSet)
  9. longToBitSet(long bits)