computeQuerySetHash static method

int computeQuerySetHash(
  1. Iterable<String> queries
)

Stable hash identifying a query set by its content: each query is trimmed and internal whitespace runs collapse to one space (case is preserved — SQL string literals are case-sensitive), the normalized list is sorted, and FNV-1a 32-bit runs over the joined result. The same queries in any order always produce the same hash, across process restarts.

Implementation

static int computeQuerySetHash(Iterable<String> queries) {
  final normalized =
      queries.map((q) => q.trim().replaceAll(RegExp(r'\s+'), ' ')).toList()
        ..sort();
  var hash = 0x811c9dc5;
  void mix(int byte) {
    hash ^= byte;
    hash = (hash * 0x01000193) & 0xFFFFFFFF;
  }

  for (final query in normalized) {
    for (final unit in query.codeUnits) {
      mix(unit & 0xFF);
      mix((unit >> 8) & 0xFF);
    }
    mix(0x0A);
  }
  return hash;
}