1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-22 05:12:28 +08:00

Compare commits

...

1 Commits

Author SHA1 Message Date
dudaodong
9107eb4b32 fix: fix resize bug in HashMap 2022-08-25 14:04:26 +08:00
2 changed files with 14 additions and 0 deletions

View File

@@ -98,6 +98,8 @@ func (hm *HashMap) resize() {
tempTable := hm.table
hm.table = make([]*mapNode, hm.capacity)
for i := 0; i < len(tempTable); i++ {
node := tempTable[i]
if node == nil {

View File

@@ -19,6 +19,18 @@ func TestHashMap_PutAndGet(t *testing.T) {
assert.Equal(4, hm.Get("abc"))
}
func TestHashMap_Resize(t *testing.T) {
assert := internal.NewAssert(t, "TestHashMap_Resize")
hm := NewHashMapWithCapacity(3, 3)
for i := 0; i < 20; i++ {
hm.Put(i, 10)
}
assert.Equal(10, hm.Get(5))
}
func TestHashMap_Delete(t *testing.T) {
assert := internal.NewAssert(t, "TestHashMap_Delete")