JavaScript创建更好的散列函数

一个良好的散列函数的构成有:插入和检索的时间(即性能),以及较低的冲突可能性。

djb2HashCode(key){
    const tableKey = this.toStrFn(key);
    let hash = 5381;
    for (let i = 0; i < tableKey.length; i++){
        hash = (hash * 33) + tableKey.charCodeAt(i);
    }
    return hash % 1013;
}

 

posted @ 2020-11-08 22:28  WP-WangPin  阅读(97)  评论(0编辑  收藏  举报