TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
String search algorithms. More...
Functions | |
int | brute_force (const std::string &text, const std::string &pattern) |
std::vector< size_t > | getFailureArray (const std::string &pattern) |
Generate the partial match table aka failure function for a pattern to search. | |
size_t | kmp (const std::string &pattern, const std::string &text) |
KMP algorithm to find a pattern in a text. | |
int64_t | create_hash (const std::string &s, int n) |
int64_t | recalculate_hash (const std::string &s, int old_index, int new_index, int64_t old_hash, int patLength) |
bool | check_if_equal (const std::string &str1, const std::string &str2, int start1, int end1, int start2, int end2) |
int | rabin_karp (const std::string &str, const std::string &pat) |
String search algorithms.
for assert for IO operations for std::string for std::vector
int string_search::brute_force | ( | const std::string & | text, |
const std::string & | pattern ) |
Find a pattern in a string by comparing the pattern to every substring.
text | Any string that might contain the pattern. |
pattern | String that we are searching for. |
Definition at line 21 of file brute_force_string_searching.cpp.
bool string_search::check_if_equal | ( | const std::string & | str1, |
const std::string & | str2, | ||
int | start1, | ||
int | end1, | ||
int | start2, | ||
int | end2 ) |
compare if two sub-strings are equal
[in] | str1 | string pattern to search |
[in] | str2 | text in which to search |
[in] | start1,end1 | start and end indices for substring in str1 |
[in] | start2,end2 | start and end indices for substring in str2 |
true
if pattern was found false
if pattern was not found Definition at line 60 of file rabin_karp.cpp.
int64_t string_search::create_hash | ( | const std::string & | s, |
int | n ) |
convert a string to an intger - called as hashing function
[in] | s | source of string to hash |
[in] | n | length of substring to hash |
Definition at line 25 of file rabin_karp.cpp.
std::vector< size_t > string_search::getFailureArray | ( | const std::string & | pattern | ) |
Generate the partial match table aka failure function for a pattern to search.
pattern | text for which to create the partial match table |
Definition at line 32 of file knuth_morris_pratt.cpp.
size_t string_search::kmp | ( | const std::string & | pattern, |
const std::string & | text ) |
KMP algorithm to find a pattern in a text.
pattern | string pattern to search |
text | text in which to search |
std::string::npos
if not found Definition at line 53 of file knuth_morris_pratt.cpp.
int string_search::rabin_karp | ( | const std::string & | str, |
const std::string & | pat ) |
Perform string pattern search using Rabin-Karp algorithm
[in] | str | string to search in |
[in] | pat | pattern to search for |
Definition at line 83 of file rabin_karp.cpp.
int64_t string_search::recalculate_hash | ( | const std::string & | s, |
int | old_index, | ||
int | new_index, | ||
int64_t | old_hash, | ||
int | patLength ) |
re-hash a string using known existing hash
[in] | s | source of string to hash |
[in] | old_index | previous index of string |
[in] | new_index | new index of string |
[in] | old_hash | previous hash of substring |
[in] | patLength | length of substring to hash |
Definition at line 42 of file rabin_karp.cpp.