PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum lwgeom_hash ( PG_FUNCTION_ARGS  )

Definition at line 132 of file lwgeom_btree.c.

References gserialized_get_srid(), and gserialized_header_size().

133 {
134  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
135  /* Point to just the type/coordinate part of buffer */
136  size_t hsz1 = gserialized_header_size(g1);
137  uint8_t *b1 = (uint8_t*)g1 + hsz1;
138  /* Calculate size of type/coordinate buffer */
139  size_t sz1 = VARSIZE(g1);
140  size_t bsz1 = sz1 - hsz1;
141  /* Calculate size of srid/type/coordinate buffer */
142  int srid = gserialized_get_srid(g1);
143  size_t bsz2 = bsz1 + sizeof(int);
144  uint8_t *b2 = palloc(bsz2);
145  /* Copy srid into front of combined buffer */
146  memcpy(b2, &srid, sizeof(int));
147  /* Copy type/coordinates into rest of combined buffer */
148  memcpy(b2+sizeof(int), b1, bsz1);
149  /* Hash combined buffer */
150  Datum hval = hash_any(b2, bsz2);
151  pfree(b2);
152  PG_FREE_IF_COPY(g1, 0);
153  PG_RETURN_DATUM(hval);
154 }
uint32_t gserialized_header_size(const GSERIALIZED *gser)
Returns the size in bytes of the header, from the start of the object up to the type number...
Definition: g_serialized.c:76
unsigned char uint8_t
Definition: uthash.h:79
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99

Here is the call graph for this function: