Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile-package
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ WORKDIR /dbzero/
# Build and install
RUN python3 scripts/generate_meson.py ./src/dbzero/ core
RUN python3 scripts/generate_meson_tests.py tests/
RUN python3 scripts/generate_meson_dbzero.py dbzero/
RUN rm .gitignore
RUN git config --global user.email "you@example.com"
RUN git config --global user.name "Your Name"
RUN git add . && git commit -m "Update meson files"

RUN ./build.sh -r
RUN python3 -m build --wheel
RUN python3 -m build --wheel
5 changes: 3 additions & 2 deletions src/dbzero/bindings/python/PyHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <dbzero/object_model/object/Object.hpp>
#include <dbzero/object_model/class/ClassFactory.hpp>
#include <dbzero/object_model/class/Class.hpp>
#include <dbzero/core/utils/hashes.hpp>

namespace db0::python

Expand All @@ -18,13 +19,13 @@ namespace db0::python
template <> std::int64_t getPyHashImpl<TypeId::STRING>(db0::swine_ptr<Fixture> &, PyObject *key)
{
auto unicode_value = PyUnicode_AsUTF8(key);
return std::hash<std::string>{}(unicode_value);
return murmurhash64A(unicode_value, std::strlen(unicode_value));
}

template <> std::int64_t getPyHashImpl<TypeId::BYTES>(db0::swine_ptr<Fixture> &, PyObject *key)
{
auto bytes_value = PyBytes_AsString(key);
return std::hash<std::string>{}(bytes_value);
return murmurhash64A(bytes_value, std::strlen(bytes_value));
}

template <> std::int64_t getPyHashImpl<TypeId::TUPLE>(db0::swine_ptr<Fixture> &fixture, PyObject *key)
Expand Down
54 changes: 54 additions & 0 deletions src/dbzero/core/utils/hashes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
#include "hashes.hpp"

namespace db0

{
uint64_t murmurhash64A(const void* key, size_t len, uint64_t seed)
{
const uint64_t m = 0xc6a4a7935bd1e995ULL;
const int r = 47;

uint64_t h = seed ^ (len * m);

const uint64_t* data = (const uint64_t*)key;
const uint64_t* end = data + (len / 8);

//----------
// Body: process 8 bytes (64 bits) at a time
while (data != end) {
uint64_t k = *data++;

k *= m;
k ^= k >> r;
k *= m;

h ^= k;
h *= m;
}

//----------
// Tail: handle remaining bytes (less than 8)
const unsigned char* tail = (const unsigned char*)data;

switch (len & 7) {
case 7: h ^= (uint64_t)tail[6] << 48;
case 6: h ^= (uint64_t)tail[5] << 40;
case 5: h ^= (uint64_t)tail[4] << 32;
case 4: h ^= (uint64_t)tail[3] << 24;
case 3: h ^= (uint64_t)tail[2] << 16;
case 2: h ^= (uint64_t)tail[1] << 8;
case 1: h ^= (uint64_t)tail[0];
h *= m;
};

//----------
// Finalization mix
h ^= h >> r;
h *= m;
h ^= h >> r;

return h;
}

}
9 changes: 9 additions & 0 deletions src/dbzero/core/utils/hashes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <iostream>

namespace db0
{
uint64_t murmurhash64A(const void* key, size_t len, uint64_t seed = 0);
}
3 changes: 2 additions & 1 deletion src/dbzero/object_model/enum/EnumValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <dbzero/object_model/enum/EnumFactory.hpp>
#include <dbzero/object_model/enum/Enum.hpp>
#include <dbzero/workspace/Snapshot.hpp>
#include <dbzero/core/utils/hashes.hpp>

namespace db0::object_model

Expand Down Expand Up @@ -148,7 +149,7 @@ namespace db0::object_model
}

std::int64_t EnumValue::getPermHash() const {
return std::hash<std::string>{}(m_str_repr);
return murmurhash64A(m_str_repr.c_str(), m_str_repr.size());
}

void EnumValue::serialize(std::vector<std::byte> &buffer) const
Expand Down