mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-18 04:00:03 +02:00
common/include/eoskeygen/key_search.hpp: add max and count variables to the class.
This is done so that m_max can be set to zero from another method. stopping a find() operation. (for threaded operations)
This commit is contained in:
parent
3cc6a2530e
commit
2a528e0eb0
3 changed files with 31 additions and 31 deletions
|
|
@ -31,10 +31,12 @@
|
|||
namespace eoskeygen {
|
||||
|
||||
KeySearch::KeySearch() :
|
||||
m_max (0),
|
||||
m_count (0),
|
||||
#ifdef EOSIOKEYGEN_HAVE_THREADS
|
||||
m_threads(0),
|
||||
m_threads (0),
|
||||
#endif
|
||||
m_callback(NULL)
|
||||
m_callback (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -67,32 +69,34 @@ void KeySearch::setCallback(IKeySearchResult* callback)
|
|||
m_callback = callback;
|
||||
}
|
||||
|
||||
void KeySearch::_search_linear(size_t n) {
|
||||
|
||||
size_t count = 0;
|
||||
void KeySearch::_search_linear()
|
||||
{
|
||||
struct libeosio::ec_keypair pair;
|
||||
|
||||
while (count < n) {
|
||||
while (m_count < m_max) {
|
||||
struct result res;
|
||||
libeosio::ec_generate_key(&pair);
|
||||
if (_contains_word(&pair, res)) {
|
||||
m_callback->onResult(&pair, res);
|
||||
count++;
|
||||
m_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeySearch::find(size_t num_results) {
|
||||
void KeySearch::find(size_t num_results)
|
||||
{
|
||||
m_count = 0;
|
||||
m_max = num_results;
|
||||
|
||||
#ifdef EOSIOKEYGEN_HAVE_THREADS
|
||||
// Only do multithread if number of threads makes sense.
|
||||
if (m_threads >= 2) {
|
||||
_search_mt(num_results);
|
||||
_search_mt();
|
||||
return;
|
||||
}
|
||||
#endif /* HAVE_THREADS */
|
||||
|
||||
_search_linear(num_results);
|
||||
_search_linear();
|
||||
}
|
||||
|
||||
bool KeySearch::_contains_word(const struct libeosio::ec_keypair* key, struct result& result) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue