hashIgnoreAsciiCase function

int hashIgnoreAsciiCase (String string)

Hash code for a string which is compatible with equalsIgnoreAsciiCase.

The hash code is unaffected by changing the case of ASCII letters, but the case of non-ASCII letters do affect the result.

Implementation

int hashIgnoreAsciiCase(String string) {
  // Jenkins hash code ( http://en.wikipedia.org/wiki/Jenkins_hash_function).
  // adapted to smi values.
  // Same hash used by dart2js for strings, modified to ignore ASCII letter
  // case.
  int hash = 0;
  for (int i = 0; i < string.length; i++) {
    int char = string.codeUnitAt(i);
    // Convert lower-case ASCII letters to upper case.upper
    // This ensures that strings that differ only in case will have the
    // same hash code.
    if (_lowerCaseA <= char && char <= _lowerCaseZ) char -= _asciiCaseBit;
    hash = 0x1fffffff & (hash + char);
    hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
    hash >>= 6;
  }
  hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
  hash >>= 11;
  return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}