Use char instead of int for FSA rule input
This commit is contained in:
parent
852102cab9
commit
eb22abfb1b
@ -47,11 +47,10 @@ int fsa_add_state(fsa_t *fsa)
|
|||||||
return fsa->count++;
|
return fsa->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsa_add_rule(fsa_t *fsa, int from, int to, int input)
|
void fsa_add_rule(fsa_t *fsa, int from, int to, char input)
|
||||||
{
|
{
|
||||||
assert(fsa->count > from);
|
assert(fsa->count > from);
|
||||||
assert(fsa->count > to);
|
assert(fsa->count > to);
|
||||||
assert(input < ALPHABET_SIZE);
|
|
||||||
|
|
||||||
fsa_state_t *state = &fsa->states[from];
|
fsa_state_t *state = &fsa->states[from];
|
||||||
if (state->count >= state->capacity) {
|
if (state->count >= state->capacity) {
|
||||||
|
@ -8,14 +8,9 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define CHAR_COUNT 256
|
|
||||||
#define ALPHABET_SIZE (CHAR_COUNT + 1)
|
|
||||||
|
|
||||||
// Use one more than any valid char to represent empty string
|
|
||||||
#define EPSILON CHAR_COUNT
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int input, next;
|
int next;
|
||||||
|
char input;
|
||||||
} fsa_rule_t;
|
} fsa_rule_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -33,6 +28,6 @@ void fsa_init(fsa_t *fsa);
|
|||||||
void fsa_free(const fsa_t *fsa);
|
void fsa_free(const fsa_t *fsa);
|
||||||
|
|
||||||
int fsa_add_state(fsa_t *fsa);
|
int fsa_add_state(fsa_t *fsa);
|
||||||
void fsa_add_rule(fsa_t *fsa, int from, int to, int input);
|
void fsa_add_rule(fsa_t *fsa, int from, int to, char input);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user