From ae89f342b51cb4ef71f18e89b74585cd61b05a60 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 17 Dec 2025 16:20:43 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 common.h (limited to 'common.h') 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 +#include +#include + + +#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 +# 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 -- cgit v1.2.3-70-g09d2