Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same".
Equality is evaluated with a memcmp and size check. So it is possible that two identical objects where one lacks a bounding box could be evaluated as non-equal initially. Greater and less than are evaluated by calculating a sortable key from the center point of the object bounds.
314{
316 uint64_t hash1, hash2;
321 uint8_t *b1 = (uint8_t*)g1 + hsz1;
322 uint8_t *b2 = (uint8_t*)g2 + hsz2;
323 size_t bsz1 = sz1 - hsz1;
324 size_t bsz2 = sz2 - hsz2;
325 size_t bsz_min = bsz1 < bsz2 ? bsz1 : bsz2;
326
327
328
330 int cmp = memcmp(b1, b2, bsz_min);
335
336 if (bsz1 == bsz2 && cmp_srid == 0 && cmp == 0 && g1hasz == g2hasz && g1hasm == g2hasm)
337 return 0;
338 else
339 {
344
345
346 if (g1_is_empty && !g2_is_empty)
347 return -1;
348
349
350 if (!g1_is_empty && g2_is_empty)
351 return 1;
352
353 if (!g1_is_empty && !g2_is_empty)
354 {
355
358
359 if (hash1 > hash2)
360 return 1;
361 if (hash1 < hash2)
362 return -1;
363 }
364
365
366 if (bsz1 != bsz2 && cmp == 0)
367 {
368 if (bsz1 < bsz2)
369 return -1;
370 else if (bsz1 > bsz2)
371 return 1;
372 }
373
374
375 if (cmp_srid != 0)
376 return (srid1 > srid2) ? 1 : -1;
377
378
379 if (g1hasz != g2hasz)
380 return (g1hasz > g2hasz) ? 1 : -1;
381
382 if (g1hasm != g2hasm)
383 return (g1hasm > g2hasm) ? 1 : -1;
384
385 assert(cmp != 0);
386 return cmp > 0 ? 1 : -1;
387 }
388}
uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid)
Return a sortable key based on the center point of the GBOX.
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
static size_t gserialized_header_size(const GSERIALIZED *g)
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
static int gserialized_cmp_srid(const GSERIALIZED *g1, const GSERIALIZED *g2)
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.