Completed
Push — master ( cf35a6...401678 )
by Xianshun
01:24
created

BruteForceSubstringSearch   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B search_in() 0 14 5
A __init__() 0 2 1
1
from abc import ABCMeta, abstractmethod
2
3
4
class SubstringSearch(object):
5
    __metaclass__ = ABCMeta
6
7
    @abstractmethod
8
    def search_in(self, text):
9
        pass
10
11
12
class BruteForceSubstringSearch(SubstringSearch):
13
    def __init__(self, pattern):
14
        self.pattern = pattern
15
16
    def search_in(self, text):
17
        n = len(text)
18
19
        for i in range(n - len(self.pattern)):
20
            J = i
21
            for j in range(len(self.pattern)):
22
                k = i + j
23
                if text[k] != self.pattern[j]:
24
                    J = -1
25
                    break
26
            if J != -1:
27
                return J
28
29
        return -1
30