Skip to content

Commit

Permalink
Use size_t for number of blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Dec 12, 2024
1 parent eec4c4a commit 6158e28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion benchmarks/hash_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char **argv)
map.Initialize();

std::uint64_t total_time = 0;
std::size_t N = 1000;
std::size_t N = 5000;

for (size_t i = 0; i < N; ++i)
{
Expand Down
9 changes: 5 additions & 4 deletions catkit_core/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ uint32_t murmurhash3(const std::string &key, uint32_t seed = 0)
const uint32_t c2 = 0x1b873593;

// Partition in blocks of 4 bytes.
const int nblocks = len / 4;
const size_t nblocks = len / 4;
const uint32_t* blocks = reinterpret_cast<const uint32_t *>(data);
for (int i = 0; i < nblocks; i++)
for (size_t i = 0; i < nblocks; i++)
{
uint32_t k = blocks[i];
k *= c1;
Expand Down Expand Up @@ -149,7 +149,8 @@ class HashMap
else
{
// Copy key ensuring null-termination.
std::strncpy(m_Data[probe].key, key.c_str(), MaxKeyLength - 1);
std::size_t key_length = std::min(key.size(), MaxKeyLength - 1);
key.copy(m_Data[probe].key, key_length);
m_Data[probe].key[MaxKeyLength - 1] = '\0';

// Copy m_Data.
Expand Down Expand Up @@ -180,7 +181,7 @@ class HashMap
{
size_t probe = (index + i) % Size;

EntryFlags flags = m_Data[probe].flags.load();
EntryFlags flags = m_Data[probe].flags.load(std::memory_order_acquire);

if (flags == EntryFlags::OCCUPIED && std::strcmp(m_Data[probe].key, key.c_str()) == 0)
{
Expand Down

0 comments on commit 6158e28

Please sign in to comment.