X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fkmp.h;h=8c8c525448f148f5b7ab9495415752e6736e8d86;hb=029a7f6703b0a0a102f7dff6c25ff1d419d75610;hp=f4d14049235081ab90cf1c5123e87db1a2384d0d;hpb=cea5b11fa465e902552c06a54e1b1255f8b71fd5;p=libucw.git diff --git a/lib/kmp.h b/lib/kmp.h index f4d14049..8c8c5254 100644 --- a/lib/kmp.h +++ b/lib/kmp.h @@ -16,12 +16,12 @@ * * This file contains only construction of the automaton. The search * itself can be generated by inclusion of file lib/kmp-search.h. - * Separeted headers allows the user to define multiple search + * Separeted headers allow the user to define multiple search * routines for one common set of key strings. * * Example: * - * #define KMP_PREFIX(x) GLUE_(kmp,x) + * #define KMP_PREFIX(x) kmp_##x * #define KMP_WANT_CLEANUP * #define KMP_WANT_SEARCH // includes lib/kmp-search.h automatically * #define KMPS_FOUND(kmp,src,s) printf("found\n") @@ -51,14 +51,14 @@ * Basic parameters: * KMP_PREFIX(x) macro to add a name prefix (used on all global names * defined by the KMP generator); mandatory; - * below we use P(x) alias + * we abbreviate this to P(x) below * * KMP_CHAR alphabet type, the default is u16 - * - * KMP_SOURCE user-defined text source; KMP_GET_CHAR must + * + * KMP_SOURCE user-defined text source; KMP_GET_CHAR must * KMP_GET_CHAR(kmp,src,c) return zero at the end or nonzero together with the next character in c otherwise; * if not defined, zero-terminated array of bytes is used as the input - * + * * KMP_VARS user-defined variables in 'struct P(struct)' * -- a structure describing the whole automaton; * these variables are stored in .u substructure to avoid collisions @@ -131,15 +131,15 @@ typedef struct {} P(node_t); struct P(struct); struct P(state) { - struct P(state) *from; /* state with previous character (forms a tree with null state in the root) */ + struct P(state) *from; /* state with the previous character (forms a tree with null state in the root) */ struct P(state) *back; /* backwards edge to the longest shorter state with same suffix */ - struct P(state) *next; /* longest shorter match (or NULL) */ + struct P(state) *next; /* the longest of shorter matches (or NULL) */ P(len_t) len; /* state depth if it represents a key string, zero otherwise */ - P(char_t) c; /* last character of represented string */ + P(char_t) c; /* last character of the represented string */ struct { # ifdef KMP_STATE_VARS KMP_STATE_VARS -# endif +# endif } u; /* user-defined data*/ }; @@ -168,7 +168,7 @@ P(hash_hash) (struct P(hash_table) *t, struct P(state) *f, P(char_t) c) static inline uns P(hash_hash) (struct P(hash_table) *t UNUSED, struct P(state) *f, P(char_t) c) { - return (((uns)c) << 16) + (uns)(addr_int_t)f; + return (((uns)c) << 16) + (uns)(uintptr_t)f; } #endif @@ -213,10 +213,10 @@ static inline void P(hash_init_key) (struct P(hash_table) *t UNUSED, struct P(state) *s, struct P(state) *f, P(char_t) c) { bzero(s, sizeof(*s)); -# ifdef KMP_INIT_STATE +# ifdef KMP_INIT_STATE struct P(struct) *kmp = (struct P(struct) *)t; { KMP_INIT_STATE(kmp, s); } -# endif +# endif s->from = f; s->c = c; s->next = f->back; /* the pointers hold the link-list of sons... changed in build() */ @@ -224,7 +224,7 @@ P(hash_init_key) (struct P(hash_table) *t UNUSED, struct P(state) *s, struct P(s } #undef P -#define HASH_PREFIX(x) KMP_PREFIX(GLUE(hash_,x)) +#define HASH_PREFIX(x) KMP_PREFIX(hash_##x) #define HASH_NODE struct KMP_PREFIX(state) #define HASH_KEY_COMPLEX(x) x from, x c #define HASH_KEY_DECL struct KMP_PREFIX(state) *from, KMP_PREFIX(char_t) c @@ -256,7 +256,7 @@ struct P(struct) { #ifdef KMP_SOURCE typedef KMP_SOURCE P(source_t); #else -typedef byte *P(source_t); +typedef char *P(source_t); #endif #ifdef KMP_GET_CHAR @@ -281,13 +281,13 @@ P(get_char) (struct P(struct) *kmp UNUSED, P(source_t) *src, P(char_t) *c) { # ifdef KMP_USE_UTF8 uns cc; - *src = (byte *)utf8_get(*src, &cc); + *src = utf8_get(*src, &cc); # ifdef KMP_ONLYALPHA if (!cc) {} else if (!Ualpha(cc)) cc = P(control)(); else -# endif +# endif { # ifdef KMP_TOLOWER cc = Utolower(cc); @@ -402,7 +402,7 @@ P(build) (struct P(struct) *kmp) null->back = NULL; # ifdef KMP_BUILD_STATE { KMP_BUILD_STATE(kmp, null); } -# endif +# endif while (read != write) { struct P(state) *s = fifo[read++], *t; @@ -425,7 +425,7 @@ P(build) (struct P(struct) *kmp) } # ifdef KMP_BUILD_STATE { KMP_BUILD_STATE(kmp, s); } -# endif +# endif } }