Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
wildcard_matching.cpp File Reference

Implementation of the Wildcard Matching problem. More...

#include <cassert>
#include <iostream>
#include <vector>
Include dependency graph for wildcard_matching.cpp:

Namespaces

 backtracking
 Backtracking algorithms.
 
 wildcard_matching
 Functions for the Wildcard Matching problem.
 

Functions

bool backtracking::wildcard_matching::wildcard_matching (std::string s, std::string p, uint32_t pos1, uint32_t pos2)
 
static void test ()
 Self-test implementations. More...
 
int main ()
 Main function. More...
 

Variables

std::vector< std::vector< int64_t > > backtracking::wildcard_matching::dpTable (1000, std::vector< int64_t >(1000, -1))
 The main function implements if pattern can be matched with given string. More...
 

Detailed Description

Implementation of the Wildcard Matching problem.

Given a matching string and a pattern, implement wildcard pattern matching with support for ? and *. ? matches any single character. * matches any sequence of characters (including the empty sequence). The matching should cover the entire matching string (not partial). The task is to determine if the pattern matches with the matching string

Author
Swastika Gupta

Function Documentation

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
152  {
153  test(); // run self-test implementations
154  return 0;
155 }
static void test()
Self-test implementations.
Definition: wildcard_matching.cpp:101
Here is the call graph for this function:

◆ test()

static void test ( )
static

Self-test implementations.

Returns
void
101  {
102  // 1st test
103  std::cout << "1st test ";
104  std::string matching1 = "baaabab";
105  std::string pattern1 = "*****ba*****ab";
106  assert(backtracking::wildcard_matching::wildcard_matching(matching1,
107  pattern1, 0, 0) ==
108  1); // here the pattern matches with given string
109  std::cout << "passed" << std::endl;
110 
111  // 2nd test
112  std::cout << "2nd test ";
113  std::string matching2 = "baaabab";
114  std::string pattern2 = "ba*****ab";
115  assert(backtracking::wildcard_matching::wildcard_matching(matching2,
116  pattern2, 0, 0) ==
117  1); // here the pattern matches with given string
118  std::cout << "passed" << std::endl;
119 
120  // 3rd test
121  std::cout << "3rd test ";
122  std::string matching3 = "baaabab";
123  std::string pattern3 = "ba*ab";
124  assert(backtracking::wildcard_matching::wildcard_matching(matching3,
125  pattern3, 0, 0) ==
126  1); // here the pattern matches with given string
127  std::cout << "passed" << std::endl;
128 
129  // 4th test
130  std::cout << "4th test ";
131  std::string matching4 = "baaabab";
132  std::string pattern4 = "a*ab";
133  assert(backtracking::wildcard_matching::wildcard_matching(matching4,
134  pattern4, 0, 0) ==
135  1); // here the pattern matches with given string
136  std::cout << "passed" << std::endl;
137 
138  // 5th test
139  std::cout << "5th test ";
140  std::string matching5 = "baaabab";
141  std::string pattern5 = "aa?ab";
142  assert(backtracking::wildcard_matching::wildcard_matching(matching5,
143  pattern5, 0, 0) ==
144  1); // here the pattern matches with given string
145  std::cout << "passed" << std::endl;
146 }
T endl(T... args)

Variable Documentation

◆ dpTable

std::vector<std::vector<int64_t> > backtracking::wildcard_matching::dpTable(1000, std::vector< int64_t >(1000, -1)) ( 1000  ,
std::vector< int64_t >  1000, -1 
)

The main function implements if pattern can be matched with given string.

Parameters
sis the given matching string
pis the given pattern
pos1is the starting index
pos2is the last index
Returns
1 if pattern matches with matching string otherwise 0