arraybench/src/main/java/com/github/shautvast/benchmarks/arrays/Int2dArray.java
Shautvast b4e85092d2 v1
2023-08-28 20:18:40 +02:00

25 lines
545 B
Java

package com.github.shautvast.benchmarks.arrays;
/**
* Any dimensional int array, stored as an int[]
* No runtime checks! Easy to shoot yourself in the foot!
*/
public class Int2dArray {
private final int[] data;
private final int cols;
public Int2dArray(int rows, int cols) {
data = new int[rows * cols];
this.cols = cols;
}
public int get(int row, int col) {
return data[row * cols + col];
}
public void set(int row, int col, int val) {
data[row * cols + col] = val;
}
}