PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized1_hash()

int32_t gserialized1_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 227 of file gserialized1.c.

228{
229 int32_t hval;
230 int32_t pb = 0, pc = 0;
231 /* Point to just the type/coordinate part of buffer */
232 size_t hsz1 = gserialized1_header_size(g1);
233 uint8_t *b1 = (uint8_t*)g1 + hsz1;
234 /* Calculate size of type/coordinate buffer */
235 size_t sz1 = LWSIZE_GET(g1->size);
236 size_t bsz1 = sz1 - hsz1;
237 /* Calculate size of srid/type/coordinate buffer */
238 int32_t srid = gserialized1_get_srid(g1);
239 size_t bsz2 = bsz1 + sizeof(int);
240 uint8_t *b2 = lwalloc(bsz2);
241 /* Copy srid into front of combined buffer */
242 memcpy(b2, &srid, sizeof(int));
243 /* Copy type/coordinates into rest of combined buffer */
244 memcpy(b2+sizeof(int), b1, bsz1);
245 /* Hash combined buffer */
246 hashlittle2(b2, bsz2, (uint32_t *)&pb, (uint32_t *)&pc);
247 lwfree(b2);
248 hval = pb ^ pc;
249 return hval;
250}
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
Definition lookup3.c:479
int32_t gserialized1_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
static uint32_t gserialized1_header_size(const GSERIALIZED *gser)
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
Definition liblwgeom.h:324
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
uint32_t size
Definition liblwgeom.h:444

References gserialized1_get_srid(), gserialized1_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: