[postgis-tickets] r17575 - fix for 32-bit hash
Regina Obe
lr at pcorp.us
Mon Jul 1 11:15:25 PDT 2019
Author: robe
Date: 2019-07-01 11:15:25 -0700 (Mon, 01 Jul 2019)
New Revision: 17575
Modified:
trunk/NEWS
trunk/liblwgeom/gserialized.c
trunk/liblwgeom/gserialized.h
trunk/liblwgeom/gserialized1.c
trunk/liblwgeom/gserialized1.h
trunk/liblwgeom/gserialized2.c
trunk/liblwgeom/gserialized2.h
trunk/liblwgeom/liblwgeom.h.in
trunk/postgis/lwgeom_btree.c
Log:
fix for 32-bit hash
Closes #4433
Closes https://github.com/postgis/postgis/pull/429
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/NEWS 2019-07-01 18:15:25 UTC (rev 17575)
@@ -1,7 +1,13 @@
PostGIS 3.0.0alpha4
-comming next
+2019/xx/xx
+For full changes and enhancements, refer to PostGIS 3.0.0.
+This version requires PostgreSQL 9.5+-12 and GEOS >= 3.6+
+Additional features enabled if you are running Proj6+ and PostgreSQL 12
+* Major highlights *
+ - #4433 32-bit hash fix (requires reindexing your data if on 32-bit OS) (Raúl Marín)
+
PostGIS 3.0.0alpha3
2019/07/01
For full changes and enhancements, refer to PostGIS 3.0.0.
Modified: trunk/liblwgeom/gserialized.c
===================================================================
--- trunk/liblwgeom/gserialized.c 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized.c 2019-07-01 18:15:25 UTC (rev 17575)
@@ -110,7 +110,8 @@
* in the GSERIALIZED. Ignores metadata like flags and optional
* boxes, etc.
*/
-uint64_t gserialized_hash(const GSERIALIZED *g)
+int32_t
+gserialized_hash(const GSERIALIZED *g)
{
if (GFLAGS_GET_VERSION(g->gflags))
return gserialized2_hash(g);
Modified: trunk/liblwgeom/gserialized.h
===================================================================
--- trunk/liblwgeom/gserialized.h 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized.h 2019-07-01 18:15:25 UTC (rev 17575)
@@ -75,7 +75,7 @@
* in the GSERIALIZED. Ignores metadata like flags and optional
* boxes, etc.
*/
-extern uint64_t gserialized_hash(const GSERIALIZED *g);
+extern int32_t gserialized_hash(const GSERIALIZED *g);
/**
* Extract the SRID from the serialized form (it is packed into
Modified: trunk/liblwgeom/gserialized1.c
===================================================================
--- trunk/liblwgeom/gserialized1.c 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized1.c 2019-07-01 18:15:25 UTC (rev 17575)
@@ -221,11 +221,11 @@
/* pb = IN: secondary initval, OUT: secondary hash */
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
-
-uint64_t gserialized1_hash(const GSERIALIZED *g1)
+int32_t
+gserialized1_hash(const GSERIALIZED *g1)
{
- uint64_t hval;
- uint32_t pb = 0, pc = 0;
+ int32_t hval;
+ int32_t pb = 0, pc = 0;
/* Point to just the type/coordinate part of buffer */
size_t hsz1 = gserialized1_header_size(g1);
uint8_t *b1 = (uint8_t*)g1 + hsz1;
@@ -241,9 +241,9 @@
/* Copy type/coordinates into rest of combined buffer */
memcpy(b2+sizeof(int), b1, bsz1);
/* Hash combined buffer */
- hashlittle2(b2, bsz1, &pb, &pc);
+ hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
lwfree(b2);
- hval = pc + (((uint64_t)pb)<<32);
+ hval = pb ^ pc;
return hval;
}
Modified: trunk/liblwgeom/gserialized1.h
===================================================================
--- trunk/liblwgeom/gserialized1.h 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized1.h 2019-07-01 18:15:25 UTC (rev 17575)
@@ -86,7 +86,7 @@
* in the GSERIALIZED. Ignores metadata like flags and optional
* boxes, etc.
*/
-uint64_t gserialized1_hash(const GSERIALIZED *g);
+int32_t gserialized1_hash(const GSERIALIZED *g);
/**
* Extract the SRID from the serialized form (it is packed into
Modified: trunk/liblwgeom/gserialized2.c
===================================================================
--- trunk/liblwgeom/gserialized2.c 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized2.c 2019-07-01 18:15:25 UTC (rev 17575)
@@ -252,19 +252,19 @@
/* pb = IN: secondary initval, OUT: secondary hash */
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
-
-uint64_t gserialized2_hash(const GSERIALIZED *g)
+int32_t
+gserialized2_hash(const GSERIALIZED *g1)
{
- uint64_t hval;
- uint32_t pb = 0, pc = 0;
+ int32_t hval;
+ int32_t pb = 0, pc = 0;
/* Point to just the type/coordinate part of buffer */
- size_t hsz1 = gserialized2_header_size(g);
- uint8_t *b1 = (uint8_t*)g + hsz1;
+ size_t hsz1 = gserialized2_header_size(g1);
+ uint8_t *b1 = (uint8_t *)g1 + hsz1;
/* Calculate size of type/coordinate buffer */
- size_t sz1 = SIZE_GET(g->size);
+ size_t sz1 = SIZE_GET(g1->size);
size_t bsz1 = sz1 - hsz1;
/* Calculate size of srid/type/coordinate buffer */
- int32_t srid = gserialized2_get_srid(g);
+ int32_t srid = gserialized2_get_srid(g1);
size_t bsz2 = bsz1 + sizeof(int);
uint8_t *b2 = lwalloc(bsz2);
/* Copy srid into front of combined buffer */
@@ -272,9 +272,9 @@
/* Copy type/coordinates into rest of combined buffer */
memcpy(b2+sizeof(int), b1, bsz1);
/* Hash combined buffer */
- hashlittle2(b2, bsz1, &pb, &pc);
+ hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
lwfree(b2);
- hval = pc + (((uint64_t)pb)<<32);
+ hval = pb ^ pc;
return hval;
}
Modified: trunk/liblwgeom/gserialized2.h
===================================================================
--- trunk/liblwgeom/gserialized2.h 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/gserialized2.h 2019-07-01 18:15:25 UTC (rev 17575)
@@ -93,7 +93,7 @@
* in the GSERIALIZED. Ignores metadata like flags and optional
* boxes, etc.
*/
-uint64_t gserialized2_hash(const GSERIALIZED *g);
+int32_t gserialized2_hash(const GSERIALIZED *g);
/**
* Extract the SRID from the serialized form (it is packed into
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/liblwgeom/liblwgeom.h.in 2019-07-01 18:15:25 UTC (rev 17575)
@@ -735,7 +735,7 @@
* in the GSERIALIZED. Ignores metadata like flags and optional
* boxes, etc.
*/
-extern uint64_t gserialized_hash(const GSERIALIZED *g);
+extern int32_t gserialized_hash(const GSERIALIZED *g);
/**
* Extract the SRID from the serialized form (it is packed into
Modified: trunk/postgis/lwgeom_btree.c
===================================================================
--- trunk/postgis/lwgeom_btree.c 2019-07-01 14:03:24 UTC (rev 17574)
+++ trunk/postgis/lwgeom_btree.c 2019-07-01 18:15:25 UTC (rev 17575)
@@ -131,9 +131,9 @@
Datum lwgeom_hash(PG_FUNCTION_ARGS)
{
GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
- uint64_t hval = gserialized_hash(g1);
+ int32_t hval = gserialized_hash(g1);
PG_FREE_IF_COPY(g1, 0);
- PG_RETURN_DATUM(Int64GetDatum(hval));
+ PG_RETURN_INT32(hval);
}
More information about the postgis-tickets
mailing list