/**
 * This class creates a new instance of 
 * an Oracle Incidence Matrix (OracleIncMat). 
 * The matrix looks like this for numBits = 3.
 * (matrix dimension is 2^numBits = 8)
 *
 * {0,0,0,0,a,0,0,0},
 * {0,0,0,0,0,b,0,0},
 * {0,0,0,0,0,0,c,0},
 * {0,0,0,0,0,0,0,d},
 * {a,0,0,0,0,0,0,0},
 * {0,b,0,0,0,0,0,0},
 * {0,0,c,0,0,0,0,0},
 * {0,0,0,d,0,0,0,0}
 * 
 * where a,b,c,d \in {0,1} and we describe
 * them by bands. For example, bands {{0,0},{2,3}}
 * correspond to (a,b,c,d) = (1,0,1,1)
 * 
 */

public class OracleIncMat {
	private int  _numBits;
	private OracleBands _bands;
	private int[][] _matrix;
	
/**
 * 
 */
    public OracleIncMat(int numBits, OracleBands bands ) {
    	Throw.If(numBits<1 , 
    			"number of bits must be >= 1");  
    	_numBits = numBits;    	
    	Throw.If(bands.getLvsNumBits()!=numBits-1, 
    			"bands out of bounds");
		_bands = new OracleBands(bands);

		int numRows = 1<<numBits;
        //_matrix automatically initialized to zero
        _matrix = new int[numRows][numRows];

        
		for(int j=0; j<bands.getNumBands() ; j++){
			for(int k=bands.getFloorOfBand(j); 
				k<bands.getCeilingOfBand(j) + 1; k++){
				_matrix[ k][numRows/2 + k] = 1;
				_matrix[numRows/2 + k][k] = 1;
			}
		}
  	
    }
/**
 * 
 */   
	public String toString(){
       int numRows = _matrix.length;
       String output = "";
       output += "numRows = "+ numRows + '\n';
       int row, col;
       for(row=0; row<numRows; row++){
    	   for(col=0; col<numRows; col++){
    		   output += _matrix[row][col] + " ";
    	   }
    	   output += '\n';
       }
       return output;
   }
/**
 *
 */
	public int getEntry(int row, int col) {
		return _matrix[row][col];
	}
/**
* 
*/    
	public static void main(String[] args){
		int numBits = 4;
		OracleBands bands = new OracleBands( 3,
				new int[][] {{0,1},{3,5},{7,7}});

		System.out.println("numBits = " + numBits);
		System.out.println(bands.toString());
		OracleIncMat mat = new OracleIncMat(numBits, bands);
        System.out.println(mat.toString());
      
   }
	
}
