2022-09-10 14:01:13 -04:00
|
|
|
#include <stdio.h>
|
2022-09-10 14:16:43 -04:00
|
|
|
#include <string.h>
|
2022-09-11 19:04:40 -04:00
|
|
|
#include <stdlib.h>
|
2022-09-10 14:01:13 -04:00
|
|
|
#include "boilerplate.h"
|
|
|
|
|
2022-09-11 19:04:40 -04:00
|
|
|
#if PRINT_INTERMEDIATES
|
|
|
|
extern uint32_t rawWC;
|
|
|
|
#endif
|
|
|
|
|
2022-09-10 14:01:13 -04:00
|
|
|
int compare(const void * a, const void * b) {
|
2022-09-26 10:31:09 -04:00
|
|
|
return ((signature*)a)->sign - ((signature*)b)->sign;
|
2022-09-10 14:01:13 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 10:31:09 -04:00
|
|
|
uint32_t getsig(char* restrict word) {
|
2022-09-10 14:01:13 -04:00
|
|
|
uint32_t result = 0;
|
|
|
|
for (uint32_t i = 0; i < 5; i++) {
|
|
|
|
uint32_t bit = 1u << (word[i] & CHARMASK);
|
|
|
|
if (result & bit) {
|
|
|
|
// duplicate letters
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
result |= bit;
|
|
|
|
}
|
|
|
|
return result;
|
2022-09-10 14:16:43 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 10:31:09 -04:00
|
|
|
uint32_t rmdups(signature* restrict arr, uint32_t nitems) {
|
2022-09-10 14:16:43 -04:00
|
|
|
// list is already sorted
|
|
|
|
for (uint32_t i = 0; i < nitems; i++) {
|
|
|
|
while (arr[i].sign == arr[i + 1].sign) {
|
|
|
|
memmove( &arr[ i ], &arr[ i + 1 ], (nitems - i) * sizeof(signature));
|
|
|
|
nitems--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nitems;
|
2022-09-11 19:04:40 -04:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:11:08 -04:00
|
|
|
signature* makeArray(FILE * f, uint32_t* arrlen) {
|
|
|
|
signature* sigs = (signature*) calloc(WORDS, sizeof(signature));
|
|
|
|
char word[WORDLEN + sizeof(char)]; // 5 letters + \n
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
while (fread(word, sizeof(char), WORDLEN + sizeof(char), f) != 0) {
|
|
|
|
#if PRINT_INTERMEDIATES
|
|
|
|
rawWC++;
|
|
|
|
#endif
|
|
|
|
// only get sign so far, more efficient
|
|
|
|
uint32_t s = getsig(word);
|
|
|
|
if (s != 0) {
|
|
|
|
// no duplicate word letters in word
|
2022-10-06 18:11:26 -04:00
|
|
|
memcpy(sigs[i].word, word, 5);
|
2022-09-23 16:11:08 -04:00
|
|
|
sigs[i].sign = s;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*arrlen = i;
|
|
|
|
return sigs;
|
|
|
|
}
|
|
|
|
|
2022-09-26 10:31:09 -04:00
|
|
|
void printDashed(const uint32_t n) {
|
2022-09-11 19:04:40 -04:00
|
|
|
for (uint32_t i = A_BIT; i < Z_BIT; i <<= 1) {
|
|
|
|
if (i & n) {
|
|
|
|
char c = 'A';
|
2022-09-23 16:11:08 -04:00
|
|
|
uint32_t bit = A_BIT;
|
|
|
|
while (bit < i) {
|
2022-09-11 19:04:40 -04:00
|
|
|
c++;
|
2022-09-23 16:11:08 -04:00
|
|
|
bit <<= 1;
|
2022-09-11 19:04:40 -04:00
|
|
|
}
|
|
|
|
putchar(c);
|
|
|
|
} else {
|
|
|
|
putchar('-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 10:31:09 -04:00
|
|
|
void printsigs(signature* restrict sigs, uint32_t nitems, ...) {
|
2022-09-11 19:04:40 -04:00
|
|
|
va_list args;
|
|
|
|
va_start(args, nitems);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < nitems; i++) {
|
|
|
|
uint32_t index = va_arg(args, uint32_t);
|
|
|
|
signature s = sigs[index];
|
|
|
|
printDashed(s.sign);
|
2022-09-23 16:11:08 -04:00
|
|
|
printf(": %s : %-4d\n", s.word, index);
|
2022-09-11 19:04:40 -04:00
|
|
|
}
|
2022-09-23 16:11:08 -04:00
|
|
|
putchar('\n');
|
2022-09-11 19:04:40 -04:00
|
|
|
|
|
|
|
va_end(args);
|
2022-09-10 14:01:13 -04:00
|
|
|
}
|