MobilityDB  1.0
tsequenceset.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 __TSEQUENCESET_H__
37 #define __TSEQUENCESET_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 /* General functions */
49 
50 extern const TSequence *tsequenceset_seq_n(const TSequenceSet *ts, int index);
51 extern TSequenceSet *tsequenceset_make(const TSequence **sequences, int count,
52  bool normalize);
53 extern TSequenceSet * tsequenceset_make_free(TSequence **sequences, int count,
54  bool normalize);
56 extern bool tsequenceset_find_timestamp(const TSequenceSet *ts, TimestampTz t,
57  int *loc);
58 extern double tsequenceset_interval_double(const TSequenceSet *ts);
59 
60 /* Intersection/synchronize functions */
61 
63  const TInstant *inst, TInstant **inter1, TInstant **inter2);
64 extern bool intersection_tinstant_tsequenceset(const TInstant *inst,
65  const TSequenceSet *ts, TInstant **inter1, TInstant **inter2);
67  const TInstantSet *ti, TInstantSet **inter1, TInstantSet **inter2);
69  const TSequenceSet *ts, TInstantSet **inter1, TInstantSet **inter2);
71  const TSequence *seq, TIntersection mode,
72  TSequenceSet **inter1, TSequenceSet **inter2);
73 extern bool intersection_tsequence_tsequenceset(const TSequence *seq,
74  const TSequenceSet *ts, TIntersection mode,
75  TSequenceSet **inter1, TSequenceSet **inter2);
77  const TSequenceSet *ts2, TIntersection mode,
78  TSequenceSet **inter1, TSequenceSet **inter2);
79 
80 /* Input/output functions */
81 
82 extern char *tsequenceset_to_string(const TSequenceSet *ts,
83  char *(*value_out)(Oid, Datum));
84 extern void tsequenceset_write(const TSequenceSet *ts, StringInfo buf);
85 extern TSequenceSet *tsequenceset_read(StringInfo buf, Oid basetypid);
86 
87 /* Constructor functions */
88 
90  Oid basetypid, const PeriodSet *ps, bool linear);
91 
92 extern Datum tsequenceset_from_base(PG_FUNCTION_ARGS);
93 
94 /* Append and merge functions */
95 
97  const TInstant *inst);
99  const TSequenceSet *ts2);
101  int count);
102 
103 /* Cast functions */
104 
105 extern RangeType *tfloatseqset_to_range(const TSequenceSet *ts);
108 
109 /* Transformation functions */
110 
112  bool linear);
114  bool linear);
117 
118 /* Accessor functions */
119 
120 extern int tsequenceset_values(Datum *result, const TSequenceSet *ts);
121 extern ArrayType *tsequenceset_values_array(const TSequenceSet *ts);
122 extern ArrayType *tfloatseqset_ranges(const TSequenceSet *ts);
123 extern void *tsequenceset_bbox_ptr(const TSequenceSet *ts);
124 extern void tsequenceset_bbox(void *box, const TSequenceSet *ts);
125 extern const TInstant *tsequenceset_min_instant(const TSequenceSet *ts);
126 extern Datum tsequenceset_min_value(const TSequenceSet *ts);
127 extern Datum tsequenceset_max_value(const TSequenceSet *ts);
128 extern PeriodSet *tsequenceset_get_time(const TSequenceSet *ts);
129 extern Datum tsequenceset_timespan(const TSequenceSet *ts);
130 extern Datum tsequenceset_duration(const TSequenceSet *ts);
131 extern void tsequenceset_period(Period *p, const TSequenceSet *ts);
132 extern ArrayType *tsequenceset_segments_array(const TSequenceSet *ts);
133 extern const TSequence **tsequenceset_sequences(const TSequenceSet *ts);
134 extern ArrayType *tsequenceset_sequences_array(const TSequenceSet *ts);
135 extern int tsequenceset_num_instants(const TSequenceSet *ts);
136 extern const TInstant *tsequenceset_inst_n(const TSequenceSet *ts, int n);
137 extern const TInstant **tsequenceset_instants(const TSequenceSet *ts,
138  int *count);
139 extern ArrayType *tsequenceset_instants_array(const TSequenceSet *ts);
140 extern TimestampTz tsequenceset_start_timestamp(const TSequenceSet *ts);
141 extern TimestampTz tsequenceset_end_timestamp(const TSequenceSet *ts);
142 extern int tsequenceset_num_timestamps(const TSequenceSet *ts);
143 extern bool tsequenceset_timestamp_n(const TSequenceSet *ts, int n,
144  TimestampTz *result);
145 extern ArrayType *tsequenceset_timestamps(const TSequenceSet *ts);
147  const Interval *start, const Interval *duration);
148 
149 extern bool tsequenceset_ever_eq(const TSequenceSet *ts, Datum value);
150 extern bool tsequenceset_ever_lt(const TSequenceSet *ts, Datum value);
151 extern bool tsequenceset_ever_le(const TSequenceSet *ts, Datum value);
152 
153 extern bool tsequenceset_always_eq(const TSequenceSet *ts, Datum value);
154 extern bool tsequenceset_always_lt(const TSequenceSet *ts, Datum value);
155 extern bool tsequenceset_always_le(const TSequenceSet *ts, Datum value);
156 
157 /* Restriction Functions */
158 
160  Datum value, bool atfunc);
162  const Datum *values, int count, bool atfunc);
164  const RangeType *range, bool atfunc);
166  RangeType **normranges, int count, bool atfunc);
168  bool min, bool atfunc);
169 
170 extern bool tsequenceset_value_at_timestamp(const TSequenceSet *ts,
171  TimestampTz t, Datum *result);
173  TimestampTz t, Datum *result);
175  TimestampTz t);
176 
178  TimestampTz t, bool atfunc);
180  const TimestampSet *ts2, bool atfunc);
182  const Period *p, bool atfunc);
184  const PeriodSet *ps, bool atfunc);
185 
186 /* Intersection functions */
187 
188 extern bool tsequenceset_intersects_timestamp(const TSequenceSet *ts,
189  TimestampTz t);
191  const TimestampSet *ts1);
192 extern bool tsequenceset_intersects_period(const TSequenceSet *ts,
193  const Period *p);
194 extern bool tsequenceset_intersects_periodset(const TSequenceSet *ts,
195  const PeriodSet *ps);
196 
197 /* Local aggregate functions */
198 
199 extern double tnumberseqset_integral(const TSequenceSet *ts);
200 extern double tnumberseqset_twavg(const TSequenceSet *ts);
201 
202 /* Comparison functions */
203 
204 extern int tsequenceset_cmp(const TSequenceSet *ts1, const TSequenceSet *ts2);
205 extern bool tsequenceset_eq(const TSequenceSet *ts1, const TSequenceSet *ts2);
206 
207 /* Function for defining hash index */
208 
209 extern uint32 tsequenceset_hash(const TSequenceSet *ts);
210 
211 /*****************************************************************************/
212 
213 #endif
ArrayType * tsequenceset_instants_array(const TSequenceSet *ts)
Returns the distinct instants of the temporal value.
Definition: tsequenceset.c:1227
uint32 tsequenceset_hash(const TSequenceSet *ts)
Returns the hash value of the temporal value.
Definition: tsequenceset.c:2275
int tsequenceset_values(Datum *result, const TSequenceSet *ts)
Returns the distinct base values of the temporal value with stepwise interpolation.
Definition: tsequenceset.c:819
Structure to represent periods.
Definition: timetypes.h:52
char * tsequenceset_to_string(const TSequenceSet *ts, char *(*value_out)(Oid, Datum))
Returns the string representation of the temporal value.
Definition: tsequenceset.c:634
double tsequenceset_interval_double(const TSequenceSet *ts)
Returns the duration of the temporal value as a double.
Definition: tsequenceset.c:1063
TSequenceSet * tinstantset_to_tsequenceset(const TInstantSet *ti, bool linear)
Transform the temporal instant set value into a temporal sequence set value.
Definition: tsequenceset.c:770
bool intersection_tsequence_tsequenceset(const TSequence *seq, const TSequenceSet *ts, TIntersection mode, TSequenceSet **inter1, TSequenceSet **inter2)
Temporally intersect or synchronize the two temporal values.
Definition: tsequenceset.c:557
TIntersection
Enumeration for the intersection/synchronization functions.
Definition: temporal.h:119
bool synchronize_tsequenceset_tsequence(const TSequenceSet *ts, const TSequence *seq, TIntersection mode, TSequenceSet **inter1, TSequenceSet **inter2)
Temporally intersect or synchronize the two temporal values.
Definition: tsequenceset.c:504
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: temporal.h:241
Datum tsequenceset_max_value(const TSequenceSet *ts)
Returns the maximum base value of the temporal value.
Definition: tsequenceset.c:985
bool intersection_tsequenceset_tinstantset(const TSequenceSet *ts, const TInstantSet *ti, TInstantSet **inter1, TInstantSet **inter2)
Temporally intersect the two temporal values.
Definition: tsequenceset.c:434
const TSequence * tsequenceset_seq_n(const TSequenceSet *ts, int index)
Returns the n-th sequence of the temporal value.
Definition: tsequenceset.c:65
bool tsequenceset_always_eq(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is always equal to the base value.
Definition: tsequenceset.c:1441
void normalize(POINT3D *p)
TSequenceSet * tsequenceset_restrict_value(const TSequenceSet *ts, Datum value, bool atfunc)
Restricts the temporal value to the base value.
Definition: tsequenceset.c:1554
TSequenceSet * tsequenceset_restrict_values(const TSequenceSet *ts, const Datum *values, int count, bool atfunc)
Restricts the temporal value to the (complement of the) array of base values.
Definition: tsequenceset.c:1586
const TInstant * tsequenceset_inst_n(const TSequenceSet *ts, int n)
Returns the n-th distinct instant of the temporal value.
Definition: tsequenceset.c:1169
TSequenceSet * tsequenceset_from_base_internal(Datum value, Oid basetypid, const PeriodSet *ps, bool linear)
Construct a temporal sequence set value from from a base value and a timestamp set (internal function...
Definition: tsequenceset.c:227
Datum tsequenceset_duration(const TSequenceSet *ts)
Returns the duration of the temporal value.
Definition: tsequenceset.c:1042
Temporal * tsequenceset_restrict_timestamp(const TSequenceSet *ts, TimestampTz t, bool atfunc)
Restricts the temporal value to the (the complement of) timestamp.
Definition: tsequenceset.c:1708
Datum tsequenceset_min_value(const TSequenceSet *ts)
Returns the minimum base value of the temporal value.
Definition: tsequenceset.c:958
double tnumberseqset_twavg(const TSequenceSet *ts)
Returns the time-weighted average of the temporal number.
Definition: tsequenceset.c:2181
Datum tsequenceset_timespan(const TSequenceSet *ts)
Returns the timespan of the temporal value.
Definition: tsequenceset.c:1029
bool tsequenceset_intersects_timestampset(const TSequenceSet *ts, const TimestampSet *ts1)
Returns true if the temporal value intersect the timestamp set.
Definition: tsequenceset.c:2118
TSequenceSet * tsequenceset_merge(const TSequenceSet *ts1, const TSequenceSet *ts2)
Merge the two temporal values.
Definition: tsequenceset.c:289
ArrayType * tsequenceset_timestamps(const TSequenceSet *ts)
Returns the distinct timestamps of the temporal value as a PostgreSQL array.
Definition: tsequenceset.c:1356
TimestampTz tsequenceset_end_timestamp(const TSequenceSet *ts)
Returns the end timestamp of the temporal value.
Definition: tsequenceset.c:1251
PeriodSet * tsequenceset_get_time(const TSequenceSet *ts)
Returns the time on which the temporal value is defined as a period set.
Definition: tsequenceset.c:1012
TSequenceSet * tstepseqset_to_linear(const TSequenceSet *ts)
Transform the temporal value with continuous base type from stepwise to linear interpolation.
Definition: tsequenceset.c:789
TSequenceSet * tnumberseqset_restrict_range(const TSequenceSet *ts, const RangeType *range, bool atfunc)
Restricts the temporal number to the range of base values.
Definition: tsequenceset.c:1633
bool intersection_tsequenceset_tinstant(const TSequenceSet *ts, const TInstant *inst, TInstant **inter1, TInstant **inter2)
Temporally intersect the two temporal values.
Definition: tsequenceset.c:400
bool tsequenceset_ever_eq(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is ever equal to the base value.
Definition: tsequenceset.c:1425
Basic functions for temporal types of any subtype.
bool tsequenceset_always_le(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is always less than or equal to the base value.
Definition: tsequenceset.c:1523
Datum tsequenceset_from_base(PG_FUNCTION_ARGS)
Construct a temporal sequence set value from from a base value and a timestamp set.
Definition: tsequenceset.c:245
const TInstant ** tsequenceset_instants(const TSequenceSet *ts, int *count)
Returns the distinct instants of the temporal value.
Definition: tsequenceset.c:1209
bool intersection_tinstantset_tsequenceset(const TInstantSet *ti, const TSequenceSet *ts, TInstantSet **inter1, TInstantSet **inter2)
Temporally intersect the two temporal values.
Definition: tsequenceset.c:486
void * tsequenceset_bbox_ptr(const TSequenceSet *ts)
Returns a pointer to the precomputed bounding box of the temporal value.
Definition: tsequenceset.c:76
TSequenceSet * tnumberseqset_restrict_ranges(const TSequenceSet *ts, RangeType **normranges, int count, bool atfunc)
Restricts the temporal number to the (complement of the) array of ranges of base values.
Definition: tsequenceset.c:1669
Structure to represent period sets.
Definition: timetypes.h:84
TSequenceSet * tsequenceset_restrict_period(const TSequenceSet *ts, const Period *p, bool atfunc)
Restricts the temporal value to the (complement of the) period.
Definition: tsequenceset.c:1932
const TInstant * tsequenceset_inst_at_timestamp_excl(const TSequenceSet *ts, TimestampTz t)
Returns the temporal instant at the timestamp when the timestamp is at an exclusive bound...
Definition: tsequenceset.c:1822
bool tsequenceset_intersects_period(const TSequenceSet *ts, const Period *p)
Returns true if the temporal value intersect the period.
Definition: tsequenceset.c:2130
const TInstant * tsequenceset_min_instant(const TSequenceSet *ts)
Returns a pointer to the instant with minimum base value of the temporal value.
Definition: tsequenceset.c:932
void tsequenceset_period(Period *p, const TSequenceSet *ts)
Returns the bounding period on which the temporal value is defined.
Definition: tsequenceset.c:1078
double tnumberseqset_integral(const TSequenceSet *ts)
Returns the integral (area under the curve) of the temporal number.
Definition: tsequenceset.c:2169
ArrayType * tsequenceset_values_array(const TSequenceSet *ts)
Returns the distinct base values of the temporal value with stepwise interpolation as a PostgreSQL ar...
Definition: tsequenceset.c:841
TSequenceSet * tintseqset_to_tfloatseqset(const TSequenceSet *ts)
Cast the temporal integer value as a temporal float value.
Definition: tsequenceset.c:701
Temporal * tsequenceset_restrict_timestampset(const TSequenceSet *ts1, const TimestampSet *ts2, bool atfunc)
Restricts the temporal value to the (complement of the) timestamp set.
Definition: tsequenceset.c:1855
TSequenceSet * tsequenceset_make(const TSequence **sequences, int count, bool normalize)
Construct a temporal sequence set value from the array of temporal sequence values.
Definition: tsequenceset.c:119
Structure to represent temporal values of sequence set subtype.
Definition: temporal.h:293
RangeType * tfloatseqset_to_range(const TSequenceSet *ts)
Cast a temporal float value as a floatrange.
Definition: tsequenceset.c:854
Structure to represent timestamp sets.
Definition: timetypes.h:73
void tsequenceset_bbox(void *box, const TSequenceSet *ts)
Copy in the first argument the bounding box of the temporal value.
Definition: tsequenceset.c:86
bool tsequenceset_always_lt(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is always less than the base value.
Definition: tsequenceset.c:1503
bool synchronize_tsequenceset_tsequenceset(const TSequenceSet *ts1, const TSequenceSet *ts2, TIntersection mode, TSequenceSet **inter1, TSequenceSet **inter2)
Temporally intersect or synchronize the two temporal values.
Definition: tsequenceset.c:572
int tsequenceset_cmp(const TSequenceSet *ts1, const TSequenceSet *ts2)
Returns -1, 0, or 1 depending on whether the first temporal value is less than, equal, or greater than the second one.
Definition: tsequenceset.c:2241
bool tsequenceset_timestamp_n(const TSequenceSet *ts, int n, TimestampTz *result)
Returns the n-th distinct timestamp of the temporal value.
Definition: tsequenceset.c:1285
TSequenceSet * tsequenceset_restrict_periodset(const TSequenceSet *ts, const PeriodSet *ps, bool atfunc)
Restricts the temporal value to the (complement of the) period set.
Definition: tsequenceset.c:2014
Structure to represent temporal values of instant set subtype.
Definition: temporal.h:266
bool tsequenceset_ever_lt(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is ever less than the base value.
Definition: tsequenceset.c:1464
TSequenceSet * tsequenceset_append_tinstant(const TSequenceSet *ts, const TInstant *inst)
Append an instant to the temporal value.
Definition: tsequenceset.c:265
int tsequenceset_num_instants(const TSequenceSet *ts)
Returns the number of distinct instants of the temporal value.
Definition: tsequenceset.c:1145
TSequenceSet * tsequenceset_shift_tscale(const TSequenceSet *ts, const Interval *start, const Interval *duration)
Shift and/or scale the time span of the temporal value by the two intervals.
Definition: tsequenceset.c:1371
TSequenceSet * tsequenceset_merge_array(const TSequenceSet **ts, int count)
Merge the array of temporal sequence set values.
Definition: tsequenceset.c:304
bool tsequenceset_value_at_timestamp(const TSequenceSet *ts, TimestampTz t, Datum *result)
Returns the base value of the temporal value at the timestamp.
Definition: tsequenceset.c:1768
const TSequence ** tsequenceset_sequences(const TSequenceSet *ts)
Returns the sequences of the temporal value as a C array.
Definition: tsequenceset.c:1090
bool tsequenceset_intersects_periodset(const TSequenceSet *ts, const PeriodSet *ps)
Returns true if the temporal value intersect the period set.
Definition: tsequenceset.c:2153
bool tsequenceset_eq(const TSequenceSet *ts1, const TSequenceSet *ts2)
Returns true if the two temporal sequence set values are equal.
Definition: tsequenceset.c:2208
bool tsequenceset_value_at_timestamp_inc(const TSequenceSet *ts, TimestampTz t, Datum *result)
Returns the base value of the temporal value at the timestamp when the timestamp may be at an exclusi...
Definition: tsequenceset.c:1791
TSequenceSet * tsequence_to_tsequenceset(const TSequence *seq)
Construct a temporal sequence set value from the temporal sequence.
Definition: tsequenceset.c:212
bool tsequenceset_find_timestamp(const TSequenceSet *ts, TimestampTz t, int *loc)
Returns the location of the timestamp in the temporal sequence set value using binary search...
Definition: tsequenceset.c:363
ArrayType * tfloatseqset_ranges(const TSequenceSet *ts)
Returns the ranges of base values of the temporal float value as a PostgreSQL array.
Definition: tsequenceset.c:900
TSequenceSet * tsequenceset_restrict_minmax(const TSequenceSet *ts, bool min, bool atfunc)
Restricts the temporal value to (the complement of) the minimum/maximum base value.
Definition: tsequenceset.c:1698
TSequenceSet * tinstant_to_tsequenceset(const TInstant *inst, bool linear)
Transform the temporal instant value into a temporal sequence set value.
Definition: tsequenceset.c:758
TSequenceSet * tsequenceset_copy(const TSequenceSet *ts)
Returns a copy of the temporal value.
Definition: tsequenceset.c:329
bool tsequenceset_ever_le(const TSequenceSet *ts, Datum value)
Returns true if the temporal value is ever less than or equal to the base value.
Definition: tsequenceset.c:1484
ArrayType * tsequenceset_segments_array(const TSequenceSet *ts)
Returns the segments of the temporal value as a PostgreSQL array.
Definition: tsequenceset.c:1129
void tsequenceset_write(const TSequenceSet *ts, StringInfo buf)
Write the binary representation of the temporal value into the buffer.
Definition: tsequenceset.c:661
bool tsequenceset_intersects_timestamp(const TSequenceSet *ts, TimestampTz t)
Returns true if the temporal value intersect the timestamp.
Definition: tsequenceset.c:2106
TSequenceSet * tfloatseqset_to_tintseqset(const TSequenceSet *ts)
Cast the temporal float value as a temporal integer value.
Definition: tsequenceset.c:726
Structure to represent temporal values of sequence subtype.
Definition: temporal.h:279
TSequenceSet * tsequenceset_make_free(TSequence **sequences, int count, bool normalize)
Construct a temporal sequence set value from the array of temporal sequence values and free the array...
Definition: tsequenceset.c:195
bool intersection_tinstant_tsequenceset(const TInstant *inst, const TSequenceSet *ts, TInstant **inter1, TInstant **inter2)
Temporally intersect the two temporal values.
Definition: tsequenceset.c:420
int tsequenceset_num_timestamps(const TSequenceSet *ts)
Returns the number of distinct timestamps of the temporal value.
Definition: tsequenceset.c:1261
TimestampTz tsequenceset_start_timestamp(const TSequenceSet *ts)
Returns the start timestamp of the temporal value.
Definition: tsequenceset.c:1241
TSequenceSet * tsequenceset_read(StringInfo buf, Oid basetypid)
Returns a new temporal value from its binary representation read from the buffer. ...
Definition: tsequenceset.c:683
ArrayType * tsequenceset_sequences_array(const TSequenceSet *ts)
Returns the sequences of the temporal value as a PostgreSQL array.
Definition: tsequenceset.c:1102
Structure to represent temporal values of instant subtype.
Definition: temporal.h:253