Insert into the hash map if it's not already there. Return true if added, false if it was already present. If do_lock is true, lock the bin containing key while doing this operation; if do_lock is false, assume that the caller already has the bin locked, so do no locking or unlocking.
| 300 | /// operation; if do_lock is false, assume that the caller already |
| 301 | /// has the bin locked, so do no locking or unlocking. |
| 302 | bool insert (const KEY &key, const VALUE &value, |
| 303 | bool do_lock = true) { |
| 304 | size_t b = whichbin(key); |
| 305 | Bin &bin (m_bins[b]); |
| 306 | if (do_lock) |
| 307 | bin.lock (); |
| 308 | bool add = (bin.map.find (key) == bin.map.end()); |
| 309 | if (add) { |
| 310 | // not found -- add it! |
| 311 | bin.map[key] = value; |
| 312 | ++m_size; |
| 313 | } |
| 314 | if (do_lock) |
| 315 | bin.unlock(); |
| 316 | return add; |
| 317 | } |
| 318 | |
| 319 | /// If the key is in the map, safely erase it. |
| 320 | /// If do_lock is true, lock the bin containing key while doing this |