[Bf-blender-cvs] [15692c8cfe5] master: Move hash_combine utility function to a more generic place

Sergey Sharybin noreply at git.blender.org
Tue May 30 11:10:34 CEST 2017


Commit: 15692c8cfe5aac896227cfd4594e0a6f84df01b0
Author: Sergey Sharybin
Date:   Tue May 30 11:09:44 2017 +0200
Branches: master
https://developer.blender.org/rB15692c8cfe5aac896227cfd4594e0a6f84df01b0

Move hash_combine utility function to a more generic place

This way everyone can benefit from it, not only dependency graph.

===================================================================

M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/nodes/deg_node.cc
M	source/blender/depsgraph/intern/nodes/deg_node_component.cc
M	source/blender/depsgraph/intern/nodes/deg_node_operation.cc
D	source/blender/depsgraph/util/deg_util_hash.h

===================================================================

diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h
index 7e3a009ede8..3d71ad8f63e 100644
--- a/source/blender/blenlib/BLI_ghash.h
+++ b/source/blender/blenlib/BLI_ghash.h
@@ -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) ( \
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 944ee18e6b2..d1fe3557801 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -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
diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index e635256cda6..b664af570b1 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -88,7 +88,6 @@ set(SRC
 	intern/depsgraph_types.h
 
 	util/deg_util_function.h
-	util/deg_util_hash.h
 )
 
 if(WITH_CXX11)
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc
index 57b25c10670..b1d5b538e25 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node.cc
@@ -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)
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
index 06f91ac7fdc..136c66b9516 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
@@ -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)
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
index 9eed4dfe8d8..cbf397bc7a9 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
@@ -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 {
 
diff --git a/source/blender/depsgraph/util/deg_util_hash.h b/source/blender/depsgraph/util/deg_util_hash.h
deleted file mode 100644
index e490be1a7a1..00000000000
--- a/source/blender/depsgraph/util/deg_util_hash.h
+++ /dev/null
@@ -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));
-}




More information about the Bf-blender-cvs mailing list