PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized2_hash()

int32_t gserialized2_hash ( const GSERIALIZED g)

Returns a hash code for the srid/type/geometry information in the GSERIALIZED.

Ignores metadata like flags and optional boxes, etc.

Definition at line 269 of file gserialized2.c.

270 {
271  int32_t hval;
272  int32_t pb = 0, pc = 0;
273  /* Point to just the type/coordinate part of buffer */
274  size_t hsz1 = gserialized2_header_size(g1);
275  uint8_t *b1 = (uint8_t *)g1 + hsz1;
276  /* Calculate size of type/coordinate buffer */
277  size_t sz1 = LWSIZE_GET(g1->size);
278  size_t bsz1 = sz1 - hsz1;
279  /* Calculate size of srid/type/coordinate buffer */
280  int32_t srid = gserialized2_get_srid(g1);
281  size_t bsz2 = bsz1 + sizeof(int);
282  uint8_t *b2 = lwalloc(bsz2);
283  /* Copy srid into front of combined buffer */
284  memcpy(b2, &srid, sizeof(int));
285  /* Copy type/coordinates into rest of combined buffer */
286  memcpy(b2+sizeof(int), b1, bsz1);
287  /* Hash combined buffer */
288  hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
289  lwfree(b2);
290  hval = pb ^ pc;
291  return hval;
292 }
static size_t gserialized2_header_size(const GSERIALIZED *g)
Definition: gserialized2.c:91
int32_t gserialized2_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized2.c:191
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
Definition: lookup3.c:479
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
Definition: liblwgeom.h:324
void lwfree(void *mem)
Definition: lwutil.c:242
void * lwalloc(size_t size)
Definition: lwutil.c:227

References gserialized2_get_srid(), gserialized2_header_size(), hashlittle2(), lwalloc(), lwfree(), LWSIZE_GET, and GSERIALIZED::size.

Referenced by gserialized_hash().

Here is the call graph for this function:
Here is the caller graph for this function: