Initialise the alphabet for the Bitap algorithm.

    Args:
      pattern: The text to encode.

    Returns:
      Hash of character locations.
187008
def match_alphabet(self, pattern):
    
    s = {}
    for char in pattern:
      s[char] = 0
    for i in xrange(len(pattern)):
      s[pattern[i]] |= 1 << (len(pattern) - i - 1)
    return s
35075
function indexOfPattern ($pattern)
  {
    self::toUnicodeRegex ($pattern);
    if (!preg_match ($pattern, $this->S, $m, PREG_OFFSET_CAPTURE)) return false;
    return $m[0][1];
  }
669749
def pattern(self):
        
        if self.dynamic_version_of is not None:
            return self.dynamic_version_of.pattern

        if not self._pattern:
            self._pattern = re.compile('^%s_(.+)$' % self.name)
        return self._pattern
1136750
def pattern_to_str(pattern):
    
    if isinstance(pattern, str):
        return repr(pattern)
    else:
        return repr(pattern.pattern) if pattern else None
982785
def indexOf(self, pattern, start_idx, bitlength):
        
        return StrIndexOf(self, pattern, start_idx, bitlength)
1253568
def _init_alphabet_from_tokens(self, tokens):
        """"""
        # Include all characters from all tokens in the alphabet to guarantee that
        # any token can be encoded. Additionally, include all escaping
        # characters.
        self._alphabet = {c for token in tokens for c in token}
        self._alphabet |= _ESCAPE_CHARS
226053
function patternIdGen(initialID) {
  const splitID = initialID.split('.');
  splitID.shift();
  splitID.unshift('patterns');
  return splitID.join('.');
}
1200910
def getPattern(self, word):
        
        if word in self.patterns:
            return self.patterns[word]
        else:
            raise ValueError('Unknown pattern in getPattern().', word)
187184
public static String preProcessPattern(String pattern) {
		int index = pattern.indexOf('\\');
		if (index < 0) {
			return pattern;
		}

		StringBuilder sb = new StringBuilder();
		for (int pos = 0; pos < pattern.length();) {
			char ch = pattern.charAt(pos);
			if (ch != '\\') {
				sb.append(ch);
				pos++;
				continue;
			}
			if (pos + 1 >= pattern.length()) {
				// we'll end the pattern with a '\\' char
				sb.append(ch);
				break;
			}
			ch = pattern.charAt(++pos);
			switch (ch) {
				case 'b':
					sb.append('\b');
					pos++;
					break;
				case 'f':
					sb.append('\f');
					pos++;
					break;
				case 'n':
					sb.append('\n');
					pos++;
					break;
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7': {
					// 1-3 octal characters: \1 \01 or \017
					pos += radixCharsToChar(sb, pattern, pos, 3, 8);
					break;
				}
				case 'r':
					sb.append('\r');
					pos++;
					break;
				case 't':
					sb.append('\t');
					pos++;
					break;
				case 'x': {
					// 1-2 hex characters: \xD or \xD9
					int adjust = radixCharsToChar(sb, pattern, pos + 1, 2, 16);
					if (adjust > 0) {
						// adjust by 1 for the x
						pos += 1 + adjust;
					} else {
						sb.append(ch);
						pos++;
					}
					break;
				}
				case ' ':
				case '\\':
				default:
					sb.append(ch);
					pos++;
					break;
			}
		}
		return sb.toString();
	}
1261214
public Set<String> keys(String pattern) {
        Set<String> result = new TreeSet<String>();
        for (String key : keys()) {
            if (key.matches(pattern)) result.add(key);
        }
        return result;
    }
506078
def match_main(self, text, pattern, loc):
    
    # Check for null inputs.
    if text == None or pattern == None:
      raise ValueError("Null inputs. (match_main)")

    loc = max(0, min(loc, len(text)))
    if text == pattern:
      # Shortcut (potentially not guaranteed by the algorithm)
      return 0
    elif not text:
      # Nothing to match.
      return -1
    elif text[loc:loc + len(pattern)] == pattern:
      # Perfect match at the perfect spot!  (Includes case of null pattern)
      return loc
    else:
      # Do a fuzzy compare.
      match = self.match_bitap(text, pattern, loc)
      return match
453214
public float patternLineCoverage()
    {
        BitArray lin = new BitArray(width);
        bits.forEach((i)->lin.set(column(i), true));
        return (float)lin.count()/(float)width;
    }
1296191
def zip_patterns(self, patterns):
        
        suffix = self.root.value

        if suffix is not None:
            # We are in a conditional tree.
            new_patterns = {}
            for key in patterns.keys():
                new_patterns[tuple(sorted(list(key) + [suffix]))] = patterns[key]

            return new_patterns

        return patterns
966326
def generate_key(s, pattern="%s.txt"):
    
    h = hashlib.sha1()
    #h.update(s)
    h.update(s.encode('utf-8'))
    return pattern % h.hexdigest()
81646
private static String adopt2JavaPattern(String pattern)
   {
      pattern = normalizePath(pattern);

      // any character except '/', one or more times
      pattern = pattern.replaceAll("\\" + ANY_NAME, "[^/]+");

      // any character except '/' exactly one time
      pattern = pattern.replaceAll(ANY_CHAR, "[^/]{1}");

      return pattern;
   }
1105029
public ScanParams match(final String pattern) {
    params.put(MATCH, ByteBuffer.wrap(SafeEncoder.encode(pattern)));
    return this;
  }
84371
public void setLineDashPattern (final float [] pattern, final float phase) throws IOException
  {
    if (inTextMode)
    {
      throw new IllegalStateException ("Error: setLineDashPattern is not allowed within a text block.");
    }
    write ((byte) '[');
    for (final float value : pattern)
    {
      writeOperand (value);
    }
    write ((byte) ']', (byte) ' ');
    writeOperand (phase);
    writeOperator ((byte) 'd');
  }