tagHash static method

int tagHash(
  1. String field,
  2. String value
)

Computes the wyhash of a field+value pair (identical to server).

Implementation

static int tagHash(String field, String value) {
  final combined = '$field\x00$value';
  final b = utf8.encode(combined);
  final len = b.length;
  int h = _mul64(len, 0xa0761d6478bd642f);
  int i = 0;
  while (i + 8 <= len) {
    final v = _readU64LE(b, i);
    h = _wymix((h ^ v).toUnsigned(64), 0xe7037ed1a0b428db);
    i += 8;
  }
  if (i < len) {
    int tail = 0;
    for (int j = i; j < len; j++) {
      tail |= (b[j] & 0xFF) << ((j - i) * 8);
    }
    tail = tail.toUnsigned(64);
    h = _wymix((h ^ tail).toUnsigned(64), 0xe7037ed1a0b428db);
  }
  h = _wymix(h, _mul64(len, 0xa0761d6478bd642f));
  return h == 0 ? 1 : h;
}