introduce bitloops

This commit is contained in:
mike
2026-01-17 03:37:38 +01:00
parent 44f53801a3
commit d3c7128cf9
3 changed files with 12 additions and 27 deletions

View File

@@ -51,7 +51,7 @@ public record Export() {
public Clued deepCopyGrid() { return new Clued(new Clues(c.lo, c.hi, c.vlo, c.vhi, c.rlo, c.rhi)); }
String gridToString() {
var sb = new StringBuilder(INIT);
forEachSlot((s, l, a) -> {
forEachSlot((s, _, _) -> {
val idx = Slot.clueIndex(s);
val r = idx & 7;
val c = idx >>> 3;
@@ -150,7 +150,7 @@ public record Export() {
}
String gridToString(Clues clues) {
var sb = new StringBuilder(INIT);
clues.forEachSlot((s, l, a) -> {
clues.forEachSlot((s, _, _) -> {
val idx = Slot.clueIndex(s);
val r = idx & 7;
val c = idx >>> 3;
@@ -193,12 +193,11 @@ public record Export() {
interface Bit1029 {
public static long[] bit1029() { return new long[2048]; }
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
static public boolean get(long[] bits, int bitIndex) { return (bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
static public void set(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
static public void clear(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
static public void clear(long[] bits) { Arrays.fill(bits, 0L); }
static long[] bit1029() { return new long[2048]; }
static int wordIndex(int bitIndex) { return bitIndex >> 6; }
static boolean get(long[] bits, int bitIndex) { return (bits[wordIndex(bitIndex)] & 1L << bitIndex) != 0L; }
static void set(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] |= 1L << bitIndex; }
static void clear(long[] bits, int bitIndex) { bits[wordIndex(bitIndex)] &= ~(1L << bitIndex); }
}
record Placed(long lemma, int slotKey, int[] cells) {
@@ -228,21 +227,12 @@ public record Export() {
public record PuzzleResult(Clued clues, Slotinfo[] slots, FillResult filled) {
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
var g = filled().grid();
var placed = new ArrayList<Placed>();
var g = filled().grid();
var placed = new ArrayList<Placed>();
for (var slot : slots) {
placed.add(new Placed(slot.assign().w, slot.key(), Gridded.walk((byte) slot.key(), slot.lo(), slot.hi()).toArray()));
}
/* clues.forEachSlot((int key, long lo, long hi) -> {
var word = clueMap[key];
if (word != 0L) {
placed.add(extractPlacedFromSlot(Slot.from(key, lo, hi, entries[Slot.length(lo, hi)]), word));
} else {
System.err.println("Could not find clue for slot: " + key);
}
});*/
// If nothing placed: return full grid mapped to letters/# only
if (placed.isEmpty()) {
return new ExportedPuzzle(g.exportGrid(clues.c, _ -> '#', '#'), new WordOut[0], difficulty, rewards);