mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
aux/math: Add simple string hashing function
This commit is contained in:
parent
918b834a3b
commit
b8e4a5f8d1
|
@ -4,8 +4,9 @@
|
||||||
set(MATH_SOURCE_FILES
|
set(MATH_SOURCE_FILES
|
||||||
math/m_api.h
|
math/m_api.h
|
||||||
math/m_base.cpp
|
math/m_base.cpp
|
||||||
math/m_optics.c
|
|
||||||
math/m_eigen_interop.h
|
math/m_eigen_interop.h
|
||||||
|
math/m_hash.cpp
|
||||||
|
math/m_optics.c
|
||||||
math/m_quatexpmap.cpp
|
math/m_quatexpmap.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Vector functions
|
||||||
|
|
20
src/xrt/auxiliary/math/m_hash.cpp
Normal file
20
src/xrt/auxiliary/math/m_hash.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2019, Collabora, Ltd.
|
||||||
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
|
/*!
|
||||||
|
* @file
|
||||||
|
* @brief Hashing fuction.
|
||||||
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||||
|
* @ingroup aux_math
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#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<std::string> str_hash;
|
||||||
|
return str_hash(str);
|
||||||
|
}
|
Loading…
Reference in a new issue