Update hash map

This commit is contained in:
Yudong Jin 2022-12-15 23:08:07 +08:00
parent 1229f98e92
commit c071ab88d2
6 changed files with 13 additions and 8 deletions

View File

@ -53,7 +53,7 @@ public:
/* 删除操作 */ /* 删除操作 */
void remove(int key) { void remove(int key) {
int index = hashFunc(key); int index = hashFunc(key);
// 置为空字符,代表删除 // 置为 nullptr ,代表删除
bucket[index] = nullptr; bucket[index] = nullptr;
} }
@ -97,6 +97,8 @@ public:
} }
} }
}; };
/* Driver Code */
int main() { int main() {
/* 初始化哈希表 */ /* 初始化哈希表 */
ArrayHashMap map = ArrayHashMap(); ArrayHashMap map = ArrayHashMap();

View File

@ -7,6 +7,7 @@
#include "../include/include.hpp" #include "../include/include.hpp"
/* Driver Code */
int main() { int main() {
/* 初始化哈希表 */ /* 初始化哈希表 */
unordered_map<int, string> map; unordered_map<int, string> map;

View File

@ -49,7 +49,7 @@ func (a *ArrayHashMap) put(key int, val string) {
/* 删除操作 */ /* 删除操作 */
func (a *ArrayHashMap) remove(key int) { func (a *ArrayHashMap) remove(key int) {
index := a.hashFunc(key) index := a.hashFunc(key)
// 置为空字符,代表删除 // 置为 nil ,代表删除
a.bucket[index] = nil a.bucket[index] = nil
} }

View File

@ -50,4 +50,3 @@ func TestArrayHashMap(t *testing.T) {
fmt.Println(val) fmt.Println(val)
} }
} }

View File

@ -73,6 +73,7 @@ class ArrayHashMap:
print(pair.key, "->", pair.val) print(pair.key, "->", pair.val)
""" Driver Code """
if __name__ == "__main__": if __name__ == "__main__":
""" 初始化哈希表 """ """ 初始化哈希表 """
mapp = ArrayHashMap() mapp = ArrayHashMap()

View File

@ -8,6 +8,8 @@ import sys, os.path as osp
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
from include import * from include import *
""" Driver Code """
if __name__ == "__main__": if __name__ == "__main__":
""" 初始化哈希表 """ """ 初始化哈希表 """
mapp = {} mapp = {}