[gnumeric] Improve hash functions in light of variable-size sheets.



commit 5a56e1441895fce441e2e02b44eadb06628fbcd7
Author: Morten Welinder <terra gnome org>
Date:   Fri Apr 17 09:09:14 2009 -0400

    Improve hash functions in light of variable-size sheets.
    
    * src/position.c (gnm_cellpos_hash, gnm_cellref_hash,
    gnm_rangeref_hash): Improve these in light on variable-size
    sheets.
---
 ChangeLog      |    6 ++++++
 src/position.c |   18 +++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09f11aa..326c088 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-04-17  Morten Welinder  <terra gnome org>
+
+	* src/position.c (gnm_cellpos_hash, gnm_cellref_hash,
+	gnm_rangeref_hash): Improve these in light on variable-size
+	sheets.
+
 2009-04-16  Morten Welinder  <terra gnome org>
 
 	* src/parse-util.c (col_parse, row_parse): Handle MAGIC_MAX_SHEET.
diff --git a/src/position.c b/src/position.c
index fd4caae..657b5c1 100644
--- a/src/position.c
+++ b/src/position.c
@@ -250,9 +250,11 @@ gnm_cellref_equal (GnmCellRef const *a, GnmCellRef const *b)
 guint
 gnm_cellref_hash (GnmCellRef const *cr)
 {
-	guint h = ((cr->row << 8) ^ cr->col) * 4;
-	if (cr->col_relative) h |= 1;
-	if (cr->row_relative) h |= 2;
+	guint h = cr->row;
+	h = (h << 16) | (h >> 16);
+	h ^= (cr->col << 2);
+	if (cr->col_relative) h ^= 1;
+	if (cr->row_relative) h ^= 2;
 	return h;
 }
 
@@ -365,7 +367,10 @@ gnm_rangeref_equal (GnmRangeRef const *a, GnmRangeRef const *b)
 guint
 gnm_rangeref_hash (GnmRangeRef const *rr)
 {
-	return gnm_cellref_hash (&rr->a) << 16 | gnm_cellref_hash (&rr->b);
+	guint h = gnm_cellref_hash (&rr->a);
+	h = (h << 16) | (h >> 16);
+	h ^= gnm_cellref_hash (&rr->b);
+	return h;
 }
 
 GnmRangeRef *
@@ -402,7 +407,10 @@ gnm_rangeref_normalize (GnmRangeRef const *ref, GnmEvalPos const *ep,
 guint
 gnm_cellpos_hash (GnmCellPos const *key)
 {
-	return (key->row << 8) | key->col;
+	guint h = key->row;
+	h = (h << 16) | (h >> 16);
+	h ^= key->col;
+	return h;
 }
 
 gint



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