License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Hi Mr. Handy,
it is so good to see etude developers in C, don't know how but I haven't seen your function until three-four days ago.

I postponed all my activities in attempt to come up with some gem.
Last night you kicked my ass, my amateurish interests in wildcard matching led me to writing my own (in fact a semi-port of Igor Pavlov's code) function.
I did my next-to-better to make it superfast, in which I succeeded, but failed to outperform yours, your function is faster than mine both for short and long strings. BRAVO!

I already have had a wildcard searcher working just fine, a very versatile one, but slow. Therefore I added a FAST add-on to my 3-in-1 searcher Kazahana thus allowing VERSATILE (9 wildcards) and FAST (the classic 2 wildcards) modes. I also tested mine vs yours using 2 threads, in short they are really fast, the 2 threads utilize 180-192% the CPU achieving 140-170MB/s TOTAL traversal speed, see further below.

Having failed to "kick your ass" I bend a knee before you, but only temporarily, I need more time to clear my sight, in the meantime it would be nice some real programmer(s) to help me to speed up my etude.
If you can speed up my function, please do so, I will appreciate your widemindedness. Dethroning your own with your own is a sweety feeling.

Since I am fond of benchmarking and endless results logs, you are welcome to my Kazahana dedicated article to see them.

Being an UFC fan I see my defeat in the light of Johny Hendricks defeat by the champion Georges St-Pierre some weeks ago. Johny rocks, I like his style, his interviews are worth seeing as:Johny Hendricks: "I Am the Champion" (UFC 167 Post-Press Conference)

Best,
Georgi 'Kaze'

P.S.
I couldn't help it, just some of them:

The big benchmark, searching all lines in Wikipedia 1024MB dump:
My function is used in executable: Kazahana_r1-++fix+nowait_critical_nixFIX_WolfRAM+fixITER_HEXADECAD-Threads_IntelV12.exe
Your function is used in executable: Kazahana_r1-++fix+nowait_critical_nixFIX_WolfRAM+fixITER_HEXADECAD-Threads_IntelV12_JH.exe

I read this article " ,its really amazing. I appreciate your efforts. I am student, I need help in defining the same kind of function according to my requirements. I hope, I 'll get good response.

Words are strings which are separated by dots. Two additional characters are also valid i.e:The *, which matches 1 word and the #, which matches 0..N words Example: *.stock.# matches the routing keys usd.stock and eur.stock.dsf but not stock.nasdaq.

First of all I like this code, it is small and fully stand-alone.
I have modified it, because I need an additional wildcard joker that represents digits. Finally the modified function accepts '*', '?' and '#' as joker characters.

publicclass MString
{
///<summary>/// Function to compare two strings, where strA may contain wildcard characters '*' and
/// '?'. http://en.wikipedia.org/wiki/Wildcard_character
///</summary>///<paramname="strA">string which may contain wildcards, may be empty, must not be null</param>///<paramname="strB">string to compare to, no wildcard processing, may be empty, must not be null</param>///<paramname="ignoreCase">true = ignore upper/lower case, false = don't ignore case</param>///<returns>true = match, false = non-match</returns>publicstaticbool CompareWWc(string strA, string strB, bool ignoreCase)
{
if (ignoreCase)
return CompareWWc(strA.ToLower(), strB.ToLower());
elsereturn CompareWWc(strA, strB);
}
///<summary>/// Recursive function to compare two strings, where strA may contain wildcard characters
/// '*' and '?'. http://en.wikipedia.org/wiki/Wildcard_character
///</summary>///<paramname="strA">string which may contain wildcards, may be empty, must not be null</param>///<paramname="strB">string to compare to, no wildcard processing, may be empty, must not be null</param>///<returns>true = match, false = non-match</returns>publicstaticbool CompareWWc(string strA, string strB)
{
// Top of loop to scan across strA (and strB)
for (int i = 0; i < strA.Length; i++)
{
// Special processing when we hit a '*' in strA
if (strA[i] == '*')
{
// If the '*' is at the end of strA then result = true irrespective of strB
if (i == strA.Length - 1)
returntrue;
// Do recursive calls to try to find a match somewhere to the right in strB
strA = strA.Substring(i + 1); // The part of strA beyond the '*'
for (int j = i; j < strB.Length; j++)
if (CompareWWc(strA, strB.Substring(j)))
returntrue;
returnfalse;
}
// Normal processing for non-'*' characters in strA
if (i >= strB.Length || (strA[i] != strB[i] && strA[i] != '?'))
returnfalse;
}
// We've reached the end of strA and the last character is not '*'
return strA.Length == strB.Length;
}
}