Mutex for a hash table.
More...
#include <tkrzw_thread_util.h>
◆ HashMutex()
tkrzw::HashMutex::HashMutex |
( |
int32_t |
num_slots, |
|
|
int64_t |
num_buckets, |
|
|
uint64_t(*)(std::string_view, uint64_t) |
hash_func |
|
) |
| |
Constructor.
- Parameters
-
num_slots | The number of slots. |
num_buckets | The number of buckets. |
hash_func | A hash function which takes a string view object and a bucket number and returns a bucket index. |
◆ ~HashMutex()
tkrzw::HashMutex::~HashMutex |
( |
| ) |
|
◆ GetNumSlots()
int32_t tkrzw::HashMutex::GetNumSlots |
( |
| ) |
const |
Gets the number of the slots.
@ return the number of the slots.
◆ GetNumBuckets()
int64_t tkrzw::HashMutex::GetNumBuckets |
( |
| ) |
const |
Gets the number of the buckets.
- Returns
- The number of the buckets.
◆ Rehash()
void tkrzw::HashMutex::Rehash |
( |
int64_t |
num_buckets | ) |
|
Modifies the number of buckets.
- Parameters
-
num_buckets | The new number of the buckets. Precondition: The thread must have called the LockOne method. |
◆ GetBucketIndex()
int64_t tkrzw::HashMutex::GetBucketIndex |
( |
std::string_view |
data | ) |
|
Gets the index of the bucket of data.
- Parameters
-
data | The data set in the hash table. |
- Returns
- The index of the bucket which the data belongs to. Precondition: The thread must have locked the bucket or all buckets.
◆ LockOne() [1/2]
int64_t tkrzw::HashMutex::LockOne |
( |
std::string_view |
data | ) |
|
Gets exclusive ownership of a slot of a bucket.
- Parameters
-
data | The data to be set in the hash table. |
- Returns
- The index of the bucket which the data should belong to.
◆ LockOne() [2/2]
bool tkrzw::HashMutex::LockOne |
( |
int64_t |
bucket_index | ) |
|
Gets exclusive ownership of a slot by a bucket index.
- Parameters
-
bucket_index | The index of the bucket to lock. |
- Returns
- True on success or False on failure.
◆ UnlockOne()
void tkrzw::HashMutex::UnlockOne |
( |
int64_t |
bucket_index | ) |
|
Releases exclusive ownership of a slot of a bucket.
- Parameters
-
bucket_index | The index of the bucket to unlock. |
◆ LockOneShared() [1/2]
int64_t tkrzw::HashMutex::LockOneShared |
( |
std::string_view |
data | ) |
|
Gets shared ownership of a slot by a bucket index.
- Parameters
-
data | The data to be set in the hash table. |
- Returns
- The index of the bucket which the data should belong to.
◆ LockOneShared() [2/2]
bool tkrzw::HashMutex::LockOneShared |
( |
int64_t |
bucket_index | ) |
|
Gets shared ownership of a slot of a bucket.
- Parameters
-
bucket_index | The index of the bucket to lock. |
- Returns
- True on success or False on failure.
◆ UnlockOneShared()
void tkrzw::HashMutex::UnlockOneShared |
( |
int64_t |
bucket_index | ) |
|
Releases shared ownership of a slot of a bucket.
- Parameters
-
bucket_index | The index of the bucket to unlock. |
◆ LockAll()
void tkrzw::HashMutex::LockAll |
( |
| ) |
|
Gets exclusive ownership of all slots.
◆ UnlockAll()
void tkrzw::HashMutex::UnlockAll |
( |
| ) |
|
Releases exclusive ownership of all slots.
◆ LockAllShared()
void tkrzw::HashMutex::LockAllShared |
( |
| ) |
|
Gets shared ownership of all slots.
◆ UnlockAllShared()
void tkrzw::HashMutex::UnlockAllShared |
( |
| ) |
|
Releases exclusive ownership of all slots.