hashString function

int hashString(
  1. String str
)

Computes a simple numeric hash of a string for analytics grouping. Uses djb2 algorithm, returning a 32-bit unsigned integer.

Implementation

int hashString(String str) {
  int hash = 5381;
  for (int i = 0; i < str.length; i++) {
    hash = ((hash << 5) + hash + str.codeUnitAt(i)) & 0xFFFFFFFF;
  }
  return hash;
}