PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_hash()

Datum lwgeom_hash ( PG_FUNCTION_ARGS  )

Definition at line 132 of file lwgeom_btree.c.

133 {
134  Datum hval;
135  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
136  /* Point to just the type/coordinate part of buffer */
137  size_t hsz1 = gserialized_header_size(g1);
138  uint8_t *b1 = (uint8_t*)g1 + hsz1;
139  /* Calculate size of type/coordinate buffer */
140  size_t sz1 = VARSIZE(g1);
141  size_t bsz1 = sz1 - hsz1;
142  /* Calculate size of srid/type/coordinate buffer */
143  int srid = gserialized_get_srid(g1);
144  size_t bsz2 = bsz1 + sizeof(int);
145  uint8_t *b2 = palloc(bsz2);
146  /* Copy srid into front of combined buffer */
147  memcpy(b2, &srid, sizeof(int));
148  /* Copy type/coordinates into rest of combined buffer */
149  memcpy(b2+sizeof(int), b1, bsz1);
150  /* Hash combined buffer */
151  hval = hash_any(b2, bsz2);
152  pfree(b2);
153  PG_FREE_IF_COPY(g1, 0);
154  PG_RETURN_DATUM(hval);
155 }
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:100
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

References gserialized_get_srid(), and gserialized_header_size().

Here is the call graph for this function: