作者dryman (dryman)
看板EE_DSnP
標題[問題] 又要來問笨問題了--Hash
時間Sat Jan 9 11:17:52 2010
爬文看到老師說reset()要走過所有的hashnode
@ @"
我原本是想說將所有的vector<HashNode>的size變成0(capacity不變)
這樣就等於清光所有資料了,這樣做對嗎?
不太了解走過所有hashnode時要做什麼,清掉hashdata?
另外不太懂replaceInsert的comments的意思
return true if inserted successfully (i.e. ke is not in hash)
return false if k is already in the hash ==> still do the insertion.
still do the insertion是要新加一個重複hashkey的hashnode在bucket中嗎?
還是說是要覆寫掉重複hashkey的hashnode?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.97.140
1F:→ dryman:應該是replace吧?? 01/09 11:24
2F:→ dryman:cache的reset()也不太懂..要delete所有的cachenode嗎? 01/09 11:48
3F:推 ric2k1:breset 要從 uniqueTable 裏頭將所有的 BddNodeInt delete 01/09 12:02
4F:→ ric2k1:掉哦! 01/09 12:02
5F:→ ric2k1:resize(0) 並不會將自動幫你 call delete 01/09 12:03
6F:推 ric2k1:Ans: 覆寫掉重複hashkey的hashnode 01/09 12:04
7F:→ dryman:所以..要~hashdata這樣嗎? 01/09 12:14
8F:→ dryman:呃,要怎麼delete一個HashData啊,因為是template... 01/09 12:17
9F:→ dryman:我腦包,直接delete HashData就好,因為丟進去的是pointer. 01/09 12:21
10F:→ dryman:不過如果丟進去的不是pointer就不safe.. 01/09 12:22
11F:推 anfranion:如果是clear()的話他會自動呼叫destructor 可是我不知道 01/09 12:52
12F:→ anfranion:他會不會幫你delete @@ 01/09 12:52
13F:→ dryman:如果pair沒有destructor的話那就要自己delete了 01/09 13:00
14F:→ dryman:pair是struct..應該是不會幫忙delete吧@ @ 01/09 13:02
15F:推 a3785lexx:竊以為是要在BddMgr::reset()裡面delete... 01/09 15:11
16F:推 ric2k1:推樓上, destructor 是一定會被呼叫的, 但是 pointer type 01/09 15:19
17F:→ ric2k1:的 data 就不會被 delete, 所以要在 外面 先將所有 pointer 01/09 15:19
18F:→ ric2k1:data delete 掉之後 再 clear, 免得事後也找不到東西delete 01/09 15:20