introduce bitloops
This commit is contained in:
@@ -70,15 +70,10 @@ public record Export() {
|
||||
|
||||
public record Clued(@Delegate Clues c) {
|
||||
|
||||
public static Clues create(Cell... cell) {
|
||||
var empty = createEmpty();
|
||||
for (var cell1 : cell) empty.setClue(cell1);
|
||||
return empty;
|
||||
}
|
||||
public static Clues of(Cell... cells) {
|
||||
public static Clued of(Cell... cells) {
|
||||
var c = createEmpty();
|
||||
for (var cell : cells) c.setClue(cell);
|
||||
return c;
|
||||
return new Clued(c);
|
||||
}
|
||||
public Clued deepCopyGrid() { return new Clued(new Clues(c.lo, c.hi, c.vlo, c.vhi, c.rlo, c.rhi, c.xlo, c.xhi)); }
|
||||
public static Clued parse(String s) {
|
||||
@@ -125,6 +120,9 @@ public record Export() {
|
||||
|
||||
return stream.build();
|
||||
}
|
||||
public Slotinfo[] slots() {
|
||||
return Masker.slots(c, DictData.DICT.index());
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -143,13 +141,15 @@ public record Export() {
|
||||
default void visit(int index, byte[] letters) { visit(index, letters[index]); }
|
||||
}
|
||||
|
||||
record Gridded(@Delegate Grid grid, Clues cl) {
|
||||
record Gridded(@Delegate Grid grid, Clues cl)
|
||||
implements Stream<LetterAt> {
|
||||
|
||||
public Gridded(Clues clues) { this(clues.toGrid(), clues); }
|
||||
public Stream<LetterAt> stream(Clues clues) {
|
||||
public Gridded(Clued clues) { this(clues.toGrid(), clues.c); }
|
||||
public @Delegate Stream<LetterAt> stream() {
|
||||
val stream = Stream.<LetterAt>builder();
|
||||
for (var l = grid.lo & ~clues.lo; l != X; l &= l - 1) stream.accept(LetterAt.from(Long.numberOfTrailingZeros(l), grid.g));
|
||||
for (var h = grid.hi & ~clues.hi & 0xFF; h != X; h &= h - 1) stream.accept(LetterAt.from(64 | Long.numberOfTrailingZeros(h), grid.g));
|
||||
for (var l = grid.lo & ~cl.lo; l != X; l &= l - 1) stream.accept(LetterAt.from(Long.numberOfTrailingZeros(l), grid.g));
|
||||
for (var h = grid.hi & ~cl.hi & 0xFF; h != X; h &= h - 1) stream.accept(LetterAt.from(64 | Long.numberOfTrailingZeros(h), grid.g));
|
||||
return stream.build();
|
||||
}
|
||||
String gridToString(Clues clues) {
|
||||
@@ -161,7 +161,7 @@ public record Export() {
|
||||
val dir = Slot.dir(s);
|
||||
sb.setCharAt(r * (C + 1) + c, (char) (dir | 48));
|
||||
});
|
||||
stream(clues).forEach((l) -> sb.setCharAt(l.index(C + 1), l.human()));
|
||||
stream().forEach((l) -> sb.setCharAt(l.index(C + 1), l.human()));
|
||||
return sb.toString();
|
||||
}
|
||||
public String[] exportGrid(Clues clues, Replacar clueChar, char emptyFallback) {
|
||||
@@ -173,7 +173,7 @@ public record Export() {
|
||||
val dir = Slot.dir(s);
|
||||
sb.setCharAt(r * (C + 1) + c, clueChar.replace(new Rell(grid, clues, idx, (byte) (dir | 48))));
|
||||
});
|
||||
stream(clues).forEach((l) -> sb.setCharAt(l.index(C + 1), l.human()));
|
||||
stream().forEach((l) -> sb.setCharAt(l.index(C + 1), l.human()));
|
||||
return sb.toString().replaceAll(" ", "" + emptyFallback).split("\n");
|
||||
}
|
||||
public static IntStream cellWalk(byte base, long lo, long hi) {
|
||||
@@ -291,7 +291,7 @@ public record Export() {
|
||||
}
|
||||
|
||||
// 3) map of only used letter cells (everything else becomes '#')
|
||||
var map = grid.stream(clues.c()).collect(Collectors.toMap(LetterAt::index, LetterAt::human));
|
||||
var map = grid.stream().collect(Collectors.toMap(LetterAt::index, LetterAt::human));
|
||||
// 4) render gridv2 over cropped bounds (out-of-bounds become '#')
|
||||
var gridv2 = new String[Math.max(0, maxR - minR + 1)];
|
||||
for (int r = minR, i = 0; r <= maxR; r++, i++) {
|
||||
|
||||
Reference in New Issue
Block a user