Skip to content

Commit 00596b1

Browse files
committed
fix: merge conflict
2 parents 587bfec + 0a512e7 commit 00596b1

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CC = gcc
22
CFLAGS = -I. -Wall -g
33
RM = rm -f
4-
DEPS = trie_tm.h trie_ht.h
4+
OBJ = tp1.o trie-tm.o trie-hashtable.o search.o
5+
DEPS = trie-tm.h trie-hashtable.h search.h
56

67
# Compiling to object files without linking
78
%.o: %.c $(DEPS)
@@ -13,6 +14,9 @@ trie_tm: main_tm.o trie_tm.o
1314
trie_ht: main_ht.o trie_ht.o
1415
$(CC) -o trie_ht main_ht.o trie_ht.o $(CFLAGS)
1516

17+
search: search.o
18+
$(CC) -o search search.o $(CFLAGS)
19+
1620
.PHONY: clean
1721

1822
clean:

search.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include "search.h"
4+
5+
int bruteFS1(const char *text, const char *pattern) {
6+
int n = strlen(text);
7+
int m = strlen(pattern);
8+
9+
for(int i = 0; i <= n - m; i++) {
10+
int j = 0;
11+
while(j <= m - 1 && pattern[j] == text[i+j]) {
12+
j++;
13+
}
14+
if(j == m) {
15+
return i;
16+
}
17+
}
18+
return -1;
19+
}
20+
21+
int bruteFS2(const char*text, const char* pattern) {
22+
int n = strlen(text);
23+
int m = strlen(pattern);
24+
25+
const char c = pattern[0];
26+
27+
int i = 0;
28+
while(i <= n - m && text[i] != c) {
29+
i++;
30+
}
31+
32+
while(i <= n - m) {
33+
int j = 0;
34+
while(j <= m - 1 && pattern[j] == text[i+j]) {
35+
j++;
36+
}
37+
if(j == m) {
38+
return i;
39+
}
40+
i++;
41+
}
42+
return -1;
43+
}
44+
45+
int searchWithHelperFunc1(const char*text, const char *pattern) {
46+
int n = strlen(text);
47+
int m = strlen(pattern);
48+
49+
50+
return strncmp(pattern, text, m);
51+
52+
53+
54+
55+
56+
}
57+
int searchWithHelperFunc2(const char*text, const char *pattern){
58+
int n = strlen(text);
59+
int m = strlen(pattern);
60+
61+
const char c = pattern[0];
62+
63+
int i = 0;
64+
while(i <= n - m && text[i] != c) {
65+
i++;
66+
}
67+
68+
return -1;
69+
70+
}
71+
72+
int mp(const char *text, const char *pattern) {
73+
int n = strlen(text);
74+
int m = strlen(pattern);
75+
76+
// Pre-processing: construct bonPref table
77+
78+
// Double loop: use bonPref table to skip comparaisons
79+
80+
}
81+
82+
int kmp(const char *text, const char *pattern) {
83+
int n = strlen(text);
84+
int m = strlen(pattern);
85+
86+
// Pre-processing: construct MeilPref table
87+
88+
// Double loop: use bonPref table to skip comparaisons
89+
90+
}
91+
int main() {
92+
93+
const char *text = "abcabcbabcabcabcaa";
94+
const char *pattern = "bcaa";
95+
96+
// printf("bruteForce: %d\n", bruteFS1(text, pattern));
97+
printf("bruteForce: %d\n", searchWithHelperFunc1(text, pattern));
98+
99+
100+
return 0;
101+
}

search.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef HEADER_SEARCH
2+
#define HEADER_SEARCH
3+
4+
5+
/**
6+
*
7+
* Brute force algorithm, no fast loop & no sentinelle.
8+
*/
9+
int bruteFS1(const char *text, const char *pattern);
10+
/**
11+
*
12+
* Brute force algorithm, with fast loop & no sentinelle.
13+
*/
14+
int bruteFS2(const char *text, const char *pattern);
15+
/**
16+
*
17+
* Brute force algorithm, with fast loop & sentinelle.
18+
*/
19+
int bruteFS3(const char *text, const char *pattern);
20+
21+
/**
22+
* Brute force algorithm, with strncmp, no fast loop
23+
*/
24+
int searchWithHelperFunc1(const char*text, const char *pattern);
25+
/**
26+
* Brute force algorithm, with strncmp, with fast loop
27+
*/
28+
int searchWithHelperFunc2(const char*text, const char *pattern);
29+
30+
int mp(const char *text, const char *pattern);
31+
int kmp(const char *text, const char *pattern);
32+
int boyer_moore(const char *text, const char *pattern);
33+
int harspool(const char *text, const char *pattern);
34+
int quick_search(const char *text, const char *pattern);
35+
36+
#endif

0 commit comments

Comments
 (0)