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:
@@ -167,6 +167,8 @@ unsigned int BLI_ghashutil_inthash_p_murmur(const void *ptr);
|
||||
unsigned int BLI_ghashutil_inthash_p_simple(const void *ptr);
|
||||
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]);
|
||||
#define BLI_ghashutil_inthash_v4(key) ( \
|
||||
|
@@ -1225,6 +1225,11 @@ bool BLI_ghashutil_intcmp(const void *a, const void *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
|
||||
* by Daniel Bernstein to comp.lang.c some time ago. The 32 bit
|
||||
|
@@ -88,7 +88,6 @@ set(SRC
|
||||
intern/depsgraph_types.h
|
||||
|
||||
util/deg_util_function.h
|
||||
util/deg_util_hash.h
|
||||
)
|
||||
|
||||
if(WITH_CXX11)
|
||||
|
@@ -49,7 +49,6 @@ extern "C" {
|
||||
#include "intern/nodes/deg_node_operation.h"
|
||||
#include "intern/depsgraph_intern.h"
|
||||
#include "util/deg_util_foreach.h"
|
||||
#include "util/deg_util_hash.h"
|
||||
|
||||
namespace DEG {
|
||||
|
||||
@@ -158,8 +157,8 @@ static unsigned int id_deps_node_hash_key(const void *key_v)
|
||||
{
|
||||
const IDDepsNode::ComponentIDKey *key =
|
||||
reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v);
|
||||
return hash_combine(BLI_ghashutil_uinthash(key->type),
|
||||
BLI_ghashutil_strhash_p(key->name));
|
||||
return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->type),
|
||||
BLI_ghashutil_strhash_p(key->name));
|
||||
}
|
||||
|
||||
static bool id_deps_node_hash_key_cmp(const void *a, const void *b)
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
@@ -44,7 +45,6 @@ extern "C" {
|
||||
#include "intern/nodes/deg_node_operation.h"
|
||||
#include "intern/depsgraph_intern.h"
|
||||
#include "util/deg_util_foreach.h"
|
||||
#include "util/deg_util_hash.h"
|
||||
|
||||
namespace DEG {
|
||||
|
||||
@@ -95,8 +95,8 @@ static unsigned int comp_node_hash_key(const void *key_v)
|
||||
{
|
||||
const ComponentDepsNode::OperationIDKey *key =
|
||||
reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v);
|
||||
return hash_combine(BLI_ghashutil_uinthash(key->opcode),
|
||||
BLI_ghashutil_strhash_p(key->name));
|
||||
return BLI_ghashutil_combine_hash(BLI_ghashutil_uinthash(key->opcode),
|
||||
BLI_ghashutil_strhash_p(key->name));
|
||||
}
|
||||
|
||||
static bool comp_node_hash_key_cmp(const void *a, const void *b)
|
||||
|
@@ -32,13 +32,11 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
extern "C" {
|
||||
#include "BLI_utildefines.h"
|
||||
} /* extern "C" */
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "intern/depsgraph.h"
|
||||
#include "intern/depsgraph_intern.h"
|
||||
#include "util/deg_util_hash.h"
|
||||
|
||||
namespace DEG {
|
||||
|
||||
|
@@ -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));
|
||||
}
|
Reference in New Issue
Block a user