Question String matching algorithm

xiaoxiao2021-03-06  55

The String class provides methods of finding substrings, including IndexOf (String Str), IndexOf (String Str, INT fromNDEX), LastIndexOf (String Str), LastIndexof (String Str, Int fromNDEX). I am very surprised why it is a low efficiency of the normal algorithm without using an efficient KMP algorithm. I remember the algorithm when I learned the data structure. The following is a String implementation code: static int indexOf (char [] source, int sourceOffset, int sourceCount, char [] target, int targetOffset, int targetCount, int fromIndex) {if (fromIndex> = sourceCount) {return (targetCount == 0? Sourcecount: -1);} if (fromNDEX <0) {fromNDEX = 0;} if (targetcount == 0) {Return fromNDEX;

Char first = target [targetoffset]; int i = sourceoffset fromNDEX; int max = sourceoffset (SourceCount - TargetCount);

StartSearchForfirstchar: while (true) {/ * look for first character. * / while (i <= max && source [i]! = first) {i ;} if (i> max) {return -1;}

/ * Found First Character, NOW LOOK AT THE REST OF V2 * / INT J = I 1; int end = j targetcount - 1; int K = targetoffset 1; while (j

转载请注明原文地址:https://www.9cbs.com/read-114137.html

New Post(0)