作者ric2k1 (Ric)
看板EE_DSnP
标题[讨论] Hash里的replaceInsert()和forceInsert()
时间Tue Dec 25 01:06:05 2012
// return true if inserted successfully (i.e. k is not in the hash)
// return false is k is already in the hash ==> still do the insertion
bool replaceInsert(const HashKey& k, const HashData& d);
这个 function 是用在你一定想要把 HashNode(k, d) insert 进去,
不管原来 Hash 里面是否已经含有 "HashKey k" 的 entry。
如果原来没有,就 return true;
但如果原来有,不管原来对应的 HashData 是不是等於 d, 都 return false,
表示旧的有被更新到。
// Need to be sure that k is not in the hash
void forceInsert(const HashKey& k, const HashData& d);
这个 function 的呼叫是当你已经确定 Hash 里面没有 "HashKey k" 这个 entry,
(也就是说刚刚已经检查过了)
所以就不再检查,而直接把 HashNode(k, d) 直接 insert 进去。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.248.110.117
1F:推 yan12125:推! 12/25 01:10
2F:推 vegired:推! 12/25 01:38
3F:推 XDucka:所以replaceinsert是要拿新的d更新旧的d @@? 01/02 13:33
4F:→ XDucka:好像是废话=.= 01/02 13:33