MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenImageIO / insert

Function insert

src/include/unordered_map_concurrent.h:302–317  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

whichbinFunction · 0.85
lockMethod · 0.45
findMethod · 0.45
endMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected