mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-29 18:53:14 +00:00
mnemonics: misc cleanup
Pass relevant information to the base class instead of overwriting default values later, use objects instead of pointers to objects to avoid having to new objects unnecessarily.
This commit is contained in:
parent
e3d2b135e7
commit
e98f1114a0
11 changed files with 46 additions and 100 deletions
|
@ -49,9 +49,7 @@ namespace Language
|
||||||
class Dutch: public Base
|
class Dutch: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dutch()
|
Dutch(): Base("Dutch", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"aalglad",
|
"aalglad",
|
||||||
"aalscholver",
|
"aalscholver",
|
||||||
"aambeeld",
|
"aambeeld",
|
||||||
|
@ -1678,11 +1676,8 @@ namespace Language
|
||||||
"zwiep",
|
"zwiep",
|
||||||
"zwijmel",
|
"zwijmel",
|
||||||
"zworen"
|
"zworen"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Dutch";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,9 +49,7 @@ namespace Language
|
||||||
class English: public Base
|
class English: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
English()
|
English(): Base("English", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"abbey",
|
"abbey",
|
||||||
"abducts",
|
"abducts",
|
||||||
"ability",
|
"ability",
|
||||||
|
@ -1678,11 +1676,8 @@ namespace Language
|
||||||
"zombie",
|
"zombie",
|
||||||
"zones",
|
"zones",
|
||||||
"zoom"
|
"zoom"
|
||||||
});
|
}), 3)
|
||||||
unique_prefix_length = 3;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "English";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,9 +49,7 @@ namespace Language
|
||||||
class French: public Base
|
class French: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
French()
|
French(): Base("French", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"abandon",
|
"abandon",
|
||||||
"abattre",
|
"abattre",
|
||||||
"aboi",
|
"aboi",
|
||||||
|
@ -1678,11 +1676,8 @@ namespace Language
|
||||||
"zinc",
|
"zinc",
|
||||||
"zone",
|
"zone",
|
||||||
"zoom"
|
"zoom"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "French";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class German: public Base
|
class German: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
German()
|
German(): Base("German", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"Abakus",
|
"Abakus",
|
||||||
"Abart",
|
"Abart",
|
||||||
"abbilden",
|
"abbilden",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"Zündung",
|
"Zündung",
|
||||||
"Zweck",
|
"Zweck",
|
||||||
"Zyklop"
|
"Zyklop"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "German";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class Italian: public Base
|
class Italian: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Italian()
|
Italian(): Base("Italian", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"abbinare",
|
"abbinare",
|
||||||
"abbonato",
|
"abbonato",
|
||||||
"abisso",
|
"abisso",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"zolfo",
|
"zolfo",
|
||||||
"zombie",
|
"zombie",
|
||||||
"zucchero"
|
"zucchero"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Italian";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class Japanese: public Base
|
class Japanese: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Japanese()
|
Japanese(): Base("Japanese", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"あいこくしん",
|
"あいこくしん",
|
||||||
"あいさつ",
|
"あいさつ",
|
||||||
"あいだ",
|
"あいだ",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"ひさん",
|
"ひさん",
|
||||||
"びじゅつかん",
|
"びじゅつかん",
|
||||||
"ひしょ"
|
"ひしょ"
|
||||||
});
|
}), 3)
|
||||||
unique_prefix_length = 3;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Japanese";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,9 +73,9 @@ namespace Language
|
||||||
class Base
|
class Base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> *word_list; /*!< A pointer to the array of words */
|
const std::vector<std::string> word_list; /*!< A pointer to the array of words */
|
||||||
std::unordered_map<std::string, uint32_t> *word_map; /*!< hash table to find word's index */
|
std::unordered_map<std::string, uint32_t> word_map; /*!< hash table to find word's index */
|
||||||
std::unordered_map<std::string, uint32_t> *trimmed_word_map; /*!< hash table to find word's trimmed index */
|
std::unordered_map<std::string, uint32_t> trimmed_word_map; /*!< hash table to find word's trimmed index */
|
||||||
std::string language_name; /*!< Name of language */
|
std::string language_name; /*!< Name of language */
|
||||||
uint32_t unique_prefix_length; /*!< Number of unique starting characters to trim the wordlist to when matching */
|
uint32_t unique_prefix_length; /*!< Number of unique starting characters to trim the wordlist to when matching */
|
||||||
/*!
|
/*!
|
||||||
|
@ -84,33 +84,29 @@ namespace Language
|
||||||
void populate_maps()
|
void populate_maps()
|
||||||
{
|
{
|
||||||
int ii;
|
int ii;
|
||||||
std::vector<std::string>::iterator it;
|
std::vector<std::string>::const_iterator it;
|
||||||
for (it = word_list->begin(), ii = 0; it != word_list->end(); it++, ii++)
|
for (it = word_list.begin(), ii = 0; it != word_list.end(); it++, ii++)
|
||||||
{
|
{
|
||||||
(*word_map)[*it] = ii;
|
word_map[*it] = ii;
|
||||||
if (it->length() > unique_prefix_length)
|
if (it->length() > unique_prefix_length)
|
||||||
{
|
{
|
||||||
(*trimmed_word_map)[utf8prefix(*it, unique_prefix_length)] = ii;
|
trimmed_word_map[utf8prefix(*it, unique_prefix_length)] = ii;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*trimmed_word_map)[*it] = ii;
|
trimmed_word_map[*it] = ii;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Base()
|
Base(const char *language_name, const std::vector<std::string> &words, uint32_t prefix_length):
|
||||||
|
word_list(words),
|
||||||
|
unique_prefix_length(prefix_length),
|
||||||
|
language_name(language_name)
|
||||||
{
|
{
|
||||||
word_list = new std::vector<std::string>;
|
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
unique_prefix_length = 4;
|
|
||||||
}
|
}
|
||||||
virtual ~Base()
|
virtual ~Base()
|
||||||
{
|
{
|
||||||
delete word_list;
|
|
||||||
delete word_map;
|
|
||||||
delete trimmed_word_map;
|
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns a pointer to the word list.
|
* \brief Returns a pointer to the word list.
|
||||||
|
@ -118,7 +114,7 @@ namespace Language
|
||||||
*/
|
*/
|
||||||
const std::vector<std::string>& get_word_list() const
|
const std::vector<std::string>& get_word_list() const
|
||||||
{
|
{
|
||||||
return *word_list;
|
return word_list;
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns a pointer to the word map.
|
* \brief Returns a pointer to the word map.
|
||||||
|
@ -126,7 +122,7 @@ namespace Language
|
||||||
*/
|
*/
|
||||||
const std::unordered_map<std::string, uint32_t>& get_word_map() const
|
const std::unordered_map<std::string, uint32_t>& get_word_map() const
|
||||||
{
|
{
|
||||||
return *word_map;
|
return word_map;
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns a pointer to the trimmed word map.
|
* \brief Returns a pointer to the trimmed word map.
|
||||||
|
@ -134,13 +130,13 @@ namespace Language
|
||||||
*/
|
*/
|
||||||
const std::unordered_map<std::string, uint32_t>& get_trimmed_word_map() const
|
const std::unordered_map<std::string, uint32_t>& get_trimmed_word_map() const
|
||||||
{
|
{
|
||||||
return *trimmed_word_map;
|
return trimmed_word_map;
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the name of the language.
|
* \brief Returns the name of the language.
|
||||||
* \return Name of the language.
|
* \return Name of the language.
|
||||||
*/
|
*/
|
||||||
std::string get_language_name() const
|
const std::string &get_language_name() const
|
||||||
{
|
{
|
||||||
return language_name;
|
return language_name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class OldEnglish: public Base
|
class OldEnglish: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OldEnglish()
|
OldEnglish(): Base("OldEnglish", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"like",
|
"like",
|
||||||
"just",
|
"just",
|
||||||
"love",
|
"love",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"unseen",
|
"unseen",
|
||||||
"weapon",
|
"weapon",
|
||||||
"weary"
|
"weary"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "OldEnglish";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,9 +49,7 @@ namespace Language
|
||||||
class Portuguese: public Base
|
class Portuguese: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Portuguese()
|
Portuguese(): Base("Portuguese", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"abaular",
|
"abaular",
|
||||||
"abdominal",
|
"abdominal",
|
||||||
"abeto",
|
"abeto",
|
||||||
|
@ -1678,11 +1676,8 @@ namespace Language
|
||||||
"zeloso",
|
"zeloso",
|
||||||
"zenite",
|
"zenite",
|
||||||
"zumbi"
|
"zumbi"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Portuguese";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class Russian: public Base
|
class Russian: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Russian()
|
Russian(): Base("Russian", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"абажур",
|
"абажур",
|
||||||
"абзац",
|
"абзац",
|
||||||
"абонент",
|
"абонент",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"яхта",
|
"яхта",
|
||||||
"ячейка",
|
"ячейка",
|
||||||
"ящик"
|
"ящик"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Russian";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,9 +51,7 @@ namespace Language
|
||||||
class Spanish: public Base
|
class Spanish: public Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Spanish()
|
Spanish(): Base("Spanish", std::vector<std::string>({
|
||||||
{
|
|
||||||
word_list = new std::vector<std::string>({
|
|
||||||
"ábaco",
|
"ábaco",
|
||||||
"abdomen",
|
"abdomen",
|
||||||
"abeja",
|
"abeja",
|
||||||
|
@ -1680,11 +1678,8 @@ namespace Language
|
||||||
"risa",
|
"risa",
|
||||||
"ritmo",
|
"ritmo",
|
||||||
"rito"
|
"rito"
|
||||||
});
|
}), 4)
|
||||||
unique_prefix_length = 4;
|
{
|
||||||
word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
|
|
||||||
language_name = "Spanish";
|
|
||||||
populate_maps();
|
populate_maps();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue