Changeset: 4856519e93fd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4856519e93fd
Modified Files:
        gdk/gdk_hash.c
        geom/monetdb5/geom.c
Branch: default
Log Message:

Fix WKB and MBR hash functions to not use undefined operations.
The MBR hash function is changed, so this will remove hash tables based
on the old function (but keep other hashes in tact).


diffs (68 lines):

diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -100,10 +100,11 @@ HASHclear(Hash *h)
        memset(h->Bckt, 0xFF, h->nbucket * h->width);
 }
 
-#define HASH_VERSION           4
-/* this is only for the change of hash function of the UUID type; if
- * HASH_VERSION is increased again from 4, the code associated with
- * HASH_VERSION_NOUUID must be deleted */
+#define HASH_VERSION           5
+/* this is only for the change of hash function of the UUID type and MBR
+ * type; if HASH_VERSION is increased again from 5, the code associated
+ * with HASH_VERSION_NOUUID and HASH_VERSION_NOMBR must be deleted */
+#define HASH_VERSION_NOMBR     4
 #define HASH_VERSION_NOUUID    3
 #define HASH_HEADER_SIZE       7       /* nr of size_t fields in header */
 
@@ -500,7 +501,17 @@ BATcheckhash(BAT *b)
                                                         ((size_t) 1 << 24) |
 #endif
                                                         HASH_VERSION_NOUUID) &&
-                                                strcmp(ATOMname(b->ttype), 
"uuid") != 0)
+                                                strcmp(ATOMname(b->ttype), 
"uuid") != 0 &&
+                                                strcmp(ATOMname(b->ttype), 
"mbr") != 0)
+#endif
+#ifdef HASH_VERSION_NOMBR
+                                            /* if not uuid, also allow 
previous version */
+                                            || (hdata[0] == (
+#ifdef PERSISTENTHASH
+                                                        ((size_t) 1 << 24) |
+#endif
+                                                        HASH_VERSION_NOMBR) &&
+                                                strcmp(ATOMname(b->ttype), 
"mbr") != 0)
 #endif
                                                    ) &&
                                            hdata[1] > 0 &&
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -5169,7 +5169,15 @@ wkbHASH(const void *W)
        BUN h = 0;
 
        for (i = 0; i < (w->len - 1); i += 2) {
-               int a = *(w->data + i), b = *(w->data + i + 1);
+               BUN a = ((unsigned char *) w->data)[i];
+               BUN b = ((unsigned char *) w->data)[i + 1];
+#if '\377' < 0
+               /* maybe sign extend */
+               if (a & 0x80)
+                       a |= ~(BUN)0x7f;
+               if (b & 0x80)
+                       b |= ~(BUN)0x7f;
+#endif
                h = (h << 3) ^ (h >> 11) ^ (h >> 17) ^ (b << 8) ^ a;
        }
        return h;
@@ -5396,7 +5404,8 @@ static BUN
 mbrHASH(const void *ATOM)
 {
        const mbr *atom = ATOM;
-       return (BUN) (((int) atom->xmin * (int)atom->ymin) *((int) atom->xmax * 
(int)atom->ymax));
+       return ATOMhash(TYPE_flt, &atom->xmin) ^ ATOMhash(TYPE_flt, 
&atom->ymin) ^
+               ATOMhash(TYPE_flt, &atom->xmax) ^ ATOMhash(TYPE_flt, 
&atom->ymax);
 }
 
 static const void *
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to