看板 EE_DSnP 關於我們 聯絡資訊
爬文看到老師說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
dryman:應該是replace吧?? 01/09 11:24
dryman:cache的reset()也不太懂..要delete所有的cachenode嗎? 01/09 11:48
ric2k1:breset 要從 uniqueTable 裏頭將所有的 BddNodeInt delete 01/09 12:02
ric2k1:掉哦! 01/09 12:02
ric2k1:resize(0) 並不會將自動幫你 call delete 01/09 12:03
ric2k1:Ans: 覆寫掉重複hashkey的hashnode 01/09 12:04
dryman:所以..要~hashdata這樣嗎? 01/09 12:14
dryman:呃,要怎麼delete一個HashData啊,因為是template... 01/09 12:17
dryman:我腦包,直接delete HashData就好,因為丟進去的是pointer. 01/09 12:21
dryman:不過如果丟進去的不是pointer就不safe.. 01/09 12:22
anfranion:如果是clear()的話他會自動呼叫destructor 可是我不知道 01/09 12:52
anfranion:他會不會幫你delete @@ 01/09 12:52
dryman:如果pair沒有destructor的話那就要自己delete了 01/09 13:00
dryman:pair是struct..應該是不會幫忙delete吧@ @ 01/09 13:02
a3785lexx:竊以為是要在BddMgr::reset()裡面delete... 01/09 15:11
ric2k1:推樓上, destructor 是一定會被呼叫的, 但是 pointer type 01/09 15:19
ric2k1:的 data 就不會被 delete, 所以要在 外面 先將所有 pointer 01/09 15:19
ric2k1:data delete 掉之後 再 clear, 免得事後也找不到東西delete 01/09 15:20