add back const with help of mutable shared mutex

This commit is contained in:
Dario 2020-06-05 13:44:41 +02:00
parent 5060fd97f0
commit ae74352fc6
2 changed files with 5 additions and 5 deletions

View File

@ -153,7 +153,7 @@ int Mnemonic::init(void(*fill_words_func)(unsigned char*), unsigned int original
return -5;
}
short Mnemonic::getWordIndex(const char* word)
short Mnemonic::getWordIndex(const char* word) const
{
std::shared_lock<std::shared_mutex> _lock(mWorkingMutex);
DHASH word_hash = DRMakeStringHash(word);

View File

@ -30,13 +30,13 @@ public:
int init(void(*fill_words_func)(unsigned char*), unsigned int original_size, unsigned int compressed_size);
inline const char* getWord(short index) {
inline const char* getWord(short index) const {
std::shared_lock<std::shared_mutex> _lock(mWorkingMutex);
if (index < 2048 && index >= 0) return mWords[index];
return nullptr;
}
short getWordIndex(const char* word);
inline bool isWordExist(const std::string& word) {
short getWordIndex(const char* word) const;
inline bool isWordExist(const std::string& word) const {
std::shared_lock<std::shared_mutex> _lock(mWorkingMutex);
return getWordIndex(word.data()) != -1;
}
@ -62,7 +62,7 @@ protected:
typedef std::pair<std::string, unsigned short> HashCollideWordEntry;
std::map<DHASH, unsigned short> mWordHashIndices;
std::map<DHASH, std::map<std::string, unsigned short>> mHashCollisionWords;
std::shared_mutex mWorkingMutex;
mutable std::shared_mutex mWorkingMutex;
};