MobilityDB  1.0
tinstantset.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 __TINSTANTSET_H__
37 #define __TINSTANTSET_H__
38 
39 #include <postgres.h>
40 #include <catalog/pg_type.h>
41 #include <utils/array.h>
42 #include <utils/rangetypes.h>
43 
44 #include "temporal.h"
45 
46 /*****************************************************************************/
47 
48 extern const TInstant *tinstantset_inst_n(const TInstantSet *ti, int index);
49 extern bool tinstantset_find_timestamp(const TInstantSet *ti, TimestampTz t, int *pos);
50 extern TInstantSet *tinstantset_make1(const TInstant **instants, int count);
51 extern TInstantSet *tinstantset_make(const TInstant **instants, int count, bool merge);
52 extern TInstantSet *tinstantset_make_free(TInstant **instants, int count, bool merge);
53 extern TInstantSet *tinstantset_copy(const TInstantSet *ti);
54 
55 /* Intersection functions */
56 
57 extern bool intersection_tinstantset_tinstant(const TInstantSet *ti, const TInstant *inst,
58  TInstant **inter1, TInstant **inter2);
59 extern bool intersection_tinstant_tinstantset(const TInstant *inst, const TInstantSet *ti,
60  TInstant **inter1, TInstant **inter2);
61 extern bool intersection_tinstantset_tinstantset(const TInstantSet *ti1, const TInstantSet *ti2,
62  TInstantSet **inter1, TInstantSet **inter2);
63 
64 /* Input/output functions */
65 
66 extern char *tinstantset_to_string(const TInstantSet *ti, char *(*value_out)(Oid, Datum));
67 extern void tinstantset_write(const TInstantSet *ti, StringInfo buf);
68 extern TInstantSet *tinstantset_read(StringInfo buf, Oid basetypid);
69 
70 /* Constructor functions */
71 
72 extern TInstantSet *tinstantset_from_base_internal(Datum value, Oid basetypid,
73  const TimestampSet *ts);
74 
75 extern Datum tinstantset_from_base(PG_FUNCTION_ARGS);
76 
77 /* Append and merge functions */
78 
79 extern TInstantSet *tinstantset_append_tinstant(const TInstantSet *ti, const TInstant *inst);
80 extern Temporal *tinstantset_merge(const TInstantSet *ti1, const TInstantSet *ti2);
81 extern Temporal *tinstantset_merge_array(const TInstantSet **tis, int count);
82 
83 /* Cast functions */
84 
87 
88 /* Transformation functions */
89 
90 extern TInstantSet *tinstant_to_tinstantset(const TInstant *inst);
93 
94 /* Accessor functions */
95 
96 extern int tinstantset_values(Datum *result, const TInstantSet *ti);
97 extern ArrayType *tinstantset_values_array(const TInstantSet *ti);
98 extern ArrayType *tfloatinstset_ranges(const TInstantSet *ti);
99 extern PeriodSet *tinstantset_get_time(const TInstantSet *ti);
100 extern void *tinstantset_bbox_ptr(const TInstantSet *ti);
101 extern void tinstantset_bbox(void *box, const TInstantSet *ti);
102 extern Datum tinstantset_min_value(const TInstantSet *ti);
103 extern Datum tinstantset_max_value(const TInstantSet *ti);
104 extern void tinstantset_period(Period *p, const TInstantSet *ti);
105 extern Datum tinstantset_timespan(const TInstantSet *ti);
106 extern ArrayType *tinstantset_sequences_array(const TInstantSet *ti);
107 extern const TInstant **tinstantset_instants(const TInstantSet *ti, int *count);
108 extern ArrayType *tinstantset_instants_array(const TInstantSet *ti);
109 extern TimestampTz tinstantset_start_timestamp(const TInstantSet *ti);
110 extern TimestampTz tinstantset_end_timestamp(const TInstantSet *ti);
111 extern TimestampTz *tinstantset_timestamps1(const TInstantSet *ti);
112 extern ArrayType *tinstantset_timestamps(const TInstantSet *ti);
114  const Interval *start, const Interval *duration);
115 
116 extern bool tinstantset_ever_eq(const TInstantSet *ti, Datum value);
117 extern bool tinstantset_ever_lt(const TInstantSet *ti, Datum value);
118 extern bool tinstantset_ever_le(const TInstantSet *ti, Datum value);
119 
120 extern bool tinstantset_always_eq(const TInstantSet *ti, Datum value);
121 extern bool tinstantset_always_lt(const TInstantSet *ti, Datum value);
122 extern bool tinstantset_always_le(const TInstantSet *ti, Datum value);
123 
124 /* Restriction Functions */
125 
127  Datum value, bool atfunc);
129  const Datum *values, int count, bool atfunc);
131  const RangeType *range, bool atfunc);
133  RangeType **normranges, int count, bool atfunc);
134 extern const TInstant *tinstantset_min_instant(const TInstantSet *ti);
136  bool min, bool atfunc);
137 extern bool tinstantset_value_at_timestamp(const TInstantSet *ti,
138  TimestampTz t, Datum *result);
140  TimestampTz t, bool atfunc);
142  const TimestampSet *ts, bool atfunc);
144  const Period *p, bool atfunc);
146  const PeriodSet *ps, bool atfunc);
147 
148 /* Intersection Functions */
149 
150 extern bool tinstantset_intersects_timestamp(const TInstantSet *ti,
151  const TimestampTz t);
153  const TimestampSet *ts);
154 extern bool tinstantset_intersects_period(const TInstantSet *ti,
155  const Period *p);
156 extern bool tinstantset_intersects_periodset(const TInstantSet *ti,
157  const PeriodSet *ps);
158 
159 /* Local aggregate functions */
160 
161 extern double tnumberinstset_twavg(const TInstantSet *ti);
162 
163 /* Comparison functions */
164 
165 extern int tinstantset_cmp(const TInstantSet *ti1, const TInstantSet *ti2);
166 extern bool tinstantset_eq(const TInstantSet *ti1, const TInstantSet *ti2);
167 
168 /* Function for defining hash index */
169 
170 extern uint32 tinstantset_hash(const TInstantSet *ti);
171 
172 /*****************************************************************************/
173 
174 #endif
Structure to represent periods.
Definition: timetypes.h:52
ArrayType * tinstantset_instants_array(const TInstantSet *ti)
Returns the instants of the temporal value as an PostgreSQL array.
Definition: tinstantset.c:820
char * tinstantset_to_string(const TInstantSet *ti, char *(*value_out)(Oid, Datum))
Returns the string representation of the temporal value.
Definition: tinstantset.c:470
TInstantSet * tinstantset_restrict_minmax(const TInstantSet *ti, bool min, bool atfunc)
Restricts the temporal value to (the complement of) the minimum/maximum base value.
Definition: tinstantset.c:1231
TInstantSet * tinstantset_from_base_internal(Datum value, Oid basetypid, const TimestampSet *ts)
Construct a temporal instant set value from a base value and a timestamp set.
Definition: tinstantset.c:218
bool tinstantset_intersects_timestampset(const TInstantSet *ti, const TimestampSet *ts)
Returns true if the temporal value intersects the timestamp set.
Definition: tinstantset.c:1474
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: temporal.h:241
Datum tinstantset_min_value(const TInstantSet *ti)
Returns the minimum base value of the temporal value.
Definition: tinstantset.c:686
bool tinstantset_find_timestamp(const TInstantSet *ti, TimestampTz t, int *pos)
Returns the location of the timestamp in the temporal instant set value using binary search...
Definition: tinstantset.c:344
TInstantSet * tinstantset_restrict_value(const TInstantSet *ti, Datum value, bool atfunc)
Restricts the temporal value to the (complement of the) base value.
Definition: tinstantset.c:1060
TInstantSet * tinstantset_make(const TInstant **instants, int count, bool merge)
Construct a temporal instant set value from the array of temporal instant values. ...
Definition: tinstantset.c:185
TInstantSet * tinstantset_make1(const TInstant **instants, int count)
Creating a temporal value from its arguments.
Definition: tinstantset.c:111
void * tinstantset_bbox_ptr(const TInstantSet *ti)
Returns a pointer to the precomputed bounding box of the temporal value.
Definition: tinstantset.c:77
bool tinstantset_value_at_timestamp(const TInstantSet *ti, TimestampTz t, Datum *result)
Returns the base value of the temporal value at the timestamp.
Definition: tinstantset.c:1245
bool tinstantset_ever_le(const TInstantSet *ti, Datum value)
Returns true if the temporal value is ever less than or equal to the base value.
Definition: tinstantset.c:987
TimestampTz tinstantset_start_timestamp(const TInstantSet *ti)
Returns the start timestamp of the temporal value.
Definition: tinstantset.c:834
ArrayType * tinstantset_sequences_array(const TInstantSet *ti)
Returns the sequences of the temporal value as a PostgreSQL array.
Definition: tinstantset.c:794
bool tinstantset_always_eq(const TInstantSet *ti, Datum value)
Returns true if the temporal value is always equal to the base value.
Definition: tinstantset.c:941
TInstantSet * tinstantset_shift_tscale(const TInstantSet *ti, const Interval *start, const Interval *duration)
Shift and/or scale the time span of the temporal value by the two intervals.
Definition: tinstantset.c:878
TimestampTz * tinstantset_timestamps1(const TInstantSet *ti)
Returns the distinct timestamps of the temporal value.
Definition: tinstantset.c:852
TInstantSet * tsequence_to_tinstantset(const TSequence *seq)
Transforms the temporal sequence value into a temporal instant value.
Definition: tinstantset.c:573
const TInstant ** tinstantset_instants(const TInstantSet *ti, int *count)
Returns the instants of the temporal value as a C array.
Definition: tinstantset.c:807
TInstantSet * tinstantset_copy(const TInstantSet *ti)
Returns a copy of the temporal value.
Definition: tinstantset.c:311
Basic functions for temporal types of any subtype.
bool intersection_tinstantset_tinstant(const TInstantSet *ti, const TInstant *inst, TInstant **inter1, TInstant **inter2)
Temporally intersect the two temporal values.
Definition: tinstantset.c:383
bool tinstantset_ever_eq(const TInstantSet *ti, Datum value)
Returns true if the temporal value is ever equal to the base value.
Definition: tinstantset.c:922
Temporal * tinstantset_restrict_timestamp(const TInstantSet *ti, TimestampTz t, bool atfunc)
Restricts the temporal value to (the complement of) the timestamp.
Definition: tinstantset.c:1264
TInstantSet * tinstant_to_tinstantset(const TInstant *inst)
Transform the temporal instant value into a temporal instant set value.
Definition: tinstant.c:376
const TInstant * tinstantset_inst_n(const TInstantSet *ti, int index)
Returns the n-th instant of the temporal value.
Definition: tinstantset.c:66
Structure to represent period sets.
Definition: timetypes.h:84
bool tinstantset_eq(const TInstantSet *ti1, const TInstantSet *ti2)
Returns true if the two temporal instant set values are equal.
Definition: tinstantset.c:1539
int tinstantset_cmp(const TInstantSet *ti1, const TInstantSet *ti2)
Returns -1, 0, or 1 depending on whether the first temporal value is less than, equal, or greater than the second one.
Definition: tinstantset.c:1572
bool tinstantset_intersects_periodset(const TInstantSet *ti, const PeriodSet *ps)
Returns true if the temporal value intersects the period set.
Definition: tinstantset.c:1501
void tinstantset_period(Period *p, const TInstantSet *ti)
Returns the bounding period on which the temporal value is defined.
Definition: tinstantset.c:754
bool intersection_tinstant_tinstantset(const TInstant *inst, const TInstantSet *ti, TInstant **inter1, TInstant **inter2)
Temporally intersect the two temporal values.
Definition: tinstantset.c:403
void tinstantset_write(const TInstantSet *ti, StringInfo buf)
Write the binary representation of the temporal value into the buffer.
Definition: tinstantset.c:492
Datum tinstantset_timespan(const TInstantSet *ti)
Returns the timespan of the timestamp set value.
Definition: tinstantset.c:765
bool intersection_tinstantset_tinstantset(const TInstantSet *ti1, const TInstantSet *ti2, TInstantSet **inter1, TInstantSet **inter2)
Temporally intersect the two temporal values.
Definition: tinstantset.c:417
int tinstantset_values(Datum *result, const TInstantSet *ti)
Returns the base values of the temporal value as a C array.
Definition: tinstantset.c:625
TInstantSet * tinstantset_make_free(TInstant **instants, int count, bool merge)
Construct a temporal instant set value from the array of temporal instant values and free the array a...
Definition: tinstantset.c:201
ArrayType * tfloatinstset_ranges(const TInstantSet *ti)
Returns the base values of the temporal float value as an array of ranges.
Definition: tinstantset.c:653
Structure to represent temporal values of sequence set subtype.
Definition: temporal.h:293
bool tinstantset_always_le(const TInstantSet *ti, Datum value)
Returns true if the temporal value is always less than or equal to the base value.
Definition: tinstantset.c:1026
TInstantSet * tsequenceset_to_tinstantset(const TSequenceSet *ts)
Transforms the temporal sequence set value into a temporal instant set value.
Definition: tinstantset.c:591
const TInstant * tinstantset_min_instant(const TInstantSet *ti)
Returns a pointer to the instant with minimum base value of the temporal value.
Definition: tinstantset.c:1210
Structure to represent timestamp sets.
Definition: timetypes.h:73
bool tinstantset_ever_lt(const TInstantSet *ti, Datum value)
Returns true if the temporal value is ever less than the base value.
Definition: tinstantset.c:967
PeriodSet * tinstantset_get_time(const TInstantSet *ti)
Returns the time on which the temporal value is defined as a period set.
Definition: tinstantset.c:670
bool tinstantset_intersects_period(const TInstantSet *ti, const Period *p)
Returns true if the temporal value intersects the period.
Definition: tinstantset.c:1486
bool tinstantset_intersects_timestamp(const TInstantSet *ti, const TimestampTz t)
Returns true if the temporal value intersects the timestamp.
Definition: tinstantset.c:1464
TInstantSet * tinstantset_read(StringInfo buf, Oid basetypid)
Returns a new temporal value from its binary representation read from the buffer. ...
Definition: tinstantset.c:514
Datum tinstantset_from_base(PG_FUNCTION_ARGS)
Definition: tinstantset.c:229
Structure to represent temporal values of instant set subtype.
Definition: temporal.h:266
Temporal * tinstantset_merge(const TInstantSet *ti1, const TInstantSet *ti2)
Merge the two temporal values.
Definition: tinstantset.c:267
bool tinstantset_always_lt(const TInstantSet *ti, Datum value)
Returns true if the temporal value is always less than the base value.
Definition: tinstantset.c:1006
double tnumberinstset_twavg(const TInstantSet *ti)
Returns the time-weighted average of the temporal number.
Definition: tinstantset.c:1517
void tinstantset_bbox(void *box, const TInstantSet *ti)
Copy in the first argument the bounding box of the temporal value.
Definition: tinstantset.c:87
ArrayType * tinstantset_timestamps(const TInstantSet *ti)
Returns the distinct timestamps of the temporal value as a C array.
Definition: tinstantset.c:864
Datum tinstantset_max_value(const TInstantSet *ti)
Returns the maximum base value of the temporal value.
Definition: tinstantset.c:720
ArrayType * tinstantset_values_array(const TInstantSet *ti)
Returns the base values of the temporal value as a PostgreSQL array.
Definition: tinstantset.c:640
TInstantSet * tinstantset_restrict_periodset(const TInstantSet *ti, const PeriodSet *ps, bool atfunc)
Restricts the temporal value to (the complement of) the period set.
Definition: tinstantset.c:1415
TInstantSet * tinstantset_restrict_period(const TInstantSet *ti, const Period *p, bool atfunc)
Restricts the temporal value to (the complement of) the period.
Definition: tinstantset.c:1382
TInstantSet * tinstantset_append_tinstant(const TInstantSet *ti, const TInstant *inst)
Append an instant to the temporal value.
Definition: tinstantset.c:244
TInstantSet * tinstantset_restrict_timestampset(const TInstantSet *ti, const TimestampSet *ts, bool atfunc)
Restricts the temporal value to the (complement of the) timestamp set.
Definition: tinstantset.c:1307
TimestampTz tinstantset_end_timestamp(const TInstantSet *ti)
Returns the end timestamp of the temporal value.
Definition: tinstantset.c:843
uint32 tinstantset_hash(const TInstantSet *ti)
Returns the hash value of the temporal value.
Definition: tinstantset.c:1607
TInstantSet * tnumberinstset_restrict_range(const TInstantSet *ti, const RangeType *range, bool atfunc)
Restricts the temporal number to the (complement of the) range of base values.
Definition: tinstantset.c:1139
TInstantSet * tinstantset_restrict_values(const TInstantSet *ti, const Datum *values, int count, bool atfunc)
Restricts the temporal value to the (complement of the) array of base values.
Definition: tinstantset.c:1100
Temporal * tinstantset_merge_array(const TInstantSet **tis, int count)
Merge the array of temporal instant values.
Definition: tinstantset.c:285
TInstantSet * tintinstset_to_tfloatinstset(const TInstantSet *ti)
Cast the temporal integer value as a temporal float value.
Definition: tinstantset.c:531
Structure to represent temporal values of sequence subtype.
Definition: temporal.h:279
TInstantSet * tnumberinstset_restrict_ranges(const TInstantSet *ti, RangeType **normranges, int count, bool atfunc)
Restricts the temporal value to the (complement of the) array of ranges of base values.
Definition: tinstantset.c:1173
TInstantSet * tfloatinstset_to_tintinstset(const TInstantSet *ti)
Cast the temporal float value as a temporal integer value.
Definition: tinstantset.c:549
Structure to represent temporal values of instant subtype.
Definition: temporal.h:253