[gnumeric] Sheet: better hash function.



commit 52a9e59e3893282ce0d0393ebdff6fea268455a2
Author: Morten Welinder <terra gnome org>
Date:   Tue Jul 3 13:10:58 2012 -0400

    Sheet: better hash function.

 ChangeLog   |    4 ++++
 NEWS        |    1 +
 src/sheet.c |   12 +++++++++---
 3 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3c22f42..f1ab872 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-07-03  Morten Welinder  <terra gnome org>
+
+	* src/sheet.c (cell_set_hash): Use a decent hash.
+
 2012-06-25  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/NEWS b/NEWS
index cb5123d..81e44d8 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.11.5
 Morten:
 	* Solver translation fixes.
 	* Teach non-linear solver about constraints.  [Part of #620368]
+	* Avoid too many hash collissions for dense sheets.
 
 --------------------------------------------------------------------------
 Gnumeric 1.11.4
diff --git a/src/sheet.c b/src/sheet.c
index 19ba6c1..6bdeb3a 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -709,9 +709,15 @@ gnm_sheet_constructed (GObject *obj)
 static guint
 cell_set_hash (GnmCell const *key)
 {
-	guint h = key->pos.row;
-	h = (h << 16) ^ (h >> 16);
-	h ^= key->pos.col;
+	guint32 r = key->pos.row;
+	guint32 c = key->pos.col;
+	guint32 h;
+
+	h = r;
+	h *= (guint32)123456789;
+	h ^= c;
+	h *= (guint32)123456789;
+
 	return h;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]