aux/math: Add simple string hashing function

This commit is contained in:
Jakob Bornecrantz 2019-04-01 17:10:41 +01:00
parent 918b834a3b
commit b8e4a5f8d1
3 changed files with 41 additions and 1 deletions

View file

@ -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
)

View file

@ -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

View 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);
}