hordi / hash

Fast C++ flat (open addressing) hash set, map

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

need some function

ktprime opened this issue · comments

commented

add some common funtion in your hash.
//expamle like
void max_load_factor(float lf)
{
//...
}
float load_factor()
{
return (float)size() / (capacity() + 1);
}

and it'can not be compiled on win by gcc

In file included from \rank\ebench.cpp:88:
\rank./hordi/hash_set.h:218:34: error: macro "__declspec" passed 2 arguments, but takes just 1
__declspec(noreturn, noinline)
^
In file included from \rank\ebench.cpp:88:
\rank./hordi/hash_set.h:218:5: error: '__declspec' does not name a type; did you mean '_execlpe'?
__declspec(noreturn, noinline)
^~~~~~~~~~

The gcc compiler issue has been fixed (I hope).
About max_load_factor etc need to think (evaluate) how big impact to current performance it will be.

commented

it's just a litter impact from my benchmark. no float/double is used to rehash.
some codes like this for checking rehash

constexpr float max_load_factor() const
{
    return (1 << 17) / (float)_loadlf;
}

void max_load_factor(float value)
{
    if (value < 0.995f && value > 0.2f)
        _loadlf = (uint32_t)((1 << 17) / value);
}

bool reserve(uint32_t num_elems) noexcept
{
    const auto required_buckets = (uint32_t)(((uint64_t)num_elems) * _loadlf >> 17);
    if (EMHASH_LIKELY(required_buckets < _mask))
        return false;

    rehash(required_buckets + 2);
    return true;
}
commented

huangyuanbing@ubuntu:~$ clang++-6.0 -DET -DEMHASH=7 -DTKey=1 -DPHMAP_FLAT -mpclmul -std=c++17 -O3 -mtune=core-avx2 hbench.cpp -o hb && ./hb
In file included from hbench.cpp:1:
./hrd/hash_set.h:209:19: error: use of undeclared identifier '_bsrq'
int idx = bsrq(sz - 1);
^
./hrd/hash_set.h:289:35: error: dependent using declaration resolved to type without 'typename'
using const_iterator::iterator_category;
^
hbench.cpp:118:21: note: in instantiation of member class 'hrd::hash_base::iterator_base<hrd::hash_map<unsigned long, unsigned long, hrd::hash_base::hash
,
std::equal_to > >::iterator' requested here
auto it = m.find(*p);
^
hbench.cpp:270:5: note: in instantiation of function template specialization 'find_erase<hrd::hash_map<unsigned long, unsigned long, hrd::hash_base::hash
,
std::equal_to > >' requested here
find_erase(m);
^
hbench.cpp:344:16: note: in instantiation of function template specialization 'test<hrd::hash_map<unsigned long, unsigned long, hrd::hash_base::hash
, std::equal_to > >' requested here
ret -= test(m1, "\nhrd::hash_map");
^
./hrd/hash_set.h:241:47: note: target of using declaration
typedef std::forward_iterator_tag iterator_category;
^
./hrd/hash_set.h:290:35: error: dependent using declaration resolved to type without 'typename'
using const_iterator::value_type;
^
./hrd/hash_set.h:242:47: note: target of using declaration
typedef typename base::value_type value_type;
^
./hrd/hash_set.h:291:35: error: dependent using declaration resolved to type without 'typename'
using const_iterator::pointer;

Fixed in version 1.2.10

"Stub" load_factor etc functions have been added. Working code will be implemented in separated version (different namespace).