diff --git a/src/xrt/auxiliary/CMakeLists.txt b/src/xrt/auxiliary/CMakeLists.txt index 36acf157c..8e7ce6be8 100644 --- a/src/xrt/auxiliary/CMakeLists.txt +++ b/src/xrt/auxiliary/CMakeLists.txt @@ -4,8 +4,9 @@ set(MATH_SOURCE_FILES math/m_api.h math/m_base.cpp - math/m_optics.c math/m_eigen_interop.h + math/m_hash.cpp + math/m_optics.c math/m_quatexpmap.cpp ) diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index 16543e1b9..c14df3197 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -36,6 +36,25 @@ extern "C" { */ +/* + * + * Hash functions. + * + */ + +/*! + * Generate a hash value from the given string, trailing zero not included. + * + * Hashing function used is not specified so no garantee of staying the same + * between different versions of the software, or even when the same version + * is compiled on different platforms/libc++ as it might use std::hash. + * + * @ingroup aux_math + */ +size_t +math_hash_string(const char *str_c, size_t length); + + /* * * Vector functions diff --git a/src/xrt/auxiliary/math/m_hash.cpp b/src/xrt/auxiliary/math/m_hash.cpp new file mode 100644 index 000000000..20b8d84e4 --- /dev/null +++ b/src/xrt/auxiliary/math/m_hash.cpp @@ -0,0 +1,20 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Hashing fuction. + * @author Jakob Bornecrantz + * @ingroup aux_math + */ + +#include +#include "m_api.h" + + +extern "C" size_t +math_hash_string(const char *str_c, size_t length) +{ + std::string str = std::string(str_c, length); + std::hash str_hash; + return str_hash(str); +}