/*
 * Zorbage: an algebraic data hierarchy for use in numeric processing.
 *
 * Copyright (C) 2016-2020 Barry DeZonia
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package nom.bdezonia.zorbage.algorithm;

import nom.bdezonia.zorbage.algebra.Algebra;
import nom.bdezonia.zorbage.algebra.Ordered;

/**
 * 
 * @author Barry DeZonia
 *
 */
public class MinMax {

	private MinMax() { }
	
	/**
	 * 
	 * @param algebra
	 * @param a
	 * @param b
	 * @param min
	 * @param max
	 */
	public static <T extends Algebra<T,U> & Ordered<U>, U>
		void compute(T algebra, U a, U b, U min, U max)
	{
		if (algebra.isGreater().call(a, b)) {
			algebra.assign().call(a, max);
			algebra.assign().call(b, min);
		}
		else {
			algebra.assign().call(a, min);
			algebra.assign().call(b, max);
		}
	}

}

@@ -1842,16 +1842,84 @@
 max)%0A%09%7B%0A
+%09%09U tmpMin = algebra.construct();%0A%09%09U tmpMax = algebra.construct();%0A
 %09%09if (al
@@ -1978,17 +1978,20 @@
 call(a, 
-m
+tmpM
 ax);%0A%09%09%09
@@ -2015,17 +2015,20 @@
 call(b, 
-m
+tmpM
 in);%0A%09%09%7D
@@ -2065,17 +2065,20 @@
 call(a, 
-m
+tmpM
 in);%0A%09%09%09
@@ -2102,17 +2102,20 @@
 call(b, 
-m
+tmpM
 ax);%0A%09%09%7D
@@ -2115,14 +2115,90 @@
 x);%0A%09%09%7D%0A
+%09%09algebra.assign().call(tmpMin, min);%0A%09%09algebra.assign().call(tmpMax, max);%0A
 %09%7D%0A%0A%7D%0A

Make algorithm work if source vars and dest vars are the same