Tkrzw
|
Mutex for a hash table. More...
#include <tkrzw_thread_util.h>
Public Member Functions | |
HashMutex (int32_t num_slots, int64_t num_buckets, uint64_t(*hash_func)(std::string_view, uint64_t)) | |
Constructor. More... | |
~HashMutex () | |
Destructor. More... | |
HashMutex (const HashMutex &rhs)=delete | |
Copy and assignment are disabled. More... | |
HashMutex & | operator= (const HashMutex &rhs)=delete |
int32_t | GetNumSlots () const |
Gets the number of the slots. More... | |
int64_t | GetNumBuckets () const |
Gets the number of the buckets. More... | |
void | Rehash (int64_t num_buckets) |
Modifies the number of buckets. More... | |
int64_t | GetBucketIndex (std::string_view data) |
Gets the index of the bucket of data. More... | |
int64_t | LockOne (std::string_view data) |
Gets exclusive ownership of a slot of a bucket. More... | |
bool | LockOne (int64_t bucket_index) |
Gets exclusive ownership of a slot by a bucket index. More... | |
void | UnlockOne (int64_t bucket_index) |
Releases exclusive ownership of a slot of a bucket. More... | |
int64_t | LockOneShared (std::string_view data) |
Gets shared ownership of a slot by a bucket index. More... | |
bool | LockOneShared (int64_t bucket_index) |
Gets shared ownership of a slot of a bucket. More... | |
void | UnlockOneShared (int64_t bucket_index) |
Releases shared ownership of a slot of a bucket. More... | |
void | LockAll () |
Gets exclusive ownership of all slots. More... | |
void | UnlockAll () |
Releases exclusive ownership of all slots. More... | |
void | LockAllShared () |
Gets shared ownership of all slots. More... | |
void | UnlockAllShared () |
Releases shared ownership of all slots. More... | |
std::vector< int64_t > | LockMulti (const std::vector< std::string_view > &data_list) |
Gets exclusive ownership of slots of multiple buckets. More... | |
void | UnlockMulti (const std::vector< int64_t > &bucket_indices) |
Releases exclusive ownership of slots of multiple buckets. More... | |
std::vector< int64_t > | LockMultiShared (const std::vector< std::string_view > &data_list) |
Gets shared ownership of slots of multiple buckets. More... | |
void | UnlockMultiShared (const std::vector< int64_t > &bucket_indices) |
Releases shared ownership of slots of multiple buckets. More... | |
Mutex for a hash table.
tkrzw::HashMutex< SHAREDMUTEX >::HashMutex | ( | int32_t | num_slots, |
int64_t | num_buckets, | ||
uint64_t(*)(std::string_view, uint64_t) | hash_func | ||
) |
Constructor.
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. |
tkrzw::HashMutex< SHAREDMUTEX >::~HashMutex |
Destructor.
|
explicitdelete |
Copy and assignment are disabled.
int32_t tkrzw::HashMutex< SHAREDMUTEX >::GetNumSlots |
Gets the number of the slots.
@ return the number of the slots.
int64_t tkrzw::HashMutex< SHAREDMUTEX >::GetNumBuckets |
Gets the number of the buckets.
void tkrzw::HashMutex< SHAREDMUTEX >::Rehash | ( | int64_t | num_buckets | ) |
Modifies the number of buckets.
num_buckets | The new number of the buckets. |
Precondition: The thread must have called the LockOne method.
int64_t tkrzw::HashMutex< SHAREDMUTEX >::GetBucketIndex | ( | std::string_view | data | ) |
Gets the index of the bucket of data.
data | The data set in the hash table. |
Precondition: The thread must have locked the bucket or all buckets.
int64_t tkrzw::HashMutex< SHAREDMUTEX >::LockOne | ( | std::string_view | data | ) |
Gets exclusive ownership of a slot of a bucket.
data | The data to be set in the hash table. |
bool tkrzw::HashMutex< SHAREDMUTEX >::LockOne | ( | int64_t | bucket_index | ) |
Gets exclusive ownership of a slot by a bucket index.
bucket_index | The index of the bucket to lock. |
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockOne | ( | int64_t | bucket_index | ) |
Releases exclusive ownership of a slot of a bucket.
bucket_index | The index of the bucket to unlock. |
int64_t tkrzw::HashMutex< SHAREDMUTEX >::LockOneShared | ( | std::string_view | data | ) |
Gets shared ownership of a slot by a bucket index.
data | The data to be set in the hash table. |
bool tkrzw::HashMutex< SHAREDMUTEX >::LockOneShared | ( | int64_t | bucket_index | ) |
Gets shared ownership of a slot of a bucket.
bucket_index | The index of the bucket to lock. |
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockOneShared | ( | int64_t | bucket_index | ) |
Releases shared ownership of a slot of a bucket.
bucket_index | The index of the bucket to unlock. |
void tkrzw::HashMutex< SHAREDMUTEX >::LockAll |
Gets exclusive ownership of all slots.
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockAll |
Releases exclusive ownership of all slots.
void tkrzw::HashMutex< SHAREDMUTEX >::LockAllShared |
Gets shared ownership of all slots.
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockAllShared |
Releases shared ownership of all slots.
std::vector< int64_t > tkrzw::HashMutex< SHAREDMUTEX >::LockMulti | ( | const std::vector< std::string_view > & | data_list | ) |
Gets exclusive ownership of slots of multiple buckets.
data_list | The data list to be set in the hash table. |
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockMulti | ( | const std::vector< int64_t > & | bucket_indices | ) |
Releases exclusive ownership of slots of multiple buckets.
bucket_indices | The indices of the buckets to unlock. |
std::vector< int64_t > tkrzw::HashMutex< SHAREDMUTEX >::LockMultiShared | ( | const std::vector< std::string_view > & | data_list | ) |
Gets shared ownership of slots of multiple buckets.
data_list | The data list to be set in the hash table. |
void tkrzw::HashMutex< SHAREDMUTEX >::UnlockMultiShared | ( | const std::vector< int64_t > & | bucket_indices | ) |
Releases shared ownership of slots of multiple buckets.
bucket_indices | The indices of the buckets to unlock. |