/**
 * This class creates a new instance of 
 * a Glue Incidence Matrix (GlueIncMat). 
 * The matrix dimension is 2^numBits.
 * All its entries are zero except for
 * (_j1,_j2) and (_j2,_j1) which are one.
 * 
 */

public class GlueIncMat {
    private int _numBits;
    private int _j1, _j2;
    private int[][] _matrix;
/**
 * 
 */
    public GlueIncMat(int numBits, Pair pair) {
    	
        Throw.If(numBits<1, "number of bits must be >= 1");                  
        _numBits = numBits;
		_j1 = pair._x1;
		_j2 = pair._x2;
		int numRows = 1<<numBits;
		Throw.If(_j1<0 || _j1>= numRows, 
			"row or col number is out of bounds");
		Throw.If(_j2<0 || _j2>= numRows, 
			"row or col number is out of bounds");
		Throw.If(_j1==_j2, 
				"diagonal glue is not allowed");

        
        //_matrix automatically initialized to zero
        _matrix = new int[numRows][numRows];
        
        _matrix[_j1][_j2] = 1;
        _matrix[_j2][_j1] = 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;
		Pair pair = new Pair(3,7);

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

}
