made group initialization more straightforward

This commit is contained in:
joaquintides
2022-10-18 12:17:40 +02:00
parent 0d6ebb4d2f
commit ac2bc8d615

View File

@ -124,6 +124,10 @@ namespace foa{
* the first 64-bit word contain the least significant bits of each byte in the
* "logical" 128-bit word, and so forth. With this layout, match can be
* implemented with 4 ANDs, 3 shifts, 2 XORs, 1 OR and 1 NOT.
*
* group15 has no user-defined ctor so that it's a trivial type and can be
* initialized via memset etc. Where needed, group15::initialize sets the
* metadata to all zeros.
*/
#if defined(BOOST_UNORDERED_SSE2)
@ -137,6 +141,8 @@ struct group15
alignas(16) unsigned char storage[N+1]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0};
};
inline void initialize(){m=_mm_setzero_si128();}
inline void set(std::size_t pos,std::size_t hash)
{
BOOST_ASSERT(pos<N);
@ -283,6 +289,8 @@ struct group15
alignas(16) unsigned char storage[N+1]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0};
};
inline void initialize(){m=vdupq_n_s8(0);}
inline void set(std::size_t pos,std::size_t hash)
{
BOOST_ASSERT(pos<N);
@ -433,6 +441,8 @@ struct group15
{0x0000000000004000ull,0x0000000000000000ull};
};
inline void initialize(){m[0]=0;m[1]=0;}
inline void set(std::size_t pos,std::size_t hash)
{
BOOST_ASSERT(pos<N);
@ -1367,9 +1377,6 @@ public:
void clear()noexcept
{
alignas(group_type) static constexpr unsigned char
zero[sizeof(group_type)]={0,};
auto p=arrays.elements;
if(p){
for(auto pg=arrays.groups,last=pg+arrays.groups_size_mask+1;
@ -1380,7 +1387,7 @@ public:
mask&=mask-1;
}
/* we wipe the entire metadata to reset the overflow byte as well */
*pg=*reinterpret_cast<const group_type*>(zero);
pg->initialize();
}
arrays.groups[arrays.groups_size_mask].set_sentinel();
size_=0;