the helper function for KMP-string-searching is to construct the DFA. pattern should be an integer array. return a 2D array representing the DFA for moving the pattern.
354443
def _kmp_construct_next(self, pattern):
                """"""
                next = [[0 for state in pattern] for input_token in self.ALPHABETA_KMP]
                next[pattern[0]][0] = 1
                restart_state = 0
                for state in range(1, len(pattern)):
                        for input_token in self.ALPHABETA_KMP:
                                next[input_token][state] = next[input_token][restart_state]
                        next[pattern[state]][state] = state + 1
                        restart_state = next[pattern[state]][restart_state]
                return next
982785
def indexOf(self, pattern, start_idx, bitlength):
        
        return StrIndexOf(self, pattern, start_idx, bitlength)
1197233
private ArrayList algorithm1(String S, String T) {
    ArrayList candidateList = new ArrayList();
    int bound = (int) (1.0 / tr);
    for (int t = 0; t < S.length(); t++) {
      char chT = S.charAt(t);
      double lastTr = -1;
      for (int u = Math.max(0, t - bound), flag = 0;
           u < Math.min(t + bound + 1, T.length()) && flag == 0; u++) {
        double tr2 = ( (double) Math.abs(t - u));
        if ( (lastTr >= 0.0) && (lastTr < tr2)) {
          flag = 1;
        }
        else {
          char chU = T.charAt(u);
          double charScore = 0.0;
          if(chT==chU){
            charScore = 1.0;
          }
          if (charScore > 0.0) {
            if (charScore == 1.0) {
              lastTr = tr2;
            }
            charScore = charScore - (tr * tr2);
            if (charScore == 1.0) {
              flag = 1;
            }
            candidateList.add(new TagLink.Candidates(t, u, charScore));
          }
        }
      }
    }
    return candidateList;
  }
1032763
private static int[][] translate(Map<String, Integer> symbol, Map<String, Integer> suffix, String[] o) {
        int[][] seq = new int[o.length][2];
        
        for (int i = 0; i < o.length; i++) {
            Integer index = symbol.get(o[i]);
            if (index != null) {
                seq[i][0] = index;
            } else {
                seq[i][0] = 0;
            }
            
            index = null;
            if (o[i].length() > 2) {
                index = suffix.get(o[i].substring(o[i].length() - 2));
            }            
            if (index != null) {
                seq[i][1] = index;
            } else {
                seq[i][1] = -1;
            }
        }

        return seq;
    }
129862
function HKDF(hashAlg, salt, ikm) {
  if (!(this instanceof HKDF)) { return new HKDF(hashAlg, salt, ikm); }

  this.hashAlg = hashAlg;

  // create the hash alg to see if it exists and get its length
  var hash = crypto.createHash(this.hashAlg);
  this.hashLength = hash.digest().length;

  this.salt = salt || zeros(this.hashLength);
  this.ikm = ikm;

  // now we compute the PRK
  var hmac = crypto.createHmac(this.hashAlg, this.salt);
  hmac.update(this.ikm);
  this.prk = hmac.digest();
}
830039
def find(self, strSeq) :
		""""""
		arr = self.encode(strSeq)
                return self._kmp_find(arr[0], self)
1102587
def mget(self, pat=None):
        
        if pat is None:
            return {}
        expr = re.compile(fnmatch.translate(pat))
        m = {}
        for key in tuple(self.keys()):
            #make sure the key is a str first
            if isinstance(key, string_types):
                if expr.match(key):
                    m[key] = self[key]
        return m
293861
public int exactMatchSearch(char[] keyChars, int pos, int len, int nodePos)
    {
        int result = -1;

        int b = base[nodePos];
        int p;

        for (int i = pos; i < len; i++)
        {
            p = b + (int) (keyChars[i]) + 1;
            if (b == check[p])
                b = base[p];
            else
                return result;
        }

        p = b;
        int n = base[p];
        if (b == check[p] && n < 0)
        {
            result = -n - 1;
        }
        return result;
    }
725940
def string(self, *pattern, **kwargs):
        
        set_defaults(self._kwargs, kwargs)
        set_defaults(self._functional_defaults, kwargs)
        set_defaults(self._defaults, kwargs)
        pattern = self.rebulk.build_string(*pattern, **kwargs)
        part = ChainPart(self, pattern)
        self.parts.append(part)
        return part
1209947
static List<String> parsePattern(String pattern) {
    List<String> parameters = new ArrayList<>(4);
    Matcher matcher = PARAM_REGEX.matcher(pattern);
    while (matcher.find()) {
      parameters.add(matcher.group(1));
    }
    return parameters;
  }
1316751
private String matchPatternInBuffer(Pattern pattern) {
        matchValid = false;
        matcher.usePattern(pattern);
        matcher.region(position, buf.limit());
        if (matcher.lookingAt()) {
            if (matcher.hitEnd() && (!sourceClosed)) {
                // Get more input and try again
                needInput = true;
                return null;
            }
            position = matcher.end();
            return matcher.group();
        }

        if (sourceClosed)
            return null;

        // Read more to find pattern
        needInput = true;
        return null;
    }
451601
def _kmp_search_first(self, pInput_sequence, pPattern):
                """"""
                input_sequence, pattern = pInput_sequence, [len(bin(e)) for e in pPattern]
                n, m = len(input_sequence), len(pattern)
                d = p = 0
                next = self._kmp_construct_next(pattern)
                while d < n and p < m:
                        p = next[len(bin(input_sequence[d]))][p]
                        d += 1
                if p == m: return d - p
                else: return -1
1345959
private static void computeBadByteSkipArray(byte[] pattern, int[] badByteArray) {
        for (int a = 0; a < ALPHABET_SIZE; a++) {
            badByteArray[a] = pattern.length;
        }

        for (int j = 0; j < pattern.length - 1; j++) {
            badByteArray[pattern[j] - Byte.MIN_VALUE] = pattern.length - j - 1;
        }
    }
244232
def to_s( pattern='%l, %f' )
      if pattern.is_a?( Symbol )
        return conversational if pattern == :conversational
        return sortable if pattern == :sortable
        pattern = PREDEFINED_PATTERNS[pattern]
      end

      PATTERN_MAP.inject( pattern ) do |name, mapping|
        name = name.gsub( mapping.first,
                          (send( mapping.last ) || '') )
      end
    end
462632
private Map<String, String> getCustomMap(Pattern keyPattern) {
		Map<String, String> map = new HashMap<>();

		for (Iterator<Object> it = props.keySet().iterator(); it.hasNext();) {
			String key = (String) it.next();
			Matcher matcher = keyPattern.matcher(key);
			if (matcher.matches()) {

				String id = matcher.group(2);
				String propertyValue = props.getProperty(key);
				map.put(id, propertyValue);
			}
		}
		return map;
	}
95034
function () {
    var pattern = /\{(\d+)\}/g;
    //safer way to convert a pseudo array to an object array
    var args = Array.prototype.slice.call(arguments);
    var s = args.shift();
    return s.replace(pattern, function(c, d) {
      var replacement = args[d] ;
      if (lib.isNull(replacement)) {
        replacement = "";
      }
      return replacement;
    });
  }
382789
public static Object find(String strPattern, String strInput, int offset, boolean caseSensitive, boolean matchAll) throws MalformedPatternException {
	Perl5Matcher matcher = new Perl5Matcher();
	PatternMatcherInput input = new PatternMatcherInput(strInput);
	Array matches = new ArrayImpl();

	int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
	compileOptions += Perl5Compiler.SINGLELINE_MASK;
	if (offset < 1) offset = 1;

	Pattern pattern = getPattern(strPattern, compileOptions);

	if (offset <= strInput.length()) {
	    input.setCurrentOffset(offset - 1);

	    while (matcher.contains(input, pattern)) {
		Struct matchStruct = getMatchStruct(matcher.getMatch());
		if (!matchAll) {
		    return matchStruct;
		}

		matches.appendEL(matchStruct);
	    }

	    if (matches.size() != 0) {
		return matches;
	    }
	}

	Array posArray = new ArrayImpl();
	Array lenArray = new ArrayImpl();
	Array matchArray = new ArrayImpl();
	posArray.appendEL(Constants.INTEGER_0);
	lenArray.appendEL(Constants.INTEGER_0);
	matchArray.appendEL("");

	Struct struct = new StructImpl();
	struct.setEL("pos", posArray);
	struct.setEL("len", lenArray);
	struct.setEL("match", matchArray);

	if (matchAll) {
	    matches.appendEL(struct);
	    return matches;
	}

	return struct;
    }