Go-Algorithm icon indicating copy to clipboard operation
Go-Algorithm copied to clipboard

hash remove方法问题

Open peng0208 opened this issue 8 years ago • 0 comments

作者你好,目前我初学go语言,看到你的项目hashMap删除方法好像有问题,你的代码:

func (hashMap *LinkedHashMap) Remove(key int) {
	hashMap.checkTable()
	hash := getHashValue(key)
	e := hashMap.table[hash]
	if e != nil {
		for e.next != nil {
			if e.key == key {
				e.key = e.next.key
				e.value = e.next.value
				e.next = e.next.next
				return
			}
			e = e.next
		}
		if e.key == key {
                         // 此处e=nil只是对e指针类型的引用置为nil,并非将next值置为空
                         // 应该是将元素的值置为空
			e = nil
		}
	}
}

peng0208 avatar Nov 23 '17 03:11 peng0208