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 Or extends BinaryNode<Boolean> {

	@Override
	public String toString() {
		return "or";
	}

	@Override
	public boolean isSymmetric() {
		return true;
	}
	
	@Override
	protected ISemantics execute(ISemantics... arguments) {
		BitSet semantics = (BitSet)((BitSet)arguments[0].getValue()).clone();
		semantics.or((BitSet)arguments[1].getValue());

		return new BooleanSemantics(semantics);
	}

	@Override
	public Boolean[] invert(Boolean output, int missingArgIdx, Boolean... restOfArguments) {
		if (restOfArguments[0]) {
			if (output)
				return Inversions.DONT_CARE;
			else
				return Inversions.INCONSISTENT;
		}

		assert !restOfArguments[0];
		return output /* && !restOfArguments[0] */ ? Inversions.TRUE : Inversions.FALSE;
		//return new Boolean[] { output /* && !restOfArguments[0] */};
	}

}
