PostGIS  3.0.6dev-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 268 of file gserialized2.c.

269 {
270  int32_t hval;
271  int32_t pb = 0, pc = 0;
272  /* Point to just the type/coordinate part of buffer */
273  size_t hsz1 = gserialized2_header_size(g1);
274  uint8_t *b1 = (uint8_t *)g1 + hsz1;
275  /* Calculate size of type/coordinate buffer */
276  size_t sz1 = SIZE_GET(g1->size);
277  size_t bsz1 = sz1 - hsz1;
278  /* Calculate size of srid/type/coordinate buffer */
279  int32_t srid = gserialized2_get_srid(g1);
280  size_t bsz2 = bsz1 + sizeof(int);
281  uint8_t *b2 = lwalloc(bsz2);
282  /* Copy srid into front of combined buffer */
283  memcpy(b2, &srid, sizeof(int));
284  /* Copy type/coordinates into rest of combined buffer */
285  memcpy(b2+sizeof(int), b1, bsz1);
286  /* Hash combined buffer */
287  hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
288  lwfree(b2);
289  hval = pb ^ pc;
290  return hval;
291 }
static size_t gserialized2_header_size(const GSERIALIZED *g)
Definition: gserialized2.c:89
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:190
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
Definition: lookup3.c:476
void lwfree(void *mem)
Definition: lwutil.c:242
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
uint32_t size
Definition: liblwgeom.h:430

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

Referenced by gserialized_hash().

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