Move hash_combine utility function to a more generic place

This way everyone can benefit from it, not only dependency graph.
This commit is contained in:
Sergey Sharybin
2017-05-30 11:09:44 +02:00
parent fb82948043
commit 15692c8cfe
7 changed files with 13 additions and 51 deletions

View File

@@ -167,6 +167,8 @@ unsigned int BLI_ghashutil_inthash_p_murmur(const void *ptr);
unsigned int BLI_ghashutil_inthash_p_simple(const void *ptr); unsigned int BLI_ghashutil_inthash_p_simple(const void *ptr);
bool BLI_ghashutil_intcmp(const void *a, const void *b); bool BLI_ghashutil_intcmp(const void *a, const void *b);
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b);
unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4]); unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4]);
#define BLI_ghashutil_inthash_v4(key) ( \ #define BLI_ghashutil_inthash_v4(key) ( \

View File

@@ -1225,6 +1225,11 @@ bool BLI_ghashutil_intcmp(const void *a, const void *b)
return (a != b); return (a != b);
} }
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b)
{
return hash_a ^ (hash_b + 0x9e3779b9 + (hash_a << 6) + (hash_a >> 2));
}
/** /**
* This function implements the widely used "djb" hash apparently posted * This function implements the widely used "djb" hash apparently posted
* by Daniel Bernstein to comp.lang.c some time ago. The 32 bit * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit

View File

@@ -88,7 +88,6 @@ set(SRC
intern/depsgraph_types.h intern/depsgraph_types.h
util/deg_util_function.h util/deg_util_function.h
util/deg_util_hash.h
) )
if(WITH_CXX11) if(WITH_CXX11)

View File

@@ -49,7 +49,6 @@ extern "C" {
#include "intern/nodes/deg_node_operation.h" #include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_intern.h" #include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h" #include "util/deg_util_foreach.h"
#include "util/deg_util_hash.h"
namespace DEG { namespace DEG {
@@ -158,8 +157,8 @@ static unsigned int id_deps_node_hash_key(const void *key_v)
{ {
const IDDepsNode::ComponentIDKey *key = const IDDepsNode::ComponentIDKey *key =
reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v); reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v);
return hash_combine(BLI_ghashutil_uinthash(key->type), return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type),
BLI_ghashutil_strhash_p(key->name)); BLI_ghashutil_strhash_p(key->name));
} }
static bool id_deps_node_hash_key_cmp(const void *a, const void *b) static bool id_deps_node_hash_key_cmp(const void *a, const void *b)

View File

@@ -35,6 +35,7 @@
extern "C" { extern "C" {
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
@@ -44,7 +45,6 @@ extern "C" {
#include "intern/nodes/deg_node_operation.h" #include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_intern.h" #include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h" #include "util/deg_util_foreach.h"
#include "util/deg_util_hash.h"
namespace DEG { namespace DEG {
@@ -95,8 +95,8 @@ static unsigned int comp_node_hash_key(const void *key_v)
{ {
const ComponentDepsNode::OperationIDKey *key = const ComponentDepsNode::OperationIDKey *key =
reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v); reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v);
return hash_combine(BLI_ghashutil_uinthash(key->opcode), return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->opcode),
BLI_ghashutil_strhash_p(key->name)); BLI_ghashutil_strhash_p(key->name));
} }
static bool comp_node_hash_key_cmp(const void *a, const void *b) static bool comp_node_hash_key_cmp(const void *a, const void *b)

View File

@@ -32,13 +32,11 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
extern "C" {
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
} /* extern "C" */ #include "BLI_ghash.h"
#include "intern/depsgraph.h" #include "intern/depsgraph.h"
#include "intern/depsgraph_intern.h" #include "intern/depsgraph_intern.h"
#include "util/deg_util_hash.h"
namespace DEG { namespace DEG {

View File

@@ -1,41 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2014 Blender Foundation.
* All rights reserved.
*
* Original Author: Brecht van Lommel
* Contributor(s): Lukas Toenne
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/depsgraph/util/deg_util_hash.h
* \ingroup depsgraph
*/
#pragma once
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
/* XXX this might require 2 different variants for sizeof(size_t) (32 vs 64 bit) */
BLI_INLINE size_t hash_combine(size_t hash_a, size_t hash_b)
{
return hash_a ^ (hash_b + 0x9e3779b9 + (hash_a << 6) + (hash_a >> 2));
}