#include #include #include char *kmp_search(char *haystack, size_t haystack_size, char *needle, size_t needle_size); int64_t T[1024]; char *kmp_search(char *haystack, size_t haystack_size, char *needle, size_t needle_size) { //int *T; int64_t i, j; char *result = NULL; if (needle_size==0) return haystack; /* Construct the lookup table */ //T = (int*) malloc((needle_size+1) * sizeof(int)); T[0] = -1; for (i=0; i 0 && needle[i] != needle[T[i+1]-1]) T[i+1] = T[T[i+1]-1] + 1; } /* Perform the search */ for (i=j=0; i