diff --git a/Dockerfile-build-alpine b/Dockerfile-build-alpine index 6580b786..d7abb765 100644 --- a/Dockerfile-build-alpine +++ b/Dockerfile-build-alpine @@ -23,7 +23,8 @@ ARG LMS_BUILD_PACKAGES=" \ taglib-dev \ stb \ wt-dev \ - gtest-dev" + gtest-dev \ + xxhash-dev" COPY --from=xx / / diff --git a/Dockerfile-build-arch b/Dockerfile-build-arch index b197342c..55a5e7eb 100644 --- a/Dockerfile-build-arch +++ b/Dockerfile-build-arch @@ -13,7 +13,8 @@ ARG BUILD_PACKAGES="\ make \ pkgconfig \ taglib \ - wt" + wt \ + xxhash" RUN pacman -Syu --noconfirm RUN pacman -S --noconfirm ${BUILD_PACKAGES} diff --git a/Dockerfile-release b/Dockerfile-release index 2d1a29c8..e55552fe 100644 --- a/Dockerfile-release +++ b/Dockerfile-release @@ -32,7 +32,8 @@ ARG BUILD_PACKAGES=" \ libconfig-dev \ utfcpp \ sqlite-dev \ - gtest-dev" + gtest-dev \ + xxhash-dev" RUN apk add --no-cache --update ${BUILD_PACKAGES} diff --git a/INSTALL.md b/INSTALL.md index 115ddc3c..e4973605 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -37,7 +37,7 @@ __Notes__: * a C++20 compiler is needed * ffmpeg version 4 minimum is required ```sh -apt-get install g++ cmake libboost-program-options-dev libboost-system-dev libavutil-dev libavformat-dev libstb-dev libconfig++-dev ffmpeg libtag1-dev libpam0g-dev libgtest-dev libarchive-dev +apt-get install g++ cmake libboost-program-options-dev libboost-system-dev libavutil-dev libavformat-dev libstb-dev libconfig++-dev ffmpeg libtag1-dev libpam0g-dev libgtest-dev libarchive-dev libxxhash-dev ``` __Notes__: * libpam0g-dev is optional (only for using PAM authentication) diff --git a/src/libs/core/CMakeLists.txt b/src/libs/core/CMakeLists.txt index cb66dd13..fa069fba 100644 --- a/src/libs/core/CMakeLists.txt +++ b/src/libs/core/CMakeLists.txt @@ -1,5 +1,6 @@ pkg_check_modules(Config++ REQUIRED IMPORTED_TARGET libconfig++) pkg_check_modules(Archive REQUIRED IMPORTED_TARGET libarchive) +pkg_check_modules(XXHASH REQUIRED IMPORTED_TARGET libxxhash) add_library(lmscore STATIC impl/http/Client.cpp @@ -21,6 +22,7 @@ add_library(lmscore STATIC impl/TraceLogger.cpp impl/UUID.cpp impl/WtLogger.cpp + impl/XxHash3.cpp ) target_include_directories(lmscore INTERFACE @@ -34,6 +36,7 @@ target_include_directories(lmscore PRIVATE target_link_libraries(lmscore PRIVATE PkgConfig::Config++ PkgConfig::Archive + PkgConfig::XXHASH ) target_link_libraries(lmscore PUBLIC diff --git a/src/libs/core/impl/XxHash3.cpp b/src/libs/core/impl/XxHash3.cpp new file mode 100644 index 00000000..07215ae4 --- /dev/null +++ b/src/libs/core/impl/XxHash3.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2025 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include "core/XxHash3.hpp" + +#define XXH_INLINE_ALL +#include + +namespace lms::core +{ + std::uint64_t xxHash3_64(std::span buf) + { + return XXH3_64bits(buf.data(), buf.size()); + } +} // namespace lms::core \ No newline at end of file diff --git a/src/libs/core/include/core/XxHash3.hpp b/src/libs/core/include/core/XxHash3.hpp new file mode 100644 index 00000000..b960936f --- /dev/null +++ b/src/libs/core/include/core/XxHash3.hpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace lms::core +{ + std::uint64_t xxHash3_64(std::span buf); +} // namespace lms::core \ No newline at end of file diff --git a/src/libs/core/test/CMakeLists.txt b/src/libs/core/test/CMakeLists.txt index 7b255e10..3e89617a 100644 --- a/src/libs/core/test/CMakeLists.txt +++ b/src/libs/core/test/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(test-core TraceLogger.cpp Utils.cpp UUID.cpp + XxHash3.cpp ) target_link_libraries(test-core PRIVATE diff --git a/src/libs/core/test/XxHash3.cpp b/src/libs/core/test/XxHash3.cpp new file mode 100644 index 00000000..6950fdef --- /dev/null +++ b/src/libs/core/test/XxHash3.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2025 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include + +#include "core/XxHash3.hpp" + +namespace lms::core +{ + TEST(Xxhash3_64, basic) + { + std::vector buffer; + buffer.resize(1024); + + for (std::size_t i{}; i < buffer.size(); ++i) + buffer[i] = static_cast(i); + + const std::uint64_t hash{ xxHash3_64(buffer) }; + EXPECT_EQ(hash, 12137474952470826274ULL); + } +} // namespace lms::core \ No newline at end of file