additiveHash static method

int additiveHash(
  1. String key,
  2. int prime
)

加法hash

key 字符串
prime 一个质数
返回 hash结果

Implementation

static int additiveHash(String key, int prime) {
  var hash = key.length;
  for (var i = 0; i < key.length; i++) {
    hash += key.codeUnitAt(i);
  }
  return hash % prime;
}