wordle-algorithm/boilerplate.h

75 lines
2.0 KiB
C

#include <stdint.h>
#include <stdarg.h>
#if PRINT_INTERMEDIATES
uint32_t rawWC = 0;
#endif
#if TIME_SECTIONS
#include <time.h>
clock_t start, end;
double section_time;
char * curr_section;
#define START_TIME(section_name) do {\
curr_section = section_name;\
fprintf(stderr, "BEGIN %s\n", curr_section);\
start = clock();\
} while (0);
#define END_TIME do {\
end = clock();\
section_time = ((double) (end - start)) / CLOCKS_PER_SEC;\
fprintf(stderr, "END %s, %fs\n\n", curr_section, section_time);\
} while (0);
#else
// TIME_SECTIONS not specified, define to be nothing
#define START_TIME(section_name) 0;
#define END_TIME 0;
#endif
/* <defines> */
#define WORDS 12971u
#define WORDLEN 5u
#define CHARMASK ~0b1100000u
#define A_BIT 0b10u
#define Z_BIT (A_BIT << 26)
#define MAX(a,b) ((a > b) ? a : b)
#if PRINT_INTERMEDIATES
#if FANCYPRINT
#define PRINT2 printsigs(sigs, 2, i1, i2);
#define PRINT3 printsigs(sigs, 3, i1, i2, i3);
#define PRINT4 printsigs(sigs, 4, i1, i2, i3, i4);
#else
#define PRINT2 printf("%s, %s\n", sigs[i1], sigs[i2]);
#define PRINT3 printf("%s, %s, %s\n", sigs[i1], sigs[i2], sigs[i3]);
#define PRINT4 printf("%s, %s, %s, %s\n", sigs[i1], sigs[i2], sigs[i3], sigs[i4]);
#endif
#else
#define PRINT2 0;
#define PRINT3 0;
#define PRINT4 0;
#endif
/* </defines> */
typedef struct signature {
char word[5];
uint32_t sign;
} signature;
/* <declarations> */
signature* makeArray(FILE *, uint32_t*);
uint32_t getsig(char* restrict);
int compare(const void*, const void*);
uint32_t rmdups(signature* restrict, const uint32_t);
void findWords(signature* restrict, const uint32_t);
void printsigs(signature* restrict, const uint32_t, ...);
void printDashed(const uint32_t);
/* </declarations> */