getCodeWord method

int getCodeWord (
  1. String pattern
)

get the codeWord for a String. The value will be < alphabet.length if the String is found in the alphabet, > alphabet.length otherwise. If the given String does not exist in the codebook, null will be returned.

Implementation

int getCodeWord(String pattern) {
  if (alphabet.contains(pattern)) return alphabet.indexOf(pattern);

  if (_codebook.containsKey(pattern)) return _codebook[pattern];

  return null;
}