Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashmap delete功能实现 #138

Merged
merged 14 commits into from
Jan 8, 2023
Merged

hashmap delete功能实现 #138

merged 14 commits into from
Jan 8, 2023

Conversation

juniaoshaonian
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Jan 1, 2023

Codecov Report

Merging #138 (fda6007) into dev (088412c) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #138      +/-   ##
==========================================
- Coverage   95.54%   95.48%   -0.06%     
==========================================
  Files          36       36              
  Lines        1772     1818      +46     
==========================================
+ Hits         1693     1736      +43     
- Misses         62       64       +2     
- Partials       17       18       +1     
Impacted Files Coverage Δ
mapx/hashmap.go 100.00% <100.00%> (ø)
pool/task_pool.go 98.11% <0.00%> (-0.95%) ⬇️
mapx/map.go 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

mapx/hashmap.go Outdated
return root.value, true
}
pre.next = root.next
return root.value, true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个被删除节点的 node 要放回去 pool 里面

Comment on lines 164 to 166
if err != nil {
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里改成 require.NoError(t, err),我记得这里别的测试用例也用了这种写法,都改成 require.NoError()

deleteKey testData
wantVal any
wantHashMap func() map[uint64]*node[testData, int]
IsFound bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用小写 isFound

},
IsFound: true,
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一个测试用例,就是测试 hash code 冲突,然后是删除队首元素的。

@@ -128,6 +128,140 @@ func TestHashMap(t *testing.T) {
}

}
func TestHashMap_Delete(t *testing.T) {
testKV := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我其实不太建议这里提前准备好所有的数据,我建议每个测试用例单独准备测试数据。这个和 Get 不一样,Get 是纯粹的查询,不会修改数据,因此相互之间没有影响。而这个删除操作,测试用例之间是有影响的,比如说你必须要在每一个 testcase 里面小心,确保前面的测试用例没有把你当前测试用例的数据删除掉。

这违背了我们设计单元测试保持每一个测试用例独立性的要求

@flycash flycash linked an issue Jan 8, 2023 that may be closed by this pull request
@flycash flycash merged commit 215438f into ecodeclub:dev Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mapx: HashMap 增加 Delete 方法
2 participants