candid_text_hash function

int candid_text_hash(
  1. String text
)

Implementation

int candid_text_hash(String text) {
    // hash(id) = ( Sum_(i=0..k) utf8(id)[i] * 223^(k-i) ) mod 2^32 where k = |utf8(id)|-1
    int hash = 0;
    for (int b in utf8.encode(text)) {
        hash = (((hash * 223) % pow(2, 32) as int) + b) % pow(2, 32) as int;
    }
    return hash;
}