diff options
Diffstat (limited to '')
| -rw-r--r-- | common.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/common.h b/common.h new file mode 100644 index 0000000..0e132a1 --- /dev/null +++ b/common.h @@ -0,0 +1,45 @@ +/* See LICENSE file for copyright and license details. */ +#include "libautomata.h" + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + + +#define sizeof_flexstruct(STRUCT, MEMBER, COUNT)\ + (offsetof(STRUCT, MEMBER) + (COUNT) * sizeof(*((STRUCT *)NULL)->MEMBER)) + + +#define sizeof_kmp_automaton(LENGTH, ELEMSIZE)\ + (sizeof_flexstruct(struct libautomata_kmp_automaton, next, (LENGTH) + 1U) + (LENGTH) * (ELEMSIZE)) +struct libautomata_kmp_automaton { + size_t position; + size_t length; + size_t elemsize; + size_t next[/* .length + 1U */]; + /* char pattern[.length * .elemsize] */ +}; + + +#define sizeof_mp_automaton(LENGTH, ELEMSIZE)\ + (sizeof_flexstruct(struct libautomata_mp_automaton, next, (LENGTH) + 1U) + (LENGTH) * (ELEMSIZE)) +struct libautomata_mp_automaton { + size_t position; + size_t length; + size_t elemsize; + size_t next[/* .length + 1U */]; + /* char pattern[.length * .elemsize] */ +}; + + +#ifdef TEST +# include <stdio.h> +# define MEM(STR) STR, (sizeof(STR) - 1U) +# define EXPECT(EXPR)\ + do {\ + if (EXPR)\ + break;\ + fprintf(stderr, "Assertion failed at %s:%i: %s\n", __FILE__, __LINE__, #EXPR);\ + exit(1);\ + } while (0) +#endif |
