/*
 * Created on Oct 20, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package Cluedo.g6;

import java.util.BitSet;


class Disjunct {
	private BitSet disjunct; // indexed from 1 to n inclusive

	Disjunct(int n) {
		disjunct = new BitSet(n + 1);
		disjunct.set(1, n + 1);
	}

	Disjunct(int n, int[] indices) {
		this(n);
		set(indices, true);
	}

	void set(int index, boolean value) {
		disjunct.set(index, value);
	}

        boolean get(int index){
          return disjunct.get(index);
        }

	void set(int[] indices, boolean value) {
		for (int i=0; i<indices.length; i++) {
			disjunct.set(indices[i], value);
		}
	}

	int getNumSet() {
		return disjunct.cardinality();
	}

	int getNextSet(int fromIndex) {
		return disjunct.nextSetBit(fromIndex);
	}

	/**
	 * @return the indices where this disjunct has bits set to true
	 */
	int[] getIndexList() {
		int[] indices = new int[disjunct.cardinality()];
		int i = 0;

		for (int j = getNextSet(1); j >= 0;	j = getNextSet(j + 1)) {
			indices[i++] = j;
		}

		return indices;
	}
}