Skip to content

Commit

Permalink
fix murmurhash fallthrough; remove colllectionID optimizations assumi…
Browse files Browse the repository at this point in the history
…ng non-hashing
  • Loading branch information
hegner committed May 5, 2023
1 parent 5e4bf39 commit e75dd5a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
6 changes: 0 additions & 6 deletions include/podio/EventStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ class DEPR_EVTSTORE EventStore : public ICollectionProvider, public IMetaDataPro
template <typename T>
bool get(const std::string& name, const T*& collection);

/// fast access to cached collections
CollectionBase* getFast(int id) const {
return (m_cachedCollections.size() > (unsigned)id ? m_cachedCollections[id] : nullptr);
}

/// access a collection by ID. returns true if successful
bool get(int id, CollectionBase*& coll) const final;

Expand Down Expand Up @@ -120,7 +115,6 @@ class DEPR_EVTSTORE EventStore : public ICollectionProvider, public IMetaDataPro
// members
mutable std::set<int> m_retrievedIDs{};
mutable CollContainer m_collections{};
mutable std::vector<CollectionBase*> m_cachedCollections{};
IReader* m_reader{nullptr};
std::shared_ptr<CollectionIDTable> m_table;

Expand Down
14 changes: 0 additions & 14 deletions src/EventStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace podio {

EventStore::EventStore() : m_table(new CollectionIDTable()) {
m_cachedCollections.resize(128); // allow for a sufficiently large initial number of collections
}

EventStore::~EventStore() {
Expand All @@ -17,23 +16,12 @@ EventStore::~EventStore() {
}

bool EventStore::get(int id, CollectionBase*& collection) const {
// see if we have a cached collection
if ((collection = getFast(id)) != nullptr) {
return true;
}

auto val = m_retrievedIDs.insert(id);
bool success = false;
if (val.second == true) {
// collection not yet retrieved in recursive-call
auto name = m_table->name(id);
success = doGet(name, collection, true);
if (collection != nullptr) { // cache the collection for faster retreaval later
if (m_cachedCollections.size() < (unsigned)id + 1) {
m_cachedCollections.resize(id + 1);
}
m_cachedCollections[id] = collection;
}
} else {
// collection already requested in recursive call
// do not set the references to break collection dependency-cycle
Expand Down Expand Up @@ -135,8 +123,6 @@ void EventStore::clear() {

void EventStore::clearCaches() {
m_collections.clear();
m_cachedCollections.clear();
m_cachedCollections.resize(128);
m_retrievedIDs.clear();
}

Expand Down
44 changes: 22 additions & 22 deletions src/MurmurHash2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ uint32_t MurmurHash2 ( const void * key, int len, uint32_t seed )

switch(len)
{
case 3: h ^= data[2] << 16; break;
case 2: h ^= data[1] << 8; break;
case 3: h ^= data[2] << 16; [[fallthrough]];
case 2: h ^= data[1] << 8; [[fallthrough]];
case 1: h ^= data[0];
h *= m;
};
Expand Down Expand Up @@ -119,12 +119,12 @@ uint64_t MurmurHash64A ( const void * key, int len, uint64_t seed )

switch(len & 7)
{
case 7: h ^= uint64_t(data2[6]) << 48; break;
case 6: h ^= uint64_t(data2[5]) << 40; break;
case 5: h ^= uint64_t(data2[4]) << 32; break;
case 4: h ^= uint64_t(data2[3]) << 24; break;
case 3: h ^= uint64_t(data2[2]) << 16; break;
case 2: h ^= uint64_t(data2[1]) << 8; break;
case 7: h ^= uint64_t(data2[6]) << 48; [[fallthrough]];
case 6: h ^= uint64_t(data2[5]) << 40; [[fallthrough]];
case 5: h ^= uint64_t(data2[4]) << 32; [[fallthrough]];
case 4: h ^= uint64_t(data2[3]) << 24; [[fallthrough]];
case 3: h ^= uint64_t(data2[2]) << 16; [[fallthrough]];
case 2: h ^= uint64_t(data2[1]) << 8; [[fallthrough]];
case 1: h ^= uint64_t(data2[0]);
h *= m;
};
Expand Down Expand Up @@ -172,9 +172,9 @@ uint64_t MurmurHash64B ( const void * key, int len, uint64_t seed )

switch(len)
{
case 3: h2 ^= ((unsigned char*)data)[2] << 16; break;
case 2: h2 ^= ((unsigned char*)data)[1] << 8; break;
case 1: h2 ^= ((unsigned char*)data)[0]; break;
case 3: h2 ^= ((unsigned char*)data)[2] << 16; [[fallthrough]];
case 2: h2 ^= ((unsigned char*)data)[1] << 8; [[fallthrough]];
case 1: h2 ^= ((unsigned char*)data)[0]; [[fallthrough]];
h2 *= m;
};

Expand Down Expand Up @@ -227,8 +227,8 @@ uint32_t MurmurHash2A ( const void * key, int len, uint32_t seed )

switch(len)
{
case 3: t ^= data[2] << 16; break;
case 2: t ^= data[1] << 8; break;
case 3: t ^= data[2] << 16; [[fallthrough]];
case 2: t ^= data[1] << 8; [[fallthrough]];
case 1: t ^= data[0];
};

Expand Down Expand Up @@ -448,8 +448,8 @@ uint32_t MurmurHashAligned2 ( const void * key, int len, uint32_t seed )
{
switch(align)
{
case 3: d |= data[2] << 16; break;
case 2: d |= data[1] << 8; break;
case 3: d |= data[2] << 16; [[fallthrough]];
case 2: d |= data[1] << 8; [[fallthrough]];
case 1: d |= data[0];
}

Expand All @@ -464,8 +464,8 @@ uint32_t MurmurHashAligned2 ( const void * key, int len, uint32_t seed )

switch(len)
{
case 3: h ^= data[2] << 16; break;
case 2: h ^= data[1] << 8; break;
case 3: h ^= data[2] << 16; [[fallthrough]];
case 2: h ^= data[1] << 8; [[fallthrough]];
case 1: h ^= data[0];
h *= m;
};
Expand All @@ -474,9 +474,9 @@ uint32_t MurmurHashAligned2 ( const void * key, int len, uint32_t seed )
{
switch(len)
{
case 3: d |= data[2] << 16; break;
case 2: d |= data[1] << 8; break;
case 1: d |= data[0]; break;
case 3: d |= data[2] << 16; [[fallthrough]];
case 2: d |= data[1] << 8; [[fallthrough]];
case 1: d |= data[0]; [[fallthrough]];
case 0: h ^= (t >> sr) | (d << sl);
h *= m;
}
Expand Down Expand Up @@ -505,8 +505,8 @@ uint32_t MurmurHashAligned2 ( const void * key, int len, uint32_t seed )

switch(len)
{
case 3: h ^= data[2] << 16; break;
case 2: h ^= data[1] << 8; break;
case 3: h ^= data[2] << 16; [[fallthrough]];
case 2: h ^= data[1] << 8; [[fallthrough]];
case 1: h ^= data[0];
h *= m;
};
Expand Down

0 comments on commit e75dd5a

Please sign in to comment.