• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MobilityDB / MobilityDB / 10320658152

09 Aug 2024 02:09PM UTC coverage: 95.198% (-0.03%) from 95.232%
10320658152

push

github

web-flow
Rename boxes functions (#557)

563 of 588 new or added lines in 9 files covered. (95.75%)

12 existing lines in 5 files now uncovered.

32570 of 34213 relevant lines covered (95.2%)

746150.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.27
/mobilitydb/src/general/spanset.c
1
/*****************************************************************************
2
 *
3
 * This MobilityDB code is provided under The PostgreSQL License.
4
 * Copyright (c) 2016-2024, Université libre de Bruxelles and MobilityDB
5
 * contributors
6
 *
7
 * MobilityDB includes portions of PostGIS version 3 source code released
8
 * under the GNU General Public License (GPLv2 or later).
9
 * Copyright (c) 2001-2024, PostGIS contributors
10
 *
11
 * Permission to use, copy, modify, and distribute this software and its
12
 * documentation for any purpose, without fee, and without a written
13
 * agreement is hereby granted, provided that the above copyright notice and
14
 * this paragraph and the following two paragraphs appear in all copies.
15
 *
16
 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18
 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19
 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20
 * OF SUCH DAMAGE.
21
 *
22
 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25
 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 *
28
 *****************************************************************************/
29

30
/**
31
 * @file
32
 * @brief General functions for span set types composed of a set of disjoint
33
 * spans
34
 */
35

36
/* C */
37
#include <assert.h>
38
/* PostgreSQL */
39
#include <postgres.h>
40
#if POSTGRESQL_VERSION_NUMBER >= 130000
41
  #include <access/heaptoast.h>
42
  #include <access/detoast.h>
43
#else
44
  #include <access/tuptoaster.h>
45
#endif
46
#include <utils/timestamp.h>
47
/* MEOS */
48
#include <meos.h>
49
#include <meos_internal.h>
50
#include "general/set.h"
51
#include "general/span.h"
52
#include "general/temporal.h"
53
#include "general/type_out.h"
54
#include "general/type_util.h"
55
/* MobilityDB */
56
#include "pg_general/meos_catalog.h"
57
#include "pg_general/span.h"
58
#include "pg_general/temporal.h"
59
#include "pg_general/type_util.h"
60

61
/*****************************************************************************
62
 * Input/output functions
63
 *****************************************************************************/
64

65
PGDLLEXPORT Datum Spanset_in(PG_FUNCTION_ARGS);
66
PG_FUNCTION_INFO_V1(Spanset_in);
32✔
67
/**
68
 * @ingroup mobilitydb_setspan_inout
69
 * @brief Return a span set from its Well-Known Text (WKT) representation
70
 * @sqlfn spanset_in()
71
 */
72
Datum
73
Spanset_in(PG_FUNCTION_ARGS)
13,144✔
74
{
75
  const char *input = PG_GETARG_CSTRING(0);
13,144✔
76
  Oid sstypid = PG_GETARG_OID(1);
13,144✔
77
  SpanSet *result = spanset_in(input, oid_type(sstypid));
13,144✔
78
  PG_RETURN_SPANSET_P(result);
13,142✔
79
}
80

81
PGDLLEXPORT Datum Spanset_out(PG_FUNCTION_ARGS);
82
PG_FUNCTION_INFO_V1(Spanset_out);
18✔
83
/**
84
 * @ingroup mobilitydb_setspan_inout
85
 * @brief Return the Well-Known Text (WKT) representation of a span set
86
 * @sqlfn spanset_out()
87
 */
88
Datum
89
Spanset_out(PG_FUNCTION_ARGS)
171✔
90
{
91
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
171✔
92
  char *result = spanset_out(ss, Int32GetDatum(OUT_DEFAULT_DECIMAL_DIGITS));
171✔
93
  PG_FREE_IF_COPY(ss, 0);
171✔
94
  PG_RETURN_CSTRING(result);
171✔
95
}
96

97
PGDLLEXPORT Datum Spanset_recv(PG_FUNCTION_ARGS);
98
PG_FUNCTION_INFO_V1(Spanset_recv);
10✔
99
/**
100
 * @ingroup mobilitydb_setspan_inout
101
 * @brief Return a span set from its Well-Known Binary (WKB) representation
102
 * @sqlfn spanset_recv()
103
 */
104
Datum
105
Spanset_recv(PG_FUNCTION_ARGS)
495✔
106
{
107
  StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
495✔
108
  SpanSet *result = spanset_from_wkb((uint8_t *) buf->data, buf->len);
495✔
109
  /* Set cursor to the end of buffer (so the backend is happy) */
110
  buf->cursor = buf->len;
495✔
111
  PG_RETURN_SPANSET_P(result);
495✔
112
}
113

114
PGDLLEXPORT Datum Spanset_send(PG_FUNCTION_ARGS);
115
PG_FUNCTION_INFO_V1(Spanset_send);
10✔
116
/**
117
 * @ingroup mobilitydb_setspan_inout
118
 * @brief Return the Well-Known Binary (WKB) representation of a span set
119
 * @sqlfn spanset_send()
120
 */
121
Datum
122
Spanset_send(PG_FUNCTION_ARGS)
495✔
123
{
124
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
495✔
125
  uint8_t variant = 0;
126
  size_t wkb_size = VARSIZE_ANY_EXHDR(ss);
495✔
127
  uint8_t *wkb = spanset_as_wkb(ss, variant, &wkb_size);
495✔
128
  bytea *result = bstring2bytea(wkb, wkb_size);
495✔
129
  pfree(wkb);
495✔
130
  PG_RETURN_BYTEA_P(result);
495✔
131
}
132

133
/*****************************************************************************
134
 * Constructor functions
135
 ****************************************************************************/
136

137
PGDLLEXPORT Datum Spanset_constructor(PG_FUNCTION_ARGS);
138
PG_FUNCTION_INFO_V1(Spanset_constructor);
10✔
139
/**
140
 * @ingroup mobilitydb_setspan_constructor
141
 * @brief Return a span set from an array of spans
142
 * @sqlfn spanset()
143
 */
144
Datum
145
Spanset_constructor(PG_FUNCTION_ARGS)
7✔
146
{
147
  ArrayType *array = PG_GETARG_ARRAYTYPE_P(0);
7✔
148
  ensure_not_empty_array(array);
7✔
149
  int count;
150
  Span *spans = spanarr_extract(array, &count);
6✔
151
  SpanSet *result = spanset_make_free(spans, count, NORMALIZE, ORDER_NO);
6✔
152
  PG_FREE_IF_COPY(array, 0);
5✔
153
  PG_RETURN_SPANSET_P(result);
5✔
154
}
155

156
/*****************************************************************************
157
 * Conversion functions
158
 *****************************************************************************/
159

160
PGDLLEXPORT Datum Value_to_spanset(PG_FUNCTION_ARGS);
161
PG_FUNCTION_INFO_V1(Value_to_spanset);
7✔
162
/**
163
 * @ingroup mobilitydb_setspan_conversion
164
 * @brief Return a value converted to a span set
165
 * @sqlfn intspanset(), floatspanset(), ...
166
 */
167
Datum
168
Value_to_spanset(PG_FUNCTION_ARGS)
4✔
169
{
170
  Datum value = PG_GETARG_DATUM(0);
4✔
171
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 0));
4✔
172
  PG_RETURN_SPANSET_P(value_to_spanset(value, basetype));
4✔
173
}
174

175
PGDLLEXPORT Datum Set_to_spanset(PG_FUNCTION_ARGS);
176
PG_FUNCTION_INFO_V1(Set_to_spanset);
7✔
177
/**
178
 * @ingroup mobilitydb_setspan_conversion
179
 * @brief Return a set converted to a span set
180
 * @sqlfn intspanset(), floatspanset(), ...
181
 */
182
Datum
183
Set_to_spanset(PG_FUNCTION_ARGS)
4✔
184
{
185
  Set *s = PG_GETARG_SET_P(0);
4✔
186
  SpanSet *result = set_spanset(s);
4✔
187
  PG_FREE_IF_COPY(s, 0);
4✔
188
  PG_RETURN_SPANSET_P(result);
4✔
189
}
190

191
PGDLLEXPORT Datum Span_to_spanset(PG_FUNCTION_ARGS);
192
PG_FUNCTION_INFO_V1(Span_to_spanset);
12✔
193
/**
194
 * @ingroup mobilitydb_setspan_conversion
195
 * @brief Return a span converted to a span set
196
 * @sqlfn instspanset(), floatspanset(), ...
197
 */
198
Datum
199
Span_to_spanset(PG_FUNCTION_ARGS)
499✔
200
{
201
  Span *s = PG_GETARG_SPAN_P(0);
499✔
202
  PG_RETURN_SPANSET_P(span_spanset(s));
499✔
203
}
204

205
/**
206
 * @brief Peek into a span set datum to find the bounding box
207
 * @note If the datum needs to be detoasted, extract only the header and not
208
 * the full object
209
 */
210
void
211
spanset_span_slice(Datum d, Span *s)
2,194,167✔
212
{
213
  SpanSet *ss = NULL;
214
  if (PG_DATUM_NEEDS_DETOAST((struct varlena *) d))
2,194,167✔
215
    ss = (SpanSet *) PG_DETOAST_DATUM_SLICE(d, 0, time_max_header_size());
19,616✔
216
  else
217
    ss = (SpanSet *) d;
218
  memcpy(s, &ss->span, sizeof(Span));
2,194,167✔
219
  // PG_FREE_IF_COPY_P(ss, DatumGetPointer(d));
220
  return;
2,194,167✔
221
}
222

223
PGDLLEXPORT Datum Spanset_to_span(PG_FUNCTION_ARGS);
224
PG_FUNCTION_INFO_V1(Spanset_to_span);
14✔
225
/**
226
 * @ingroup mobilitydb_setspan_conversion
227
 * @brief Return a span set converted to a span
228
 * @sqlfn span()
229
 */
230
Datum
231
Spanset_to_span(PG_FUNCTION_ARGS)
505✔
232
{
233
  Datum d = PG_GETARG_DATUM(0);
505✔
234
  Span *result = palloc(sizeof(Span));
505✔
235
  spanset_span_slice(d, result);
505✔
236
  PG_RETURN_SPANSET_P(result);
505✔
237
}
238

239
PGDLLEXPORT Datum Intspanset_to_floatspanset(PG_FUNCTION_ARGS);
240
PG_FUNCTION_INFO_V1(Intspanset_to_floatspanset);
2✔
241
/**
242
 * @ingroup mobilitydb_setspan_conversion
243
 * @brief Return an integer span set converted to a float spanset
244
 * @sqlfn floatspanset()
245
 * @sqlop @p ::
246
 */
247
Datum
248
Intspanset_to_floatspanset(PG_FUNCTION_ARGS)
99✔
249
{
250
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
99✔
251
  SpanSet *result = intspanset_floatspanset(ss);
99✔
252
  PG_FREE_IF_COPY(ss, 0);
99✔
253
  PG_RETURN_SPANSET_P(result);
99✔
254
}
255

256
PGDLLEXPORT Datum Floatspanset_to_intspanset(PG_FUNCTION_ARGS);
257
PG_FUNCTION_INFO_V1(Floatspanset_to_intspanset);
2✔
258
/**
259
 * @ingroup mobilitydb_setspan_conversion
260
 * @brief Return a float span set converted to an integer spanset
261
 * @sqlfn intspanset()
262
 * @sqlop @p ::
263
 */
264
Datum
265
Floatspanset_to_intspanset(PG_FUNCTION_ARGS)
99✔
266
{
267
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
99✔
268
  SpanSet *result = floatspanset_intspanset(ss);
99✔
269
  PG_FREE_IF_COPY(ss, 0);
99✔
270
  PG_RETURN_SPANSET_P(result);
99✔
271
}
272

273
PGDLLEXPORT Datum Datespanset_to_tstzspanset(PG_FUNCTION_ARGS);
274
PG_FUNCTION_INFO_V1(Datespanset_to_tstzspanset);
3✔
275
/**
276
 * @ingroup mobilitydb_setspan_conversion
277
 * @brief Return a date span set converted to a timestamptz span set
278
 * @sqlfn tstzspanset()
279
 * @sqlop @p ::
280
 */
281
Datum
282
Datespanset_to_tstzspanset(PG_FUNCTION_ARGS)
297✔
283
{
284
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
297✔
285
  SpanSet *result = datespanset_tstzspanset(ss);
297✔
286
  PG_FREE_IF_COPY(ss, 0);
297✔
287
  PG_RETURN_SPANSET_P(result);
297✔
288
}
289

290
PGDLLEXPORT Datum Tstzspanset_to_datespanset(PG_FUNCTION_ARGS);
291
PG_FUNCTION_INFO_V1(Tstzspanset_to_datespanset);
3✔
292
/**
293
 * @ingroup mobilitydb_setspan_conversion
294
 * @brief Return a timestamptz span set converted to a date span set
295
 * @sqlfn datespanset()
296
 * @sqlop @p ::
297
 */
298
Datum
299
Tstzspanset_to_datespanset(PG_FUNCTION_ARGS)
297✔
300
{
301
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
297✔
302
  SpanSet *result = tstzspanset_datespanset(ss);
297✔
303
  PG_FREE_IF_COPY(ss, 0);
297✔
304
  PG_RETURN_SPANSET_P(result);
297✔
305
}
306

307
/*****************************************************************************/
308

309
#if POSTGRESQL_VERSION_NUMBER >= 140000
310
PGDLLEXPORT Datum Spanset_to_multirange(PG_FUNCTION_ARGS);
311
PG_FUNCTION_INFO_V1(Spanset_to_multirange);
8✔
312
/**
313
 * @ingroup mobilitydb_setspan_conversion
314
 * @brief Return a span set converted to a multirange
315
 * @sqlfn int4range(), tstzrange()
316
 * @sqlop @p ::
317
 */
318
Datum
319
Spanset_to_multirange(PG_FUNCTION_ARGS)
396✔
320
{
321
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
396✔
322
  assert(ss->spantype == T_INTSPAN || ss->spantype == T_BIGINTSPAN ||
323
    ss->spantype == T_DATESPAN || ss->spantype == T_TSTZSPAN);
324
  MultirangeType *result = multirange_make(ss);
396✔
325
  PG_FREE_IF_COPY(ss, 0);
396✔
326
  PG_RETURN_MULTIRANGE_P(result);
396✔
327
}
328

329
PGDLLEXPORT Datum Multirange_to_spanset(PG_FUNCTION_ARGS);
330
PG_FUNCTION_INFO_V1(Multirange_to_spanset);
9✔
331
/**
332
 * @ingroup mobilitydb_setspan_conversion
333
 * @brief Return a multirange converted to a span set
334
 * @sqlfn intspanset(), tstzspanset()
335
 * @sqlop @p ::
336
 */
337
Datum
338
Multirange_to_spanset(PG_FUNCTION_ARGS)
398✔
339
{
340
  MultirangeType *mrange = PG_GETARG_MULTIRANGE_P(0);
398✔
341
  TypeCacheEntry *typcache = multirange_get_typcache(fcinfo,
398✔
342
    MultirangeTypeGetOid(mrange));
343

344
  if (MultirangeIsEmpty(mrange))
398✔
345
    ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
1✔
346
      errmsg("Multirange cannot be empty")));
347

348
  Span *spans = palloc(sizeof(Span) * mrange->rangeCount);
397✔
349
  for (uint32 i = 0; i < mrange->rangeCount; i++)
3,088✔
350
  {
351
    RangeType *range = multirange_get_range(typcache->rngtype, mrange, i);
2,692✔
352
    range_set_span(range, typcache->rngtype, &spans[i]);
2,692✔
353
  }
354
  SpanSet *result = spanset_make_free(spans, mrange->rangeCount, NORMALIZE,
396✔
355
    ORDER_NO);
356
  PG_FREE_IF_COPY(mrange, 0);
396✔
357
  PG_RETURN_SPANSET_P(result);
396✔
358
}
359
#endif /* POSTGRESQL_VERSION_NUMBER >= 140000 */
360

361
/*****************************************************************************
362
 * Accessor functions
363
 *****************************************************************************/
364

365
PGDLLEXPORT Datum Spanset_mem_size(PG_FUNCTION_ARGS);
366
PG_FUNCTION_INFO_V1(Spanset_mem_size);
12✔
367
/**
368
 * @ingroup mobilitydb_setspan_accessor
369
 * @brief Return the memory size in bytes of a span set
370
 * @sqlfn memSize()
371
 */
372
Datum
373
Spanset_mem_size(PG_FUNCTION_ARGS)
306✔
374
{
375
  PG_RETURN_DATUM(toast_raw_datum_size(PG_GETARG_DATUM(0)));
306✔
376
}
377

378
PGDLLEXPORT Datum Spanset_lower(PG_FUNCTION_ARGS);
379
PG_FUNCTION_INFO_V1(Spanset_lower);
15✔
380
/**
381
 * @ingroup mobilitydb_setspan_accessor
382
 * @brief Return the lower bound of a span set
383
 * @sqlfn lower()
384
 */
385
Datum
386
Spanset_lower(PG_FUNCTION_ARGS)
2,576✔
387
{
388
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
2,576✔
389
  Datum result = spanset_lower(ss);
2,576✔
390
  PG_FREE_IF_COPY(ss, 0);
2,576✔
391
  PG_RETURN_DATUM(result);
2,576✔
392
}
393

394
PGDLLEXPORT Datum Spanset_upper(PG_FUNCTION_ARGS);
395
PG_FUNCTION_INFO_V1(Spanset_upper);
10✔
396
/**
397
 * @ingroup mobilitydb_setspan_accessor
398
 * @brief Return the upper bound of a span set
399
 * @sqlfn upper()
400
 */
401
Datum
402
Spanset_upper(PG_FUNCTION_ARGS)
299✔
403
{
404
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
299✔
405
  Datum result = spanset_upper(ss);
299✔
406
  PG_FREE_IF_COPY(ss, 0);
299✔
407
  PG_RETURN_DATUM(result);
299✔
408
}
409

410
/* span -> bool functions */
411

412
PGDLLEXPORT Datum Spanset_lower_inc(PG_FUNCTION_ARGS);
413
PG_FUNCTION_INFO_V1(Spanset_lower_inc);
10✔
414
/**
415
 * @ingroup mobilitydb_setspan_accessor
416
 * @brief Return true if the lower bound of a span set is inclusive
417
 * @sqlfn lower_inc()
418
 */
419
Datum
420
Spanset_lower_inc(PG_FUNCTION_ARGS)
299✔
421
{
422
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
299✔
423
  bool result = spanset_lower_inc(ss);
299✔
424
  PG_FREE_IF_COPY(ss, 0);
299✔
425
  PG_RETURN_BOOL(result);
299✔
426
}
427

428
Datum Spanset_upper_inc(PG_FUNCTION_ARGS);
429
PG_FUNCTION_INFO_V1(Spanset_upper_inc);
10✔
430
/**
431
 * @ingroup mobilitydb_setspan_accessor
432
 * @brief Return true if the upper bound of a span set is inclusive
433
 * @sqlfn lower_inc()
434
 */
435
Datum
436
Spanset_upper_inc(PG_FUNCTION_ARGS)
299✔
437
{
438
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
299✔
439
  bool result = spanset_upper_inc(ss);
299✔
440
  PG_FREE_IF_COPY(ss, 0);
299✔
441
  PG_RETURN_BOOL(result);
299✔
442
}
443

444
PGDLLEXPORT Datum Numspanset_width(PG_FUNCTION_ARGS);
445
PG_FUNCTION_INFO_V1(Numspanset_width);
7✔
446
/**
447
 * @ingroup mobilitydb_setspan_accessor
448
 * @brief Return the width of a number span set
449
 * @sqlfn width()
450
 */
451
Datum
452
Numspanset_width(PG_FUNCTION_ARGS)
202✔
453
{
454
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
202✔
455
  bool boundspan = PG_GETARG_BOOL(1);
202✔
456
  Datum result = numspanset_width(ss, boundspan);
202✔
457
  PG_FREE_IF_COPY(ss, 0);
202✔
458
  PG_RETURN_DATUM(result);
202✔
459
}
460

461
Datum Datespanset_duration(PG_FUNCTION_ARGS);
462
PG_FUNCTION_INFO_V1(Datespanset_duration);
3✔
463
/**
464
 * @ingroup mobilitydb_setspan_accessor
465
 * @brief Return the duration of a date span set
466
 * @sqlfn duration()
467
 */
468
Datum
469
Datespanset_duration(PG_FUNCTION_ARGS)
204✔
470
{
471
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
204✔
472
  bool boundspan = PG_GETARG_BOOL(1);
204✔
473
  Interval *result = datespanset_duration(ss, boundspan);
204✔
474
  PG_FREE_IF_COPY(ss, 0);
204✔
475
  PG_RETURN_INTERVAL_P(result);
204✔
476
}
477

478
Datum Tstzspanset_duration(PG_FUNCTION_ARGS);
479
PG_FUNCTION_INFO_V1(Tstzspanset_duration);
7✔
480
/**
481
 * @ingroup mobilitydb_setspan_accessor
482
 * @brief Return the duration of a timestamptz span set
483
 * @sqlfn duration()
484
 */
485
Datum
486
Tstzspanset_duration(PG_FUNCTION_ARGS)
1,189✔
487
{
488
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
1,189✔
489
  bool boundspan = PG_GETARG_BOOL(1);
1,189✔
490
  Interval *result = tstzspanset_duration(ss, boundspan);
1,189✔
491
  PG_FREE_IF_COPY(ss, 0);
1,189✔
492
  PG_RETURN_INTERVAL_P(result);
1,189✔
493
}
494

495
PGDLLEXPORT Datum Datespanset_num_dates(PG_FUNCTION_ARGS);
496
PG_FUNCTION_INFO_V1(Datespanset_num_dates);
2✔
497
/**
498
 * @ingroup mobilitydb_setspan_accessor
499
 * @brief Return the number of dates of a span set
500
 * @sqlfn numDates()
501
 */
502
Datum
503
Datespanset_num_dates(PG_FUNCTION_ARGS)
2✔
504
{
505
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
2✔
506
  int result = datespanset_num_dates(ss);
2✔
507
  PG_FREE_IF_COPY(ss, 0);
2✔
508
  PG_RETURN_INT32(result);
2✔
509
}
510

511
PGDLLEXPORT Datum Datespanset_start_date(PG_FUNCTION_ARGS);
512
PG_FUNCTION_INFO_V1(Datespanset_start_date);
2✔
513
/**
514
 * @ingroup mobilitydb_setspan_accessor
515
 * @brief Return the start date of a span set
516
 * @sqlfn startDate()
517
 */
518
Datum
519
Datespanset_start_date(PG_FUNCTION_ARGS)
2✔
520
{
521
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
2✔
522
  DateADT result = datespanset_start_date(ss);
2✔
523
  PG_FREE_IF_COPY(ss, 0);
2✔
524
  PG_RETURN_DATEADT(result);
2✔
525
}
526

527
PGDLLEXPORT Datum Datespanset_end_date(PG_FUNCTION_ARGS);
528
PG_FUNCTION_INFO_V1(Datespanset_end_date);
2✔
529
/**
530
 * @ingroup mobilitydb_setspan_accessor
531
 * @brief Return the end date of a span set
532
 * @sqlfn endDate()
533
 */
534
Datum
535
Datespanset_end_date(PG_FUNCTION_ARGS)
2✔
536
{
537
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
2✔
538
  DateADT result = datespanset_end_date(ss);
2✔
539
  PG_FREE_IF_COPY(ss, 0);
2✔
540
  PG_RETURN_DATEADT(result);
2✔
541
}
542

543
PGDLLEXPORT Datum Datespanset_date_n(PG_FUNCTION_ARGS);
544
PG_FUNCTION_INFO_V1(Datespanset_date_n);
2✔
545
/**
546
 * @ingroup mobilitydb_setspan_accessor
547
 * @brief Return the n-th date of a span set
548
 * @sqlfn dateN()
549
 */
550
Datum
551
Datespanset_date_n(PG_FUNCTION_ARGS)
4✔
552
{
553
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
4✔
554
  int n = PG_GETARG_INT32(1); /* Assume 1-based */
4✔
555
  DateADT result;
556
  bool found = datespanset_date_n(ss, n, &result);
4✔
557
  PG_FREE_IF_COPY(ss, 0);
4✔
558
  if (! found)
4✔
559
    PG_RETURN_NULL();
2✔
560
  PG_RETURN_DATEADT(result);
2✔
561
}
562

563
PGDLLEXPORT Datum Datespanset_dates(PG_FUNCTION_ARGS);
564
PG_FUNCTION_INFO_V1(Datespanset_dates);
2✔
565
/**
566
 * @ingroup mobilitydb_setspan_accessor
567
 * @brief Return the set of dates of a span set
568
 * @sqlfn dates()
569
 */
570
Datum
571
Datespanset_dates(PG_FUNCTION_ARGS)
2✔
572
{
573
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
2✔
574
  Set *result = datespanset_dates(ss);
2✔
575
  PG_FREE_IF_COPY(ss, 0);
2✔
576
  PG_RETURN_SET_P(result);
2✔
577
}
578

579
PGDLLEXPORT Datum Tstzspanset_num_timestamps(PG_FUNCTION_ARGS);
580
PG_FUNCTION_INFO_V1(Tstzspanset_num_timestamps);
3✔
581
/**
582
 * @ingroup mobilitydb_setspan_accessor
583
 * @brief Return the number of timestamptz values of a span set
584
 * @sqlfn numTimestamps()
585
 */
586
Datum
587
Tstzspanset_num_timestamps(PG_FUNCTION_ARGS)
105✔
588
{
589
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
105✔
590
  int result = tstzspanset_num_timestamps(ss);
105✔
591
  PG_FREE_IF_COPY(ss, 0);
105✔
592
  PG_RETURN_INT32(result);
105✔
593
}
594

595
PGDLLEXPORT Datum Tstzspanset_start_timestamptz(PG_FUNCTION_ARGS);
596
PG_FUNCTION_INFO_V1(Tstzspanset_start_timestamptz);
3✔
597
/**
598
 * @ingroup mobilitydb_setspan_accessor
599
 * @brief Return the start timestamptz of a span set
600
 * @sqlfn startTimestamp()
601
 */
602
Datum
603
Tstzspanset_start_timestamptz(PG_FUNCTION_ARGS)
204✔
604
{
605
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
204✔
606
  TimestampTz result = tstzspanset_start_timestamptz(ss);
204✔
607
  PG_FREE_IF_COPY(ss, 0);
204✔
608
  PG_RETURN_TIMESTAMPTZ(result);
204✔
609
}
610

611
PGDLLEXPORT Datum Tstzspanset_end_timestamptz(PG_FUNCTION_ARGS);
612
PG_FUNCTION_INFO_V1(Tstzspanset_end_timestamptz);
3✔
613
/**
614
 * @ingroup mobilitydb_setspan_accessor
615
 * @brief Return the end timestamptz of a span set
616
 * @sqlfn endTimestamp()
617
 */
618
Datum
619
Tstzspanset_end_timestamptz(PG_FUNCTION_ARGS)
105✔
620
{
621
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
105✔
622
  TimestampTz result = tstzspanset_end_timestamptz(ss);
105✔
623
  PG_FREE_IF_COPY(ss, 0);
105✔
624
  PG_RETURN_TIMESTAMPTZ(result);
105✔
625
}
626

627
PGDLLEXPORT Datum Tstzspanset_timestamptz_n(PG_FUNCTION_ARGS);
628
PG_FUNCTION_INFO_V1(Tstzspanset_timestamptz_n);
3✔
629
/**
630
 * @ingroup mobilitydb_setspan_accessor
631
 * @brief Return the n-th timestamptz of a span set
632
 * @sqlfn timestampN()
633
 */
634
Datum
635
Tstzspanset_timestamptz_n(PG_FUNCTION_ARGS)
106✔
636
{
637
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
106✔
638
  int n = PG_GETARG_INT32(1); /* Assume 1-based */
106✔
639
  TimestampTz result;
640
  bool found = tstzspanset_timestamptz_n(ss, n, &result);
106✔
641
  PG_FREE_IF_COPY(ss, 0);
106✔
642
  if (! found)
106✔
643
    PG_RETURN_NULL();
101✔
644
  PG_RETURN_TIMESTAMPTZ(result);
5✔
645
}
646

647
PGDLLEXPORT Datum Tstzspanset_timestamps(PG_FUNCTION_ARGS);
648
PG_FUNCTION_INFO_V1(Tstzspanset_timestamps);
3✔
649
/**
650
 * @ingroup mobilitydb_setspan_accessor
651
 * @brief Return the array of timestamptz values of a span set
652
 * @sqlfn timestamps()
653
 */
654
Datum
655
Tstzspanset_timestamps(PG_FUNCTION_ARGS)
105✔
656
{
657
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
105✔
658
  Set *result = tstzspanset_timestamps(ss);
105✔
659
  PG_FREE_IF_COPY(ss, 0);
105✔
660
  PG_RETURN_SET_P(result);
105✔
661
}
662

663
PGDLLEXPORT Datum Spanset_num_spans(PG_FUNCTION_ARGS);
664
PG_FUNCTION_INFO_V1(Spanset_num_spans);
15✔
665
/**
666
 * @ingroup mobilitydb_setspan_accessor
667
 * @brief Return the number of spans of a span set
668
 * @sqlfn numSpans()
669
 */
670
Datum
671
Spanset_num_spans(PG_FUNCTION_ARGS)
501✔
672
{
673
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
501✔
674
  int result = spanset_num_spans(ss);
501✔
675
  PG_FREE_IF_COPY(ss, 0);
501✔
676
  PG_RETURN_INT32(result);
501✔
677
}
678

679
PGDLLEXPORT Datum Spanset_start_span(PG_FUNCTION_ARGS);
680
PG_FUNCTION_INFO_V1(Spanset_start_span);
12✔
681
/**
682
 * @ingroup mobilitydb_setspan_accessor
683
 * @brief Return the start span of a span set
684
 * @sqlfn startSpan()
685
 */
686
Datum
687
Spanset_start_span(PG_FUNCTION_ARGS)
306✔
688
{
689
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
306✔
690
  Span *result = spanset_start_span(ss);
306✔
691
  PG_FREE_IF_COPY(ss, 0);
306✔
692
  PG_RETURN_SPAN_P(result);
306✔
693
}
694

695
PGDLLEXPORT Datum Spanset_end_span(PG_FUNCTION_ARGS);
696
PG_FUNCTION_INFO_V1(Spanset_end_span);
12✔
697
/**
698
 * @ingroup mobilitydb_setspan_accessor
699
 * @brief Return the end span of a span set
700
 * @sqlfn endSpan()
701
 */
702
Datum
703
Spanset_end_span(PG_FUNCTION_ARGS)
306✔
704
{
705
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
306✔
706
  Span *result = spanset_end_span(ss);
306✔
707
  PG_FREE_IF_COPY(ss, 0);
306✔
708
  PG_RETURN_SPAN_P(result);
306✔
709
}
710

711
PGDLLEXPORT Datum Spanset_span_n(PG_FUNCTION_ARGS);
712
PG_FUNCTION_INFO_V1(Spanset_span_n);
12✔
713
/**
714
 * @ingroup mobilitydb_setspan_accessor
715
 * @brief Return the n-th span of a span set
716
 * @sqlfn spanN()
717
 */
718
Datum
719
Spanset_span_n(PG_FUNCTION_ARGS)
306✔
720
{
721
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
306✔
722
  int i = PG_GETARG_INT32(1); /* Assume 1-based */
306✔
723
  Span *result = spanset_span_n(ss, i);
306✔
724
  PG_FREE_IF_COPY(ss, 0);
306✔
725
  if (! result)
306✔
726
    PG_RETURN_NULL();
2✔
727
  PG_RETURN_SPAN_P(result);
304✔
728
}
729

730
/*****************************************************************************
731
 * Transformation functions
732
 *
733
 * Since in PostgreSQL the type date is defined as follows
734
 *   typedef int32 DateADT;
735
 * the functions #Numspan_shift, #Numspan_scale, and #Numspan_shift_scale are
736
 * also used for datespans and datespansets
737
 *****************************************************************************/
738

739
PGDLLEXPORT Datum Numspanset_shift(PG_FUNCTION_ARGS);
740
PG_FUNCTION_INFO_V1(Numspanset_shift);
8✔
741
/**
742
 * @ingroup mobilitydb_setspan_transf
743
 * @brief Return a number span set shifted by a value
744
 * @note This function is also used for `datespanset`
745
 * @sqlfn shift()
746
 */
747
Datum
748
Numspanset_shift(PG_FUNCTION_ARGS)
298✔
749
{
750
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
298✔
751
  Datum shift = PG_GETARG_DATUM(1);
298✔
752
  SpanSet *result = numspanset_shift_scale(ss, shift, 0, true, false);
298✔
753
  PG_FREE_IF_COPY(ss, 0);
298✔
754
  PG_RETURN_SPANSET_P(result);
298✔
755
}
756

757
PGDLLEXPORT Datum Tstzspanset_shift(PG_FUNCTION_ARGS);
758
PG_FUNCTION_INFO_V1(Tstzspanset_shift);
3✔
759
/**
760
 * @ingroup mobilitydb_setspan_transf
761
 * @brief Return a timestamptz span set shifted by an interval
762
 * @sqlfn shift()
763
 */
764
Datum
765
Tstzspanset_shift(PG_FUNCTION_ARGS)
105✔
766
{
767
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
105✔
768
  Interval *shift = PG_GETARG_INTERVAL_P(1);
105✔
769
  SpanSet *result = tstzspanset_shift_scale(ss, shift, NULL);
105✔
770
  PG_FREE_IF_COPY(ss, 0);
105✔
771
  PG_RETURN_SPANSET_P(result);
105✔
772
}
773

774
PGDLLEXPORT Datum Numspanset_scale(PG_FUNCTION_ARGS);
775
PG_FUNCTION_INFO_V1(Numspanset_scale);
7✔
776
/**
777
 * @ingroup mobilitydb_setspan_transf
778
 * @brief Return a number span set scaled by a value
779
 * @note This function is also used for `datespanset`
780
 * @sqlfn scale()
781
 */
782
Datum
783
Numspanset_scale(PG_FUNCTION_ARGS)
297✔
784
{
785
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
297✔
786
  Datum width = PG_GETARG_DATUM(1);
297✔
787
  SpanSet *result = numspanset_shift_scale(ss, 0, width, false, true);
297✔
788
  PG_FREE_IF_COPY(ss, 0);
297✔
789
  PG_RETURN_SPANSET_P(result);
297✔
790
}
791

792
PGDLLEXPORT Datum Tstzspanset_scale(PG_FUNCTION_ARGS);
793
PG_FUNCTION_INFO_V1(Tstzspanset_scale);
3✔
794
/**
795
 * @ingroup mobilitydb_setspan_transf
796
 * @brief Return a timestamptz span set scaled by an interval
797
 * @sqlfn scale()
798
 */
799
Datum
800
Tstzspanset_scale(PG_FUNCTION_ARGS)
105✔
801
{
802
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
105✔
803
  Interval *duration = PG_GETARG_INTERVAL_P(1);
105✔
804
  SpanSet *result = tstzspanset_shift_scale(ss, NULL, duration);
105✔
805
  PG_FREE_IF_COPY(ss, 0);
105✔
806
  PG_RETURN_SPANSET_P(result);
105✔
807
}
808

809
PGDLLEXPORT Datum Numspanset_shift_scale(PG_FUNCTION_ARGS);
810
PG_FUNCTION_INFO_V1(Numspanset_shift_scale);
7✔
811
/**
812
 * @ingroup mobilitydb_setspan_transf
813
 * @brief Return a number span set shifted and scaled by two values
814
 * @note This function is also used for `datespanset`
815
 * @sqlfn shiftTscale()
816
 */
817
Datum
818
Numspanset_shift_scale(PG_FUNCTION_ARGS)
297✔
819
{
820
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
297✔
821
  Datum shift = PG_GETARG_DATUM(1);
297✔
822
  Datum width = PG_GETARG_DATUM(2);
297✔
823
  SpanSet *result = numspanset_shift_scale(ss, shift, width, true, true);
297✔
824
  PG_FREE_IF_COPY(ss, 0);
297✔
825
  PG_RETURN_SPANSET_P(result);
297✔
826
}
827

828
PGDLLEXPORT Datum Tstzspanset_shift_scale(PG_FUNCTION_ARGS);
829
PG_FUNCTION_INFO_V1(Tstzspanset_shift_scale);
3✔
830
/**
831
 * @ingroup mobilitydb_setspan_transf
832
 * @brief Return a timestamptz span set shifted and scaled by two intervals
833
 * @sqlfn shiftTscale()
834
 */
835
Datum
836
Tstzspanset_shift_scale(PG_FUNCTION_ARGS)
204✔
837
{
838
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
204✔
839
  Interval *shift = PG_GETARG_INTERVAL_P(1);
204✔
840
  Interval *duration = PG_GETARG_INTERVAL_P(2);
204✔
841
  SpanSet *result = tstzspanset_shift_scale(ss, shift, duration);
204✔
842
  PG_FREE_IF_COPY(ss, 0);
204✔
843
  PG_RETURN_SPANSET_P(result);
204✔
844
}
845

846
PGDLLEXPORT Datum Floatspanset_floor(PG_FUNCTION_ARGS);
847
PG_FUNCTION_INFO_V1(Floatspanset_floor);
2✔
848
/**
849
 * @ingroup mobilitydb_setspan_transf
850
 * @brief Return a float span set rounded down to the nearest integer
851
 * @sqlfn floor()
852
 */
853
Datum
854
Floatspanset_floor(PG_FUNCTION_ARGS)
1✔
855
{
856
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
1✔
857
  SpanSet *result = floatspanset_floor(ss);
1✔
858
  PG_FREE_IF_COPY(ss, 0);
1✔
859
  PG_RETURN_SPANSET_P(result);
1✔
860
}
861

862
PGDLLEXPORT Datum Floatspanset_ceil(PG_FUNCTION_ARGS);
863
PG_FUNCTION_INFO_V1(Floatspanset_ceil);
2✔
864
/**
865
 * @ingroup mobilitydb_setspan_transf
866
 * @brief Return a float span set rounded up to the nearest integer
867
 * @sqlfn ceil()
868
 */
869
Datum
870
Floatspanset_ceil(PG_FUNCTION_ARGS)
1✔
871
{
872
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
1✔
873
  SpanSet *result = floatspanset_ceil(ss);
1✔
874
  PG_FREE_IF_COPY(ss, 0);
1✔
875
  PG_RETURN_SPANSET_P(result);
1✔
876
}
877

878
PGDLLEXPORT Datum Floatspanset_round(PG_FUNCTION_ARGS);
879
PG_FUNCTION_INFO_V1(Floatspanset_round);
3✔
880
/**
881
 * @ingroup mobilitydb_setspan_transf
882
 * @brief Return a float span set with the precision of the values set to a
883
 * number of decimal places
884
 * @sqlfn round()
885
 */
886
Datum
887
Floatspanset_round(PG_FUNCTION_ARGS)
100✔
888
{
889
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
100✔
890
  int maxdd = PG_GETARG_INT32(1);
100✔
891
  SpanSet *result = floatspanset_rnd(ss, maxdd);
100✔
892
  PG_FREE_IF_COPY(ss, 0);
100✔
893
  PG_RETURN_SPANSET_P(result);
100✔
894
}
895

896
PGDLLEXPORT Datum Spanset_spans(PG_FUNCTION_ARGS);
897
PG_FUNCTION_INFO_V1(Spanset_spans);
12✔
898
/**
899
 * @ingroup mobilitydb_temporal_bbox_topo
900
 * @brief Return an array of spans from the spans of a spanset
901
 * @sqlfn spans()
902
 */
903
Datum
904
Spanset_spans(PG_FUNCTION_ARGS)
306✔
905
{
906
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
306✔
907
  Span *spans = spanset_spans(ss);
306✔
908
  int count = ss->count;
306✔
909
  PG_FREE_IF_COPY(ss, 0);
306✔
910
  if (! spans)
306✔
911
    PG_RETURN_NULL();
×
912
  ArrayType *result = spanarr_to_array(spans, count);
306✔
913
  pfree(spans);
306✔
914
  PG_RETURN_ARRAYTYPE_P(result);
306✔
915
}
916

917
PGDLLEXPORT Datum Spanset_split_n_spans(PG_FUNCTION_ARGS);
918
PG_FUNCTION_INFO_V1(Spanset_split_n_spans);
9✔
919
/**
920
 * @ingroup mobilitydb_temporal_bbox_topo
921
 * @brief Return an array of N spans from the spans of a spanset
922
 * @sqlfn splitNspans()
923
 */
924
Datum
925
Spanset_split_n_spans(PG_FUNCTION_ARGS)
25✔
926
{
927
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
25✔
928
  int span_count = PG_GETARG_INT32(1);
25✔
929
  int count;
930
  Span *spans = spanset_split_n_spans(ss, span_count, &count);
25✔
931
  PG_FREE_IF_COPY(ss, 0);
24✔
932
  if (! spans)
24✔
NEW
933
    PG_RETURN_NULL();
×
934
  ArrayType *result = spanarr_to_array(spans, count);
24✔
935
  pfree(spans);
24✔
936
  PG_RETURN_ARRAYTYPE_P(result);
24✔
937
}
938

939
PGDLLEXPORT Datum Spanset_split_each_n_spans(PG_FUNCTION_ARGS);
940
PG_FUNCTION_INFO_V1(Spanset_split_each_n_spans);
9✔
941
/**
942
 * @ingroup mobilitydb_temporal_bbox_topo
943
 * @brief Return an array of spans from a spanset obtained by merging a given
944
 * number of successive composing spans
945
 * @sqlfn splitEachNspans()
946
 */
947
Datum
948
Spanset_split_each_n_spans(PG_FUNCTION_ARGS)
25✔
949
{
950
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
25✔
951
  int span_count = PG_GETARG_INT32(1);
25✔
952
  int count;
953
  Span *spans = spanset_split_each_n_spans(ss, span_count, &count);
25✔
954
  PG_FREE_IF_COPY(ss, 0);
24✔
955
  if (! spans)
24✔
956
    PG_RETURN_NULL();
×
957
  ArrayType *result = spanarr_to_array(spans, count);
24✔
958
  pfree(spans);
24✔
959
  PG_RETURN_ARRAYTYPE_P(result);
24✔
960
}
961

962
/*****************************************************************************
963
 * Comparison functions for defining B-tree indexes
964
 *****************************************************************************/
965

966
PGDLLEXPORT Datum Spanset_cmp(PG_FUNCTION_ARGS);
967
PG_FUNCTION_INFO_V1(Spanset_cmp);
16✔
968
/**
969
 * @ingroup mobilitydb_setspan_comp
970
 * @brief Return -1, 0, or 1 depending on whether the first span set
971
 * is less than, equal to, or greater than the second one
972
 * @sqlfn spanset_cmp()
973
 */
974
Datum
975
Spanset_cmp(PG_FUNCTION_ARGS)
43,518✔
976
{
977
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
43,518✔
978
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
43,518✔
979
  int cmp = spanset_cmp_int(ss1, ss2);
43,518✔
980
  PG_FREE_IF_COPY(ss1, 0);
43,518✔
981
  PG_FREE_IF_COPY(ss2, 1);
43,518✔
982
  PG_RETURN_INT32(cmp);
43,518✔
983
}
984

985
PGDLLEXPORT Datum Spanset_eq(PG_FUNCTION_ARGS);
986
PG_FUNCTION_INFO_V1(Spanset_eq);
17✔
987
/**
988
 * @ingroup mobilitydb_setspan_comp
989
 * @brief Return true if the first span set is equal to the second one
990
 * @sqlfn spanset_eq()
991
 * @sqlop @p =
992
 */
993
Datum
994
Spanset_eq(PG_FUNCTION_ARGS)
59,606✔
995
{
996
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
59,606✔
997
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
59,606✔
998
  bool result = spanset_eq_int(ss1, ss2);
59,606✔
999
  PG_FREE_IF_COPY(ss1, 0);
59,606✔
1000
  PG_FREE_IF_COPY(ss2, 1);
59,606✔
1001
  PG_RETURN_BOOL(result);
59,606✔
1002
}
1003

1004
PGDLLEXPORT Datum Spanset_ne(PG_FUNCTION_ARGS);
1005
PG_FUNCTION_INFO_V1(Spanset_ne);
19✔
1006
/**
1007
 * @ingroup mobilitydb_setspan_comp
1008
 * @brief Return true if the first span set is different from the second one
1009
 * @sqlfn spanset_ne()
1010
 * @sqlop @p <>
1011
 */
1012
Datum
1013
Spanset_ne(PG_FUNCTION_ARGS)
41,485✔
1014
{
1015
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
41,485✔
1016
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
41,485✔
1017
  bool result = spanset_ne(ss1, ss2);
41,485✔
1018
  PG_FREE_IF_COPY(ss1, 0);
41,485✔
1019
  PG_FREE_IF_COPY(ss2, 1);
41,485✔
1020
  PG_RETURN_BOOL(result);
41,485✔
1021
}
1022

1023
/* Comparison operators using the internal B-tree comparator */
1024

1025
PGDLLEXPORT Datum Spanset_lt(PG_FUNCTION_ARGS);
1026
PG_FUNCTION_INFO_V1(Spanset_lt);
14✔
1027
/**
1028
 * @ingroup mobilitydb_setspan_comp
1029
 * @brief Return true if the first span set is less than the second one
1030
 * @sqlfn spanset_lt()
1031
 * @sqlop @p <
1032
 */
1033
Datum
1034
Spanset_lt(PG_FUNCTION_ARGS)
39,408✔
1035
{
1036
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
39,408✔
1037
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
39,408✔
1038
  bool result = spanset_lt(ss1, ss2);
39,408✔
1039
  PG_FREE_IF_COPY(ss1, 0);
39,408✔
1040
  PG_FREE_IF_COPY(ss2, 1);
39,408✔
1041
  PG_RETURN_BOOL(result);
39,408✔
1042
}
1043

1044
PGDLLEXPORT Datum Spanset_le(PG_FUNCTION_ARGS);
1045
PG_FUNCTION_INFO_V1(Spanset_le);
14✔
1046
/**
1047
 * @ingroup mobilitydb_setspan_comp
1048
 * @brief Return true if the first span set is less than or equal to
1049
 * the second one
1050
 * @sqlfn spanset_le()
1051
 * @sqlop @p <=
1052
 */
1053
Datum
1054
Spanset_le(PG_FUNCTION_ARGS)
39,406✔
1055
{
1056
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
39,406✔
1057
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
39,406✔
1058
  bool result = spanset_le(ss1, ss2);
39,406✔
1059
  PG_FREE_IF_COPY(ss1, 0);
39,406✔
1060
  PG_FREE_IF_COPY(ss2, 1);
39,406✔
1061
  PG_RETURN_BOOL(result);
39,406✔
1062
}
1063

1064
PGDLLEXPORT Datum Spanset_ge(PG_FUNCTION_ARGS);
1065
PG_FUNCTION_INFO_V1(Spanset_ge);
14✔
1066
/**
1067
 * @ingroup mobilitydb_setspan_comp
1068
 * @brief Return true if the first span set is greater than or equal to
1069
 * the second one
1070
 * @sqlfn spanset_ge()
1071
 * @sqlop @p >=
1072
 */
1073
Datum
1074
Spanset_ge(PG_FUNCTION_ARGS)
39,406✔
1075
{
1076
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
39,406✔
1077
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
39,406✔
1078
  bool result = spanset_ge(ss1, ss2);
39,406✔
1079
  PG_FREE_IF_COPY(ss1, 0);
39,406✔
1080
  PG_FREE_IF_COPY(ss2, 1);
39,406✔
1081
  PG_RETURN_BOOL(result);
39,406✔
1082
}
1083

1084
PGDLLEXPORT Datum Spanset_gt(PG_FUNCTION_ARGS);
1085
PG_FUNCTION_INFO_V1(Spanset_gt);
14✔
1086
/**
1087
 * @ingroup mobilitydb_setspan_comp
1088
 * @brief Return true if the first span set is greater than the second one
1089
 * @sqlfn spanset_gt()
1090
 * @sqlop @p >
1091
 */
1092
Datum
1093
Spanset_gt(PG_FUNCTION_ARGS)
39,406✔
1094
{
1095
  SpanSet *ss1 = PG_GETARG_SPANSET_P(0);
39,406✔
1096
  SpanSet *ss2 = PG_GETARG_SPANSET_P(1);
39,406✔
1097
  bool result = spanset_gt(ss1, ss2);
39,406✔
1098
  PG_FREE_IF_COPY(ss1, 0);
39,406✔
1099
  PG_FREE_IF_COPY(ss2, 1);
39,406✔
1100
  PG_RETURN_BOOL(result);
39,406✔
1101
}
1102

1103
/*****************************************************************************
1104
 * Functions for defining hash indexes
1105
 * The functions reuses the approach for array types for combining the hash of
1106
 * the elements.
1107
 *****************************************************************************/
1108

1109
PGDLLEXPORT Datum Spanset_hash(PG_FUNCTION_ARGS);
1110
PG_FUNCTION_INFO_V1(Spanset_hash);
10✔
1111
/**
1112
 * @ingroup mobilitydb_setspan_accessor
1113
 * @brief Return the 32-bit hash value of a span set
1114
 * @sqlfn spanset_hash()
1115
 */
1116
Datum
1117
Spanset_hash(PG_FUNCTION_ARGS)
115✔
1118
{
1119
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
115✔
1120
  uint32 result = spanset_hash(ss);
115✔
1121
  PG_FREE_IF_COPY(ss, 0);
115✔
1122
  PG_RETURN_UINT32(result);
115✔
1123
}
1124

1125
PGDLLEXPORT Datum Spanset_hash_extended(PG_FUNCTION_ARGS);
1126
PG_FUNCTION_INFO_V1(Spanset_hash_extended);
10✔
1127
/**
1128
 * @ingroup mobilitydb_setspan_accessor
1129
 * @brief Return the 64-bit hash value of a span set using a seed
1130
 * @sqlfn spanset_hash_extended()
1131
 */
1132
Datum
1133
Spanset_hash_extended(PG_FUNCTION_ARGS)
115✔
1134
{
1135
  SpanSet *ss = PG_GETARG_SPANSET_P(0);
115✔
1136
  uint64 seed = PG_GETARG_INT64(1);
115✔
1137
  uint64 result = spanset_hash_extended(ss, seed);
115✔
1138
  PG_FREE_IF_COPY(ss, 0);
115✔
1139
  PG_RETURN_UINT64(result);
115✔
1140
}
1141

1142
/*****************************************************************************/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc