《Ant Design Pro v5 获取动态菜单与基于角色权限管理视频教程》 和 《零基础学习 Vue3 教程 2021 年最新教程 免费视频教程》 正在更新
世界上最伟大的投资就是投资自己的教育
剧场模式
http://www.woshipm.com/pmd/805326.html
https://www.jianshu.com/p/bf1d7eee28d0
https://zh.wikipedia.org/wiki/%E5%93%88%E5%B8%8C%E8%A1%A8
function hashStringToInt(s, tableSize) {
let hash = 17;
for (let i = 0; i < s.length; i++) {
hash = (13 * hash * s.charCodeAt(i)) % tableSize;
}
return hash;
}
class HashTable {
table = new Array(3333);
numItems = 0;
resize = () => {
const newTable = new Array(this.table.length * 2);
this.table.forEach(item => {
if (item) {
const idx = hashStringToInt(item[0], newTable.length);
newTable[idx] = item;
}
});
this.table = newTable;
};
getItem = key => {
const idx = hashStringToInt(key, this.table.length);
if (!this.table[idx]) {
return null;
}
return this.table[idx][1];
};
setItem = (key, val) => {
this.numItems++;
const loadFactor = this.numItems / this.table.length;
if (loadFactor > 0.8) {
this.resize();
}
const idx = hashStringToInt(key, this.table.length);
this.table[idx] = [key, val];
};
}
const myTable = new HashTable();
myTable.setItem("firstName", "bob");
myTable.setItem("f", "bob1");
myTable.setItem("firstNafe", "bob2");
myTable.setItem("firstNafe", "bob3");
console.log(myTable.getItem("firstName"));
console.log(myTable.getItem("f"));
console.log(myTable.getItem("firstNafe"));
0 条回复
暂无回复~~
喜欢
统计信息
学员: 19865
视频数量: 1241
帖子数量: 443
© 汕尾市求知科技有限公司 | 关注我们 | 专业版网站 | 在线学员:1136
粤公网安备 44152102000088号 | 粤ICP备19038915号