UNPKG

hash-string

Version:

A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm.

17 lines (14 loc) 382 B
/** A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm. @param {string} text - String to hash @return {number} Resulting number. */ function hash(text) { 'use strict'; var hash = 5381, index = text.length; while (index) { hash = (hash * 33) ^ text.charCodeAt(--index); } return hash >>> 0; }