作者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