1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
|