Read hash table Please note that read lock should be held by the caller. This is because the caller owns the data, and should hold the read lock as long as he operates on the data.
| 104 | // the caller owns the data, and should hold the read lock as long as he |
| 105 | // operates on the data. |
| 106 | bool Find(const T& t, T* ret, RWMutex** ret_lock) { |
| 107 | const uint64_t h = Hash()(t); |
| 108 | const uint32_t bucket_idx = h % nbuckets_; |
| 109 | const uint32_t lock_idx = bucket_idx % nlocks_; |
| 110 | |
| 111 | RWMutex& lock = locks_[lock_idx]; |
| 112 | lock.ReadLock(); |
| 113 | |
| 114 | auto& bucket = buckets_[bucket_idx]; |
| 115 | if (Find(&bucket, t, ret)) { |
| 116 | *ret_lock = &lock; |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | lock.ReadUnlock(); |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | // |
| 125 | // Erase a given key from the hash table |
no test coverage detected