Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Optimized isRowComplete()/isColumnComplete()
Browse files Browse the repository at this point in the history
  • Loading branch information
nibix committed Jun 24, 2024
1 parent e651154 commit 30be2a7
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/main/java/com/selectivem/check/CheckTableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1577,15 +1577,7 @@ public boolean isRowComplete(R row) {
throw new IllegalArgumentException("Invalid row: " + row);
}

for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
int i = tableIndex(rowIndex, columnIndex);

if (!this.table[i]) {
return false;
}
}

return true;
return isRowCompleted(rowIndex);
}

@Override
Expand All @@ -1596,15 +1588,7 @@ public boolean isColumnComplete(C column) {
throw new IllegalArgumentException("Invalid column: " + column);
}

for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
int i = tableIndex(rowIndex, columnIndex);

if (!this.table[i]) {
return false;
}
}

return true;
return isColumnCompleted(columnIndex);
}

@Override
Expand Down Expand Up @@ -1658,9 +1642,11 @@ public Set<C> getCheckedColumns(R row) {
}

private boolean isRowCompleted(int rowIndex) {
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
int i = tableIndex(rowIndex, columnIndex);
int start = tableIndex(rowIndex, 0);
int end = tableIndex(rowIndex, columnCount - 1);
int inc = this.rowCount;

for (int i = start; i <= end; i += inc) {
if (!this.table[i]) {
return false;
}
Expand All @@ -1670,9 +1656,10 @@ private boolean isRowCompleted(int rowIndex) {
}

private boolean isColumnCompleted(int columnIndex) {
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
int i = tableIndex(rowIndex, columnIndex);
int start = tableIndex(0, columnIndex);
int end = tableIndex(rowCount - 1, columnIndex);

for (int i = start; i <= end; i++) {
if (!this.table[i]) {
return false;
}
Expand Down

0 comments on commit 30be2a7

Please sign in to comment.