is BitSet Subset - Java java.util

Java examples for java.util:BitSet

Description

is BitSet Subset

Demo Code


//package com.java2s;

import java.util.BitSet;
import java.lang.reflect.*;

public class Main {
    static Field wordsField = null;

    public static boolean isSubset2(BitSet s1, BitSet s2) {

        try {//from  w  w  w .  j  ava 2s .c  om
            long[] left = (long[]) wordsField.get(s1);
            long[] right = (long[]) wordsField.get(s2);

            for (int i = 0; i < left.length; i++) {
                long x = left[i];
                if (i >= right.length) {
                    if (x != 0)
                        return false;
                } else {
                    long y = right[i];
                    if ((x | y) != y) {
                        return false;
                    }
                }
            }
        } catch (IllegalArgumentException cannotHappen) {
        } catch (IllegalAccessException cannotHappen) {
        }

        // System.out.println(Arrays.toString(left) + " vs " +
        // Arrays.toString(right));

        return true;
        // return false;
    }
}

Related Tutorials