package ec.app.semanticGP.func.logic;

import library.semantics.BitSet;
import ec.gp.semantic.BooleanSemantics;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.BinaryNode;

public final class Xor extends BinaryNode<Boolean> {
	
	@Override
	public String toString() {
		return "xor";
	}
	
	@Override
	public boolean isSymmetric() {
		return true;
	}
	
	@Override
	protected ISemantics execute(ISemantics... arguments) {
		BitSet semantics = (BitSet) ((BitSet) arguments[0].getValue()).clone();
		semantics.xor((BitSet) arguments[1].getValue());
		
		return new BooleanSemantics(semantics);
	}
	
	@Override
	public Boolean[] invert(Boolean output, int missingArgIdx, Boolean... restOfArguments) {
		return output ^ restOfArguments[0] ? Inversions.TRUE : Inversions.FALSE;
		//return new Boolean[] { output ^ restOfArguments[0] };
	}
	
}
