/* **GiSTsupportmethods
*/
PG_FUNCTION_INFO_V1(gseg_consistent);
PG_FUNCTION_INFO_V1(gseg_compress);
PG_FUNCTION_INFO_V1(gseg_decompress);
PG_FUNCTION_INFO_V1(gseg_picksplit);
PG_FUNCTION_INFO_V1(gseg_penalty);
PG_FUNCTION_INFO_V1(gseg_union);
PG_FUNCTION_INFO_V1(gseg_same); static Datum gseg_leaf_consistent(Datum key, Datum query, StrategyNumber strategy); static Datum gseg_internal_consistent(Datum key, Datum query, StrategyNumber strategy); static Datum gseg_binary_union(Datum r1, Datum r2, int *sizep);
/* **TheGiSTUnionmethodforsegments **returnstheminimalboundingsegthatenclosesalltheentriesinentryvec
*/
Datum
gseg_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); int *sizep = (int *) PG_GETARG_POINTER(1); int numranges,
i;
Datum out = 0;
Datum tmp;
/* seg_over_left -- is the right edge of (a) located at or left of the right edge of (b)?
*/
Datum
seg_over_left(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
PG_RETURN_BOOL(a->upper <= b->upper);
}
/* seg_left -- is (a) entirely on the left of (b)?
*/
Datum
seg_left(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
PG_RETURN_BOOL(a->upper < b->lower);
}
/* seg_right -- is (a) entirely on the right of (b)?
*/
Datum
seg_right(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
PG_RETURN_BOOL(a->lower > b->upper);
}
/* seg_over_right -- is the left edge of (a) located at or right of the left edge of (b)?
*/
Datum
seg_over_right(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
PG_RETURN_BOOL(a->lower >= b->lower);
}
Datum
seg_union(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
SEG *n;
n = (SEG *) palloc(sizeof(*n));
/* take max of upper endpoints */ if (a->upper > b->upper)
{
n->upper = a->upper;
n->u_sigd = a->u_sigd;
n->u_ext = a->u_ext;
} else
{
n->upper = b->upper;
n->u_sigd = b->u_sigd;
n->u_ext = b->u_ext;
}
/* take min of lower endpoints */ if (a->lower < b->lower)
{
n->lower = a->lower;
n->l_sigd = a->l_sigd;
n->l_ext = a->l_ext;
} else
{
n->lower = b->lower;
n->l_sigd = b->l_sigd;
n->l_ext = b->l_ext;
}
PG_RETURN_POINTER(n);
}
Datum
seg_inter(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
SEG *n;
n = (SEG *) palloc(sizeof(*n));
/* take min of upper endpoints */ if (a->upper < b->upper)
{
n->upper = a->upper;
n->u_sigd = a->u_sigd;
n->u_ext = a->u_ext;
} else
{
n->upper = b->upper;
n->u_sigd = b->u_sigd;
n->u_ext = b->u_ext;
}
/* take max of lower endpoints */ if (a->lower > b->lower)
{
n->lower = a->lower;
n->l_sigd = a->l_sigd;
n->l_ext = a->l_ext;
} else
{
n->lower = b->lower;
n->l_sigd = b->l_sigd;
n->l_ext = b->l_ext;
}
/***************************************************************************** *Miscellaneousoperators
*****************************************************************************/
Datum
seg_cmp(PG_FUNCTION_ARGS)
{
SEG *a = PG_GETARG_SEG_P(0);
SEG *b = PG_GETARG_SEG_P(1);
/* *Firstcompareonlowerboundaryposition
*/ if (a->lower < b->lower)
PG_RETURN_INT32(-1); if (a->lower > b->lower)
PG_RETURN_INT32(1);
/* *a->lower==b->lower,soconsidertypeofboundary. * *A'-'lowerboundis<anyotherkind(thiscouldonlyberelevantif *-HUGE_VALisusedasaregulardatavalue).A'<'lowerboundis<any *otherkindexcept'-'.A'>'lowerboundis>anyotherkind.
*/ if (a->l_ext != b->l_ext)
{ if (a->l_ext == '-')
PG_RETURN_INT32(-1); if (b->l_ext == '-')
PG_RETURN_INT32(1); if (a->l_ext == '<')
PG_RETURN_INT32(-1); if (b->l_ext == '<')
PG_RETURN_INT32(1); if (a->l_ext == '>')
PG_RETURN_INT32(1); if (b->l_ext == '>')
PG_RETURN_INT32(-1);
}
/* *Forotherboundarytypes,consider#ofsignificantdigitsfirst.
*/ if (a->l_sigd < b->l_sigd) /* (a) is blurred and is likely to include (b) */
PG_RETURN_INT32(-1); if (a->l_sigd > b->l_sigd) /* (a) is less blurred and is likely to be
* included in (b) */
PG_RETURN_INT32(1);
/* *Forsame#ofdigits,anapproximateboundaryismoreblurredthan *exact.
*/ if (a->l_ext != b->l_ext)
{ if (a->l_ext == '~') /* (a) is approximate, while (b) is exact */
PG_RETURN_INT32(-1); if (b->l_ext == '~')
PG_RETURN_INT32(1); /* can't get here unless data is corrupt */
elog(ERROR, "bogus lower boundary types %d %d",
(int) a->l_ext, (int) b->l_ext);
}
/* at this point, the lower boundaries are identical */
/* *Firstcompareonupperboundaryposition
*/ if (a->upper < b->upper)
PG_RETURN_INT32(-1); if (a->upper > b->upper)
PG_RETURN_INT32(1);
/* *a->upper==b->upper,soconsidertypeofboundary. * *A'-'upperboundis>anyotherkind(thiscouldonlyberelevantif *HUGE_VALisusedasaregulardatavalue).A'<'upperboundis<any *otherkind.A'>'upperboundis>anyotherkindexcept'-'.
*/ if (a->u_ext != b->u_ext)
{ if (a->u_ext == '-')
PG_RETURN_INT32(1); if (b->u_ext == '-')
PG_RETURN_INT32(-1); if (a->u_ext == '<')
PG_RETURN_INT32(-1); if (b->u_ext == '<')
PG_RETURN_INT32(1); if (a->u_ext == '>')
PG_RETURN_INT32(1); if (b->u_ext == '>')
PG_RETURN_INT32(-1);
}
/* *Forotherboundarytypes,consider#ofsignificantdigitsfirst.Note *resulthereisconverseofthelower-boundarycase.
*/ if (a->u_sigd < b->u_sigd) /* (a) is blurred and is likely to include (b) */
PG_RETURN_INT32(1); if (a->u_sigd > b->u_sigd) /* (a) is less blurred and is likely to be
* included in (b) */
PG_RETURN_INT32(-1);
/* *Forsame#ofdigits,anapproximateboundaryismoreblurredthan *exact.Again,resultisconverseoflower-boundarycase.
*/ if (a->u_ext != b->u_ext)
{ if (a->u_ext == '~') /* (a) is approximate, while (b) is exact */
PG_RETURN_INT32(1); if (b->u_ext == '~')
PG_RETURN_INT32(-1); /* can't get here unless data is corrupt */
elog(ERROR, "bogus upper boundary types %d %d",
(int) a->u_ext, (int) b->u_ext);
}
PG_RETURN_INT32(0);
}
Datum
seg_lt(PG_FUNCTION_ARGS)
{ int cmp = DatumGetInt32(DirectFunctionCall2(seg_cmp,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)));
PG_RETURN_BOOL(cmp < 0);
}
Datum
seg_le(PG_FUNCTION_ARGS)
{ int cmp = DatumGetInt32(DirectFunctionCall2(seg_cmp,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)));
PG_RETURN_BOOL(cmp <= 0);
}
Datum
seg_gt(PG_FUNCTION_ARGS)
{ int cmp = DatumGetInt32(DirectFunctionCall2(seg_cmp,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)));
PG_RETURN_BOOL(cmp > 0);
}
Datum
seg_ge(PG_FUNCTION_ARGS)
{ int cmp = DatumGetInt32(DirectFunctionCall2(seg_cmp,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)));
PG_RETURN_BOOL(cmp >= 0);
}
Datum
seg_different(PG_FUNCTION_ARGS)
{ int cmp = DatumGetInt32(DirectFunctionCall2(seg_cmp,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)));
/* *Putacaponthenumberofsignificantdigitstoavoidgarbageinthe *outputandensurewedon'toverruntheresultbuffer.(nshouldnotbe *negative,butchecktoprotectourselvesagainstcorrupteddata.)
*/ if (n <= 0)
n = FLT_DIG; else
n = Min(n, FLT_DIG);
/* remember the sign */
sign = (val < 0 ? 1 : 0);
/* print, in %e style to start with */
sprintf(result, "%.*e", n - 1, val);
/* find the exponent */
p = strchr(result, 'e');
/* punt if we have 'inf' or similar */ if (p == NULL) return strlen(result);
exp = atoi(p + 1); if (exp == 0)
{ /* just truncate off the 'e+00' */
*p = '\0';
} else
{ if (abs(exp) <= 4)
{ /* *removethedecimalpointfromthemantissaandwritethedigits *tothebufarray
*/ for (p = result + sign, i = 10, dp = 0; *p != 'e'; p++, i++)
{
buf[i] = *p; if (*p == '.')
{
dp = i--; /* skip the decimal point */
}
} if (dp == 0)
dp = i--; /* no decimal point was found in the above
* for() loop */
/* do nothing for abs(exp) > 4; %e must be OK */ /* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
/* ... this is not done yet. */
} return strlen(result);
}
/* **Miscellany
*/
/* find out the number of significant digits in a string representing *afloatingpointnumber
*/ int
significant_digits(constchar *s)
{ constchar *p = s; int n,
c,
zeroes;
zeroes = 1; /* skip leading zeroes and sign */ for (c = *p; (c == '0' || c == '+' || c == '-') && c != 0; c = *(++p));
/* skip decimal point and following zeroes */ for (c = *p; (c == '0' || c == '.') && c != 0; c = *(++p))
{ if (c != '.')
zeroes++;
}
/* count significant digits (n) */ for (c = *p, n = 0; c != 0; c = *(++p))
{ if (!((c >= '0' && c <= '9') || (c == '.'))) break; if (c != '.')
n++;
}
if (!n) return zeroes;
return n;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-09)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.