Java BitSet unionAdd(BitSet newClique, int nNodes, LinkedList cliques)

Here you can find the source of unionAdd(BitSet newClique, int nNodes, LinkedList cliques)

Description

union Add

License

Open Source License

Declaration

static void unionAdd(BitSet newClique, int nNodes, LinkedList<BitSet> cliques) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .  java2 s. c om*/
 * Copyright (C) 2006-2011 by Olivier Chafik (http://ochafik.com)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.util.BitSet;

import java.util.LinkedList;

public class Main {
    static void unionAdd(BitSet newClique, int nNodes, LinkedList<BitSet> cliques) {
        for (int iClique = cliques.size(); iClique-- != 0;) {
            if (iClique >= cliques.size())
                continue; // the size may vary because of recusive calls to unionAdd that may merge some cliques
            BitSet clique = cliques.get(iClique);

            boolean containsAll = true, isAllContained = true;
            for (int node = nNodes; node-- != 0;) {
                boolean bClique = clique.get(node), bNew = newClique.get(node);
                if (bClique) {
                    if (!bNew) {
                        containsAll = false;
                    }
                } else {
                    if (bNew) {
                        isAllContained = false;
                    }
                }
            }
            if (isAllContained)
                return; // no modification needed
            else if (containsAll) {
                // Modification needed : critical part
                cliques.remove(clique);
                for (int node = nNodes; node-- != 0;) {
                    clique.set(node, newClique.get(node));
                }
                unionAdd(clique, nNodes, cliques); // added recursively
                return;
            }
        }

        BitSet copy = new BitSet(nNodes);
        copy.or(newClique);
        cliques.add(copy);
        return; // added clique to list
    }
}

Related

  1. toIntArray(final BitSet bits, final int size)
  2. toInteger(final BitSet bits)
  3. toLong(final BitSet value)
  4. toString(BitSet bs)
  5. translateBitSetToProjIndx(BitSet projBitSet)
  6. unpackInt(BitSet bs, int offset, int noOfBits)
  7. unsignedIntToLittleEndianBitSet(int i)
  8. validateEncoded(BitSet encoded, int encodedBitLength)
  9. validCookieNameOctets(BitSet validCookieValueOctets)