Skip to content

Commit

Permalink
pat3 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonsqueeze committed Mar 22, 2019
1 parent 1f921c5 commit c0e11b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
23 changes: 14 additions & 9 deletions pattern3.c
Expand Up @@ -12,16 +12,21 @@ static void
pattern_record(pattern3s_t *p, int pi, char *str, hash3_t pat, int fixed_color)
{
hash3_t h = hash3_to_hash(pat);
while (p->hash[h & pattern3_hash_mask].pattern != pat
&& p->hash[h & pattern3_hash_mask].value != 0)
h++;
while (p->hash[h].pattern != pat && p->hash[h].value)
h = (h + 1) & pattern3_hash_mask;

p->hash[h].pattern = pat;
p->hash[h].value = (fixed_color ? fixed_color : 3) | (pi << 2);

#if 0
if (h != hash3_to_hash(pat) && p->hash[h & pattern3_hash_mask].pattern != pat)
fprintf(stderr, "collision of %06x: %llx(%x)\n", pat, hash3_to_hash(pat)&pattern3_hash_mask, p->hash[hash3_to_hash(pat)&pattern3_hash_mask].pattern);
#endif
p->hash[h & pattern3_hash_mask].pattern = pat;
p->hash[h & pattern3_hash_mask].value = (fixed_color ? fixed_color : 3) | (pi << 2);
//fprintf(stderr, "[%s] %04x %d\n", str, pat, fixed_color);
if (h != hash3_to_hash(pat) && p->hash[h].pattern != pat)
fprintf(stderr, "collision of %06x: %llx(%x)\n", pat, hash3_to_hash(pat), p->hash[hash3_to_hash(pat)].pattern);
if (p->hash[h].pattern == pat && (p->hash[h].value >> 2) != pi)
fprintf(stderr, "clobbering prev pattern %#06x value %i -> %i\n", pat,
(p->hash[h].value >> 2), pi);
/* Dump all patterns_record() (including clobbers) */
// fprintf(stderr, "[%s] %06x %d %i\n", str, pat, fixed_color, pi);
#endif
}

static int
Expand Down
12 changes: 5 additions & 7 deletions pattern3.h
Expand Up @@ -105,7 +105,7 @@ hash3_to_hash(hash3_t pat)
for (int i = 0; i < 8; i++) {
h ^= p3hashes[i][ataribits[i] >= 0 ? (pat >> (16 + ataribits[i])) & 1 : 0][(pat >> (i*2)) & 3];
}
return h;
return (h & pattern3_hash_mask);
}

static inline bool
Expand All @@ -132,12 +132,10 @@ pattern3_move_here(pattern3s_t *p, board_t *b, move_t *m, char *idx)
#endif
hash3_t h = hash3_to_hash(pat);

while (p->hash[h & pattern3_hash_mask].pattern != pat &&
p->hash[h & pattern3_hash_mask].value != 0)
h++;

if (p->hash[h & pattern3_hash_mask].value & m->color) {
*idx = p->hash[h & pattern3_hash_mask].value >> 2;
while (p->hash[h].pattern != pat && p->hash[h].value)
h = (h + 1) & pattern3_hash_mask;
if (p->hash[h].value & m->color) {
*idx = p->hash[h].value >> 2;
return true;
}

Expand Down

0 comments on commit c0e11b4

Please sign in to comment.