-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from siro53/pysan3
ahocorasick
- Loading branch information
Showing
13 changed files
with
136 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
grpwk | ||
distance | ||
result | ||
*.sh | ||
*.py | ||
!analyze.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
PROG = grpwk | ||
OBJS = test_ahocorasick.o ahocorasick.o ahotrie.o ahotext.o queue.o | ||
CC = gcc | ||
CFLAGS = -W -Wall -Wextra -Wconversion -Wshadow | ||
LDFLAGS = | ||
|
||
.SUFFIXES: .c | ||
|
||
$(PROG): $(OBJS) | ||
$(CC) $(LDFLAGS) -o $(PROG) $^ | ||
.c.o: | ||
$(CC) $(CFLAGS) -c $< | ||
clean: | ||
rm $(OBJS) $(PROG) | ||
FILES = $(shell gcc test_distance.c -o distance | find ./ \( -name "*.c" \) \( -not -name "*test*" \)) | ||
default: | ||
$(CC) $(CFLAGS) -o $(PROG) $(FILES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#pragma once | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "grpwk.h" | ||
|
||
char *grpwk(const string_s t, const string_s s[], int len) { | ||
char *str = (char *)malloc(sizeof(char) * 100); | ||
sprintf(str, "I got %d data!", len); | ||
|
||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include "../string_s.h" | ||
|
||
char *grpwk(const string_s t, const string_s s[], int len); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include "string_s.h" | ||
|
||
// change here to include your files!! | ||
#include "example/grpwk.h" | ||
|
||
int main_prg(int, char **); | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
__clock_t c_start, c_end; | ||
|
||
c_start = clock(); | ||
main_prg(argc, argv); | ||
c_end = clock(); | ||
|
||
printf("%f\n", (double)(c_end - c_start) / CLOCKS_PER_SEC); | ||
return (0); | ||
} | ||
|
||
int main_prg(int argc, char **argv) | ||
{ | ||
assert(argc == 3); | ||
FILE *fp_in = fopen(argv[1], "r"); | ||
assert(fp_in != NULL); | ||
FILE *fp_out = fopen(argv[2], "w"); | ||
assert(fp_out != NULL); | ||
|
||
string_s t, s[50000]; | ||
|
||
// input t | ||
fscanf(fp_in, "%s", t.str); | ||
t.len = strlen(t.str); | ||
|
||
// input s[] | ||
int i = 0; | ||
while (~fscanf(fp_in, "%s", s[i].str)) s[i++].len = strlen(s[i].str); | ||
|
||
fprintf(fp_out, "%s\n", grpwk(t, s, i)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
typedef struct { | ||
char str[120]; | ||
int len; | ||
} string_s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
FILE *fp_in = fopen(argv[1], "r"); | ||
assert(fp_in != NULL); | ||
FILE *fp_out = fopen(argv[2], "r"); | ||
assert(fp_out != NULL); | ||
|
||
char in[500000], out[500000]; | ||
fscanf(fp_in, "%s", in); | ||
fscanf(fp_out, "%s", out); | ||
|
||
int counter = 0; | ||
for (int i=0; i<strlen(in); i++) counter += (in[i] != out[i]); | ||
counter += abs(strlen(in) - strlen(out)); | ||
|
||
printf("edit distance: %d\n", counter); | ||
|
||
return 0; | ||
} |