MobilityDB  1.0
periodset.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * This MobilityDB code is provided under The PostgreSQL License.
4  *
5  * Copyright (c) 2016-2021, Université libre de Bruxelles and MobilityDB
6  * contributors
7  *
8  * MobilityDB includes portions of PostGIS version 3 source code released
9  * under the GNU General Public License (GPLv2 or later).
10  * Copyright (c) 2001-2021, PostGIS contributors
11  *
12  * Permission to use, copy, modify, and distribute this software and its
13  * documentation for any purpose, without fee, and without a written
14  * agreement is hereby granted, provided that the above copyright notice and
15  * this paragraph and the following two paragraphs appear in all copies.
16  *
17  * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
18  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
19  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
20  * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
21  * OF SUCH DAMAGE.
22  *
23  * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
26  * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
27  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
28  *
29  *****************************************************************************/
30 
36 #ifndef __PERIODSET_H__
37 #define __PERIODSET_H__
38 
39 #include <postgres.h>
40 #include <catalog/pg_type.h>
41 #include "timetypes.h"
42 
43 /*****************************************************************************/
44 
45 /* Assorted support functions */
46 
47 extern const Period *periodset_per_n(const PeriodSet *ps, int index);
48 extern const Period *periodset_bbox_ptr(const PeriodSet *ps);
49 extern void periodset_bbox(Period *p, const PeriodSet *ps);
50 extern PeriodSet *periodset_make(const Period **periods, int count,
51  bool normalize);
52 extern PeriodSet *periodset_make_free(Period **periods, int count,
53  bool normalize);
54 extern PeriodSet *periodset_copy(const PeriodSet *ps);
55 extern bool periodset_find_timestamp(const PeriodSet *ps, TimestampTz t,
56  int *loc);
57 
58 /* Input/output functions */
59 
60 extern Datum periodset_in(PG_FUNCTION_ARGS);
61 extern Datum periodset_out(PG_FUNCTION_ARGS);
62 extern Datum periodset_send(PG_FUNCTION_ARGS);
63 extern Datum periodset_recv(PG_FUNCTION_ARGS);
64 
65 extern char *periodset_to_string(const PeriodSet *ps);
66 
67 /* Constructor function */
68 
69 extern Datum periodset_constructor(PG_FUNCTION_ARGS);
70 
71 /* Cast functions */
72 
73 extern Datum timestamp_to_periodset(PG_FUNCTION_ARGS);
74 extern Datum timestampset_to_periodset(PG_FUNCTION_ARGS);
75 extern Datum period_to_periodset(PG_FUNCTION_ARGS);
76 extern Datum periodset_to_period(PG_FUNCTION_ARGS);
77 
78 extern PeriodSet *timestamp_to_periodset_internal(TimestampTz t);
81 
82 /* Accessor functions */
83 
84 extern Datum periodset_mem_size(PG_FUNCTION_ARGS);
85 extern Datum periodset_timespan(PG_FUNCTION_ARGS);
86 extern Datum periodset_duration(PG_FUNCTION_ARGS);
87 extern Datum periodset_num_periods(PG_FUNCTION_ARGS);
88 extern Datum periodset_start_period(PG_FUNCTION_ARGS);
89 extern Datum periodset_end_period(PG_FUNCTION_ARGS);
90 extern Datum periodset_period_n(PG_FUNCTION_ARGS);
91 extern Datum periodset_periods(PG_FUNCTION_ARGS);
92 extern Datum periodset_num_timestamps(PG_FUNCTION_ARGS);
93 extern Datum periodset_start_timestamp(PG_FUNCTION_ARGS);
94 extern Datum periodset_end_timestamp(PG_FUNCTION_ARGS);
95 extern Datum periodset_timestamp_n(PG_FUNCTION_ARGS);
96 extern Datum periodset_timestamps(PG_FUNCTION_ARGS);
97 extern Datum periodset_shift(PG_FUNCTION_ARGS);
98 
99 extern void periodset_to_period_internal(Period *p, const PeriodSet *ps);
100 extern const Period **periodset_periods_internal(const PeriodSet *ps);
101 extern TimestampTz periodset_start_timestamp_internal(const PeriodSet *ps);
102 extern TimestampTz periodset_end_timestamp_internal(const PeriodSet *ps);
103 extern PeriodSet *periodset_shift_internal(const PeriodSet *ps, const Interval *interval);
104 
105 /* Functions for defining B-tree index */
106 
107 extern Datum periodset_cmp(PG_FUNCTION_ARGS);
108 extern Datum periodset_eq(PG_FUNCTION_ARGS);
109 extern Datum periodset_ne(PG_FUNCTION_ARGS);
110 extern Datum periodset_lt(PG_FUNCTION_ARGS);
111 extern Datum periodset_le(PG_FUNCTION_ARGS);
112 extern Datum periodset_ge(PG_FUNCTION_ARGS);
113 extern Datum periodset_gt(PG_FUNCTION_ARGS);
114 
115 extern int periodset_cmp_internal(const PeriodSet *ps1, const PeriodSet *ps2);
116 extern bool periodset_eq_internal(const PeriodSet *ps1, const PeriodSet *ps2);
117 extern bool periodset_ne_internal(const PeriodSet *ps1, const PeriodSet *ps2);
118 
119 #endif
120 
121 /*****************************************************************************/
void periodset_to_period_internal(Period *p, const PeriodSet *ps)
Returns the bounding period on which the period set value is defined (internal function) ...
Definition: periodset.c:410
Datum periodset_recv(PG_FUNCTION_ARGS)
Receive function for period set values.
Definition: periodset.c:303
TimestampTz periodset_start_timestamp_internal(const PeriodSet *ps)
Returns the start timestamp of the period set value (internal function)
Definition: periodset.c:614
void periodset_bbox(Period *p, const PeriodSet *ps)
Copy in the first argument the bounding box of the timestamp set value.
Definition: periodset.c:75
Datum periodset_start_period(PG_FUNCTION_ARGS)
Returns the start period of the period set value.
Definition: periodset.c:507
Structure to represent periods.
Definition: timetypes.h:52
char * periodset_to_string(const PeriodSet *ps)
Returns the string representation of the period set value.
Definition: periodset.c:247
Datum periodset_gt(PG_FUNCTION_ARGS)
Returns true if the first period set value is greater than the second one.
Definition: periodset.c:938
PeriodSet * timestampset_to_periodset_internal(const TimestampSet *ts)
Cast the timestamp set value as a period set value (internal function)
Definition: periodset.c:369
Datum periodset_mem_size(PG_FUNCTION_ARGS)
Returns the size in bytes of the period set value.
Definition: periodset.c:441
const Period * periodset_per_n(const PeriodSet *ps, int index)
Returns the n-th period of the period set value.
Definition: periodset.c:57
void normalize(POINT3D *p)
Datum timestampset_to_periodset(PG_FUNCTION_ARGS)
Cast the timestamp set value as a period set value.
Definition: periodset.c:386
bool periodset_ne_internal(const PeriodSet *ps1, const PeriodSet *ps2)
Returns true if the first period set value is different from the second one (internal function) ...
Definition: periodset.c:864
Datum periodset_timestamp_n(PG_FUNCTION_ARGS)
Returns the n-th timestamp of the period set value.
Definition: periodset.c:663
bool periodset_eq_internal(const PeriodSet *ps1, const PeriodSet *ps2)
Returns true if the first period set value is equal to the second one (internal function) ...
Definition: periodset.c:828
Datum periodset_cmp(PG_FUNCTION_ARGS)
Returns -1, 0, or 1 depending on whether the first period set value is less than, equal...
Definition: periodset.c:811
int periodset_cmp_internal(const PeriodSet *ps1, const PeriodSet *ps2)
Returns -1, 0, or 1 depending on whether the first period set value is less than, equal...
Definition: periodset.c:778
Datum periodset_num_periods(PG_FUNCTION_ARGS)
Returns the number of periods of the period set value.
Definition: periodset.c:494
PeriodSet * periodset_shift_internal(const PeriodSet *ps, const Interval *interval)
Shift the period set value by the interval (internal function)
Definition: periodset.c:740
Datum periodset_period_n(PG_FUNCTION_ARGS)
Returns the n-th period of the period set value.
Definition: periodset.c:533
Datum periodset_ne(PG_FUNCTION_ARGS)
Returns true if the first period set value is different from the second one.
Definition: periodset.c:874
Datum periodset_out(PG_FUNCTION_ARGS)
Output function for period set values.
Definition: periodset.c:266
Datum periodset_in(PG_FUNCTION_ARGS)
Input function for period set values.
Definition: periodset.c:236
Structure to represent period sets.
Definition: timetypes.h:84
Datum periodset_end_period(PG_FUNCTION_ARGS)
Returns the end period of the period set value.
Definition: periodset.c:520
Datum periodset_timestamps(PG_FUNCTION_ARGS)
Returns the timestamps of the period set value.
Definition: periodset.c:713
Datum periodset_le(PG_FUNCTION_ARGS)
Returns true if the first period set value is less than or equal to the second one.
Definition: periodset.c:907
Datum periodset_to_period(PG_FUNCTION_ARGS)
Returns the bounding period on which the period set value is defined.
Definition: periodset.c:423
Datum period_to_periodset(PG_FUNCTION_ARGS)
Cast the period value as a period set value.
Definition: periodset.c:398
Datum periodset_end_timestamp(PG_FUNCTION_ARGS)
Returns the end timestamp of the period set value.
Definition: periodset.c:649
Functions for time types based on TimestampTz, that is, TimestampSet, Period, and PeriodSet...
Structure to represent timestamp sets.
Definition: timetypes.h:73
TimestampTz periodset_end_timestamp_internal(const PeriodSet *ps)
Returns the end timestamp of the period set value (internal function)
Definition: periodset.c:638
const Period ** periodset_periods_internal(const PeriodSet *ps)
Returns the periods of the period set value (internal function)
Definition: periodset.c:550
Datum periodset_start_timestamp(PG_FUNCTION_ARGS)
Returns the start timestamp of the period set value.
Definition: periodset.c:625
PeriodSet * timestamp_to_periodset_internal(TimestampTz t)
Cast the timestamp value as a period set value (internal function)
Definition: periodset.c:345
const Period * periodset_bbox_ptr(const PeriodSet *ps)
Returns a pointer to the precomputed bounding box of the period set value.
Definition: periodset.c:66
PeriodSet * periodset_make(const Period **periods, int count, bool normalize)
Construct a period set from an array of periods.
Definition: periodset.c:100
Datum periodset_eq(PG_FUNCTION_ARGS)
Returns true if the first period set value is equal to the second one.
Definition: periodset.c:849
Datum periodset_send(PG_FUNCTION_ARGS)
Send function for period set values.
Definition: periodset.c:279
Datum timestamp_to_periodset(PG_FUNCTION_ARGS)
Cast the timestamp value as a period set value.
Definition: periodset.c:358
PeriodSet * period_to_periodset_internal(const Period *p)
Construct a period set from a period (internal function)
Definition: periodset.c:161
Datum periodset_timespan(PG_FUNCTION_ARGS)
Returns the timespan of the period set value.
Definition: periodset.c:454
Datum periodset_ge(PG_FUNCTION_ARGS)
Returns true if the first period set value is greater than or equal to the second one...
Definition: periodset.c:923
Datum periodset_duration(PG_FUNCTION_ARGS)
Returns the timespan of the period set value.
Definition: periodset.c:470
bool periodset_find_timestamp(const PeriodSet *ps, TimestampTz t, int *loc)
Returns the location of the timestamp in the temporal sequence set value using binary search...
Definition: periodset.c:201
PeriodSet * periodset_copy(const PeriodSet *ps)
Returns a copy of the period set.
Definition: periodset.c:170
Datum periodset_periods(PG_FUNCTION_ARGS)
Returns the periods of the period set value.
Definition: periodset.c:563
Datum periodset_num_timestamps(PG_FUNCTION_ARGS)
Returns the number of timestamps of the period set value.
Definition: periodset.c:578
Datum periodset_lt(PG_FUNCTION_ARGS)
Returns true if the first period set value is less than the second one.
Definition: periodset.c:891
PeriodSet * periodset_make_free(Period **periods, int count, bool normalize)
Construct a period set from an array of periods and free the array and the periods after the creation...
Definition: periodset.c:144
Datum periodset_shift(PG_FUNCTION_ARGS)
Shift the period set value by the interval.
Definition: periodset.c:757
Datum periodset_constructor(PG_FUNCTION_ARGS)
Construct a period set from an array of period values.
Definition: periodset.c:323