projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Timeline now passed via constructor
[Mograsim.git]
/
era.mi
/
src
/
era
/
mi
/
logic
/
Util.java
diff --git
a/era.mi/src/era/mi/logic/Util.java
b/era.mi/src/era/mi/logic/Util.java
index
4a03410
..
d621a44
100644
(file)
--- a/
era.mi/src/era/mi/logic/Util.java
+++ b/
era.mi/src/era/mi/logic/Util.java
@@
-2,10
+2,14
@@
package era.mi.logic;
import java.util.Arrays;
import java.util.Arrays;
-public final class Util {
+import era.mi.logic.types.Bit;
+
+public final class Util
+{
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
- public static <T> T[] concat(T[]... arrays) {
+ public static <T> T[] concat(T[]... arrays)
+ {
if (arrays.length == 0)
throw new IllegalArgumentException("Cannot concatenate 0 arrays.");
if (arrays.length == 0)
throw new IllegalArgumentException("Cannot concatenate 0 arrays.");
@@
-15,7
+19,8
@@
public final class Util {
T[] newArray = Arrays.copyOf(arrays[0], length);
int appendIndex = arrays[0].length;
T[] newArray = Arrays.copyOf(arrays[0], length);
int appendIndex = arrays[0].length;
- for (int i = 1; i < arrays.length; i++) {
+ for (int i = 1; i < arrays.length; i++)
+ {
System.arraycopy(arrays[i], 0, newArray, appendIndex, arrays[i].length);
appendIndex += arrays[i].length;
}
System.arraycopy(arrays[i], 0, newArray, appendIndex, arrays[i].length);
appendIndex += arrays[i].length;
}
@@
-45,31
+50,38
@@
public final class Util {
// return (T[][]) newArray;
// }
// return (T[][]) newArray;
// }
- public static Bit[] and(Bit[] a, Bit[] b) {
- return binBitOp(a, b, (bA, bB) -> Bit.and(bA, bB));
+ public static Bit[] and(Bit[] a, Bit[] b)
+ {
+ return binBitOp(a, b, Bit::and);
}
}
- public static Bit[] or(Bit[] a, Bit[] b) {
- return binBitOp(a, b, (bA, bB) -> Bit.or(bA, bB));
+ public static Bit[] or(Bit[] a, Bit[] b)
+ {
+ return binBitOp(a, b, Bit::or);
}
}
- public static Bit[] xor(Bit[] a, Bit[] b) {
- return binBitOp(a, b, (bA, bB) -> Bit.xor(bA, bB));
+ public static Bit[] xor(Bit[] a, Bit[] b)
+ {
+ return binBitOp(a, b, Bit::xor);
}
}
- private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op) {
+ private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op)
+ {
if (a.length != b.length)
throw new IllegalArgumentException("Bit Arrays were not of equal length.");
Bit[] out = new Bit[a.length];
if (a.length != b.length)
throw new IllegalArgumentException("Bit Arrays were not of equal length.");
Bit[] out = new Bit[a.length];
- for (int i = 0; i < a.length; i++) {
+ for (int i = 0; i < a.length; i++)
+ {
out[i] = op.execute(a[i], b[i]);
}
return out;
}
out[i] = op.execute(a[i], b[i]);
}
return out;
}
- public static Bit[] not(Bit[] a) {
+ public static Bit[] not(Bit[] a)
+ {
Bit[] out = new Bit[a.length];
Bit[] out = new Bit[a.length];
- for (int i = 0; i < a.length; i++) {
+ for (int i = 0; i < a.length; i++)
+ {
out[i] = a[i].not();
}
return out;
out[i] = a[i].not();
}
return out;
@@
-80,16
+92,19
@@
public final class Util {
*
* @author Christian Femers
*/
*
* @author Christian Femers
*/
- public static Bit[] combineInto(Bit[] dest, Bit[] addition) {
+ public static Bit[] combineInto(Bit[] dest, Bit[] addition)
+ {
if (dest.length != addition.length)
throw new IllegalArgumentException("Bit Arrays were not of equal length.");
if (dest.length != addition.length)
throw new IllegalArgumentException("Bit Arrays were not of equal length.");
- for (int i = 0; i < addition.length; i++) {
- dest[i] = dest[i].combineWith(addition[i]);
+ for (int i = 0; i < addition.length; i++)
+ {
+ dest[i] = dest[i].join(addition[i]);
}
return dest;
}
}
return dest;
}
- interface BitOp {
+ interface BitOp
+ {
Bit execute(Bit a, Bit b);
}
}
Bit execute(Bit a, Bit b);
}
}