From c071ab88d27774859d4b7ffb075577343c1e26e4 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Thu, 15 Dec 2022 23:08:07 +0800 Subject: [PATCH] Update hash map --- codes/cpp/chapter_hashing/array_hash_map.cpp | 6 ++++-- codes/cpp/chapter_hashing/hash_map.cpp | 3 ++- codes/go/chapter_hashing/array_hash_map.go | 4 ++-- codes/go/chapter_hashing/array_hash_map_test.go | 1 - codes/python/chapter_hashing/array_hash_map.py | 3 ++- codes/python/chapter_hashing/hash_map.py | 4 +++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/codes/cpp/chapter_hashing/array_hash_map.cpp b/codes/cpp/chapter_hashing/array_hash_map.cpp index 2e0f2662..394e3681 100644 --- a/codes/cpp/chapter_hashing/array_hash_map.cpp +++ b/codes/cpp/chapter_hashing/array_hash_map.cpp @@ -53,7 +53,7 @@ public: /* 删除操作 */ void remove(int key) { int index = hashFunc(key); - // 置为空字符,代表删除 + // 置为 nullptr ,代表删除 bucket[index] = nullptr; } @@ -97,6 +97,8 @@ public: } } }; + +/* Driver Code */ int main() { /* 初始化哈希表 */ ArrayHashMap map = ArrayHashMap(); @@ -139,4 +141,4 @@ int main() { } return 0; -} \ No newline at end of file +} diff --git a/codes/cpp/chapter_hashing/hash_map.cpp b/codes/cpp/chapter_hashing/hash_map.cpp index 6c8df4b8..898f679a 100644 --- a/codes/cpp/chapter_hashing/hash_map.cpp +++ b/codes/cpp/chapter_hashing/hash_map.cpp @@ -7,6 +7,7 @@ #include "../include/include.hpp" +/* Driver Code */ int main() { /* 初始化哈希表 */ unordered_map map; @@ -49,4 +50,4 @@ int main() { } return 0; -} \ No newline at end of file +} diff --git a/codes/go/chapter_hashing/array_hash_map.go b/codes/go/chapter_hashing/array_hash_map.go index 7a55055d..a962b6a4 100644 --- a/codes/go/chapter_hashing/array_hash_map.go +++ b/codes/go/chapter_hashing/array_hash_map.go @@ -49,7 +49,7 @@ func (a *ArrayHashMap) put(key int, val string) { /* 删除操作 */ func (a *ArrayHashMap) remove(key int) { index := a.hashFunc(key) - // 置为空字符,代表删除 + // 置为 nil ,代表删除 a.bucket[index] = nil } @@ -93,4 +93,4 @@ func (a *ArrayHashMap) print() { fmt.Println(pair.key, "->", pair.val) } } -} \ No newline at end of file +} diff --git a/codes/go/chapter_hashing/array_hash_map_test.go b/codes/go/chapter_hashing/array_hash_map_test.go index 9b0954c4..6925f0d5 100644 --- a/codes/go/chapter_hashing/array_hash_map_test.go +++ b/codes/go/chapter_hashing/array_hash_map_test.go @@ -50,4 +50,3 @@ func TestArrayHashMap(t *testing.T) { fmt.Println(val) } } - diff --git a/codes/python/chapter_hashing/array_hash_map.py b/codes/python/chapter_hashing/array_hash_map.py index fdb57e4e..046e5c61 100644 --- a/codes/python/chapter_hashing/array_hash_map.py +++ b/codes/python/chapter_hashing/array_hash_map.py @@ -73,6 +73,7 @@ class ArrayHashMap: print(pair.key, "->", pair.val) +""" Driver Code """ if __name__ == "__main__": """ 初始化哈希表 """ mapp = ArrayHashMap() @@ -109,4 +110,4 @@ if __name__ == "__main__": print("\n单独遍历值 Value") for val in mapp.valueSet(): - print(val) \ No newline at end of file + print(val) diff --git a/codes/python/chapter_hashing/hash_map.py b/codes/python/chapter_hashing/hash_map.py index 1afa9feb..f5db7863 100644 --- a/codes/python/chapter_hashing/hash_map.py +++ b/codes/python/chapter_hashing/hash_map.py @@ -8,6 +8,8 @@ import sys, os.path as osp sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) from include import * + +""" Driver Code """ if __name__ == "__main__": """ 初始化哈希表 """ mapp = {} @@ -44,4 +46,4 @@ if __name__ == "__main__": print("\n单独遍历值 Value") for val in mapp.values(): - print(val) \ No newline at end of file + print(val)