<commit_before>#pragma once

#include <vector>
#include <cstring>

using std::cout;
using std::endl;

class Solution {
public:
    using vector = std::vector<int>;

    int strStr(char* T, char* P) {
        vector overlap;
        buildOverlapTable(P, overlap);

        cout << overlap << endl;

        return -1;
    }

private:
    void buildOverlapTable(char* needle, vector& table) {
        table.clear();

        if (needle[0] == '\0') {
            return;
        }

        table.push_back(-1);

        if (needle[1] == '\0') {
            return;
        }

        table.push_back(0);

        // Table constructing magic
        {
            int cnd{};
<commit_msg>implemented KMP match function<commit_after>#pragma once

#include <vector>
#include <cstring>

using std::cout;
using std::endl;

class Solution {
public:
    using vector = std::vector<int>;

    int strStr(char* T, char* P) {
        vector overlap;
        buildOverlapTable(P, overlap);

        const auto length = strlen(T), end = overlap.size() - 1;

        for (int m{}, i{}; m + i < length;) {
            if (P[i] == T[m + i]) {
                if (i == end) {
                    return m;
                }
                ++i;
            } else {
                if (overlap[i] > -1) {
                    m += i - overlap[i];
                    i = overlap[i];
                } else {
                    i = 0;
                    ++m;
                }
            }
        }

        return -1;
    }

private:
    void buildOverlapTable(char* needle, vector& table) {
        table.clear();

        if (needle[0] == '\0') {
            return;
        }

        table.push_back(-1);

        if (needle[1] == '\0') {
            return;
        }

        table.push_back(0);

        // Table constructing magic
        {
            int cnd{};

{'fraction_non_alphanumeric': 0.13584905660377358, 'fraction_numerical': 0.009164420485175202, 'mean_word_length': 1.314214463840399, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '806483', 'n_tokens_mistral': 589, 'n_tokens_neox': 553, 'n_words': 141}