diff --git a/Dockerfile-package b/Dockerfile-package index 36f5a3e1..d910b413 100644 --- a/Dockerfile-package +++ b/Dockerfile-package @@ -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 \ No newline at end of file +RUN python3 -m build --wheel diff --git a/src/dbzero/bindings/python/PyHash.cpp b/src/dbzero/bindings/python/PyHash.cpp index 42061c21..c32031b6 100644 --- a/src/dbzero/bindings/python/PyHash.cpp +++ b/src/dbzero/bindings/python/PyHash.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace db0::python @@ -18,13 +19,13 @@ namespace db0::python template <> std::int64_t getPyHashImpl(db0::swine_ptr &, PyObject *key) { auto unicode_value = PyUnicode_AsUTF8(key); - return std::hash{}(unicode_value); + return murmurhash64A(unicode_value, std::strlen(unicode_value)); } template <> std::int64_t getPyHashImpl(db0::swine_ptr &, PyObject *key) { auto bytes_value = PyBytes_AsString(key); - return std::hash{}(bytes_value); + return murmurhash64A(bytes_value, std::strlen(bytes_value)); } template <> std::int64_t getPyHashImpl(db0::swine_ptr &fixture, PyObject *key) diff --git a/src/dbzero/core/utils/hashes.cpp b/src/dbzero/core/utils/hashes.cpp new file mode 100644 index 00000000..d77ffffe --- /dev/null +++ b/src/dbzero/core/utils/hashes.cpp @@ -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; + } + +} \ No newline at end of file diff --git a/src/dbzero/core/utils/hashes.hpp b/src/dbzero/core/utils/hashes.hpp new file mode 100644 index 00000000..38ee33a3 --- /dev/null +++ b/src/dbzero/core/utils/hashes.hpp @@ -0,0 +1,9 @@ +#pragma once +#include +#include +#include + +namespace db0 +{ +uint64_t murmurhash64A(const void* key, size_t len, uint64_t seed = 0); +} \ No newline at end of file diff --git a/src/dbzero/object_model/enum/EnumValue.cpp b/src/dbzero/object_model/enum/EnumValue.cpp index b300be7d..05b02a3c 100644 --- a/src/dbzero/object_model/enum/EnumValue.cpp +++ b/src/dbzero/object_model/enum/EnumValue.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace db0::object_model @@ -148,7 +149,7 @@ namespace db0::object_model } std::int64_t EnumValue::getPermHash() const { - return std::hash{}(m_str_repr); + return murmurhash64A(m_str_repr.c_str(), m_str_repr.size()); } void EnumValue::serialize(std::vector &buffer) const