introduce bitloops
This commit is contained in:
@@ -3,14 +3,14 @@ package puzzle;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.Delegate;
|
||||
import puzzle.Export.Gridded;
|
||||
import puzzle.SwedishGenerator.Dict;
|
||||
import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.stream.IntStream;
|
||||
import static puzzle.SwedishGenerator.R;
|
||||
import static puzzle.SwedishGenerator.Lemma;
|
||||
import static puzzle.SwedishGenerator.Slot;
|
||||
@@ -38,6 +38,55 @@ public record Export() {
|
||||
record Gridded(@Delegate Grid grid) {
|
||||
|
||||
static boolean isLetter(byte b) { return (b & SwedishGenerator.B64) != SwedishGenerator.B0; }
|
||||
public static IntStream walk(byte base, long lo, long hi) {
|
||||
if (Slot.increasing(base)) {
|
||||
return IntStream.concat(
|
||||
IntStream.generate(new IntSupplier() {
|
||||
|
||||
long temp = lo;
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
int res = Long.numberOfTrailingZeros(temp);
|
||||
temp &= temp - 1;
|
||||
return res;
|
||||
}
|
||||
}).limit(Long.bitCount(lo)),
|
||||
IntStream.generate(new IntSupplier() {
|
||||
|
||||
long temp = hi;
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
int res = 64 | Long.numberOfTrailingZeros(temp);
|
||||
temp &= temp - 1;
|
||||
return res;
|
||||
}
|
||||
}).limit(Long.bitCount(hi)));
|
||||
} else {
|
||||
return IntStream.concat(
|
||||
IntStream.generate(new IntSupplier() {
|
||||
|
||||
long temp = hi;
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
int msb = 63 - Long.numberOfLeadingZeros(temp);
|
||||
int res = 64 | msb;
|
||||
temp &= ~(1L << msb);
|
||||
return res;
|
||||
}
|
||||
}).limit(Long.bitCount(hi)),
|
||||
IntStream.generate(new IntSupplier() {
|
||||
|
||||
long temp = lo;
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
int msb = 63 - Long.numberOfLeadingZeros(temp);
|
||||
int res = msb;
|
||||
temp &= ~(1L << msb);
|
||||
return res;
|
||||
}
|
||||
}).limit(Long.bitCount(lo)));
|
||||
}
|
||||
}
|
||||
//public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||
char NOT_CLUE_NOT_LETTER_TO(byte b, char fallback) { return isLetter(b) ? (char) b : fallback; }
|
||||
String gridToString() {
|
||||
@@ -123,8 +172,7 @@ public record Export() {
|
||||
Placed extractPlacedFromSlot(Slot s, long lemma) {
|
||||
var d = s.dir();
|
||||
|
||||
var cells = new int[s.len()];
|
||||
for (int i = 0, len = s.len(); i < len; i++) cells[i] = s.pos(i);
|
||||
var cells = s.walk().toArray();
|
||||
|
||||
char direction;
|
||||
var startRow = Grid.r(cells[0]);
|
||||
|
||||
Reference in New Issue
Block a user