MobilityDB 1.3
Loading...
Searching...
No Matches
tsequence.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * This MobilityDB code is provided under The PostgreSQL License.
4 * Copyright (c) 2016-2025, 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-2025, 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
34#ifndef __TSEQUENCE_H__
35#define __TSEQUENCE_H__
36
37/* PostgreSQL */
38#include <postgres.h>
39/* MEOS */
40#include <meos.h>
41#include "temporal/meos_catalog.h"
42#include "temporal/temporal.h"
43
44/*****************************************************************************/
45
46/* Collinear function */
47
48extern bool float_collinear(double x1, double x2, double x3, double ratio);
49
50/* Interpolation functions */
51
52extern double floatsegm_interpolate(double value1, double value2,
53 long double value);
54extern long double floatsegm_locate(double value1, double value2,
55 double value);
56
57extern int tnumbersegm_intersection(Datum start1, Datum end1, Datum start2,
58 Datum end2, meosType basetype, TimestampTz lower, TimestampTz upper,
59 TimestampTz *t);
60
61/* Normalization functions */
62
63extern bool tsequence_norm_test(Datum value1, Datum value2, Datum value3,
64 meosType basetype, interpType interp, TimestampTz t1, TimestampTz t2,
65 TimestampTz t3);
66extern bool tsequence_join_test(const TSequence *seq1, const TSequence *seq2,
67 bool *removelast, bool *removefirst);
68extern TSequence *tsequence_join(const TSequence *seq1, const TSequence *seq2,
69 bool removelast, bool removefirst);
70extern TInstant **tinstarr_normalize(const TInstant **instants,
71 interpType interp, int count, int *newcount);
72
73/* General functions */
74
75extern int tcontseq_find_timestamptz(const TSequence *seq, TimestampTz t);
76extern int tdiscseq_find_timestamptz(const TSequence *seq, TimestampTz t);
77extern TSequence **tseqarr2_to_tseqarr(TSequence ***sequences, int *countseqs,
78 int count, int totalseqs);
79
80extern bool ensure_valid_tinstarr_common(const TInstant **instants, int count,
81 bool lower_inc, bool upper_inc, interpType interp);
82extern TSequence *tsequence_make_exp1(const TInstant **instants, int count,
83 int maxcount, bool lower_inc, bool upper_inc, interpType interp,
84 bool normalize, void *bbox);
85
86/* Synchronization functions */
87
88extern bool synchronize_tsequence_tsequence(const TSequence *seq1,
89 const TSequence *seq2, TSequence **sync1, TSequence **sync2,
90 bool interpoint);
91
92/* Intersection functions */
93
94extern int tfloatsegm_intersection_value(Datum start, Datum end, Datum value,
95 TimestampTz lower, TimestampTz upper, TimestampTz *t);
96extern int tsegment_intersection_value(Datum start, Datum end, Datum value,
97 meosType temptype, TimestampTz lower, TimestampTz upper, TimestampTz *t1,
98 TimestampTz *t2);
99extern int tsegment_intersection(Datum start1, Datum end1, Datum start2,
100 Datum end2, meosType temptype, TimestampTz lower, TimestampTz upper,
101 TimestampTz *t1, TimestampTz *t2);
103 meosType temptype, TimestampTz lower, TimestampTz upper, TimestampTz t);
104
105extern bool intersection_tdiscseq_tdiscseq(const TSequence *seq1,
106 const TSequence *seq2, TSequence **inter1, TSequence **inter2);
107extern bool intersection_tcontseq_tdiscseq(const TSequence *seq1,
108 const TSequence *seq2, TSequence **inter1, TSequence **inter2);
109extern bool intersection_tdiscseq_tcontseq(const TSequence *is,
110 const TSequence *seq2, TSequence **inter1, TSequence **inter2);
111
112extern bool intersection_tsequence_tinstant(const TSequence *seq,
113 const TInstant *inst, TInstant **inter1, TInstant **inter2);
114extern bool intersection_tinstant_tsequence(const TInstant *inst,
115 const TSequence *seq, TInstant **inter1, TInstant **inter2);
116
117/* Input/output functions */
118
119extern char *tsequence_to_string(const TSequence *seq, int maxdd,
120 bool component, outfunc value_out);
121
122/* Constructor functions */
123
124extern bool ensure_increasing_timestamps(const TInstant *inst1,
125 const TInstant *inst2, bool strict);
126extern void bbox_expand(const void *box1, void *box2, meosType temptype);
127extern bool ensure_valid_tinstarr(const TInstant **instants, int count,
128 bool merge, interpType interp);
129extern bool tsequence_make_valid(const TInstant **instants, int count,
130 bool lower_inc, bool upper_inc, interpType interp);
131
132/* Transformation functions */
133
134extern void tnumberseq_shift_scale_value_iter(TSequence *seq, Datum origin,
135 Datum delta, bool hasdelta, double scale);
137 double scale);
138extern int tstepseq_to_linear_iter(const TSequence *seq, TSequence **result);
139extern TSequenceSet *tstepseq_to_linear(const TSequence *seq);
140
141/* Accessor functions */
142
143extern int tsequence_segments_iter(const TSequence *seq, TSequence **result);
144extern int tsequence_timestamps_iter(const TSequence *seq, TimestampTz *result);
145
146/* Local Aggregate Functions */
147
148extern double tnumberseq_cont_twavg(const TSequence *seq);
149
150/*****************************************************************************/
151
152#endif
meosType
Enumeration that defines the built-in and temporal types used in MobilityDB.
Definition: meos_catalog.h:55
char *(* outfunc)(Datum value, meosType type, int maxdd)
Definition: temporal.h:277
int tnumbersegm_intersection(Datum start1, Datum end1, Datum start2, Datum end2, meosType basetype, TimestampTz lower, TimestampTz upper, TimestampTz *t)
Compute the intersection, if any, of two segments of temporal sequences.
Definition: tsequence.c:2671
TSequence ** tseqarr2_to_tseqarr(TSequence ***sequences, int *countseqs, int count, int totalseqs)
Return an array of temporal sequences converted from an array of arrays of temporal sequences.
Definition: tsequence.c:735
int tsequence_segments_iter(const TSequence *seq, TSequence **result)
Return the array of segments of a temporal sequence (iterator function)
Definition: tsequence.c:2048
bool tsequence_join_test(const TSequence *seq1, const TSequence *seq2, bool *removelast, bool *removefirst)
Test whether two sequences can be joined during normalization.
Definition: tsequence.c:505
int tsegment_intersection_value(Datum start, Datum end, Datum value, meosType temptype, TimestampTz lower, TimestampTz upper, TimestampTz *t1, TimestampTz *t2)
Return true if a segment of a temporal sequence intersects a base value at a timestamptz.
Definition: tsequence.c:2614
char * tsequence_to_string(const TSequence *seq, int maxdd, bool component, outfunc value_out)
Return the Well-Known Text (WKT) representation of a temporal sequence.
Definition: tsequence.c:791
void bbox_expand(const void *box1, void *box2, meosType temptype)
Expand the second bounding box with the first one.
Definition: tsequence.c:1024
void tnumberseq_shift_scale_value_iter(TSequence *seq, Datum origin, Datum delta, bool hasdelta, double scale)
Shift and/or scale the values of the instants of a temporal sequence (iterator function)
Definition: tsequence.c:1659
bool intersection_tinstant_tsequence(const TInstant *inst, const TSequence *seq, TInstant **inter1, TInstant **inter2)
Temporally intersect two temporal values.
Definition: tsequence.c:2818
bool intersection_tdiscseq_tcontseq(const TSequence *is, const TSequence *seq2, TSequence **inter1, TSequence **inter2)
Temporally intersect two temporal values.
Definition: tsequence.c:2553
bool ensure_valid_tinstarr(const TInstant **instants, int count, bool merge, interpType interp)
Ensure that all temporal instants of the array are valid.
Definition: tsequence.c:1083
int tstepseq_to_linear_iter(const TSequence *seq, TSequence **result)
Return a temporal sequence with continuous base type transformed from step to linear interpolation (i...
Definition: tsequence.c:1558
TSequence * tsequence_make_exp1(const TInstant **instants, int count, int maxcount, bool lower_inc, bool upper_inc, interpType interp, bool normalize, void *bbox)
Return a temporal sequence from an array of temporal instants.
Definition: tsequence.c:913
bool float_collinear(double x1, double x2, double x3, double ratio)
Basic functions for temporal sequences.
Definition: tsequence.c:95
TInstant ** tinstarr_normalize(const TInstant **instants, interpType interp, int count, int *newcount)
Normalize the array of temporal instants.
Definition: tsequence.c:458
double tnumberseq_cont_twavg(const TSequence *seq)
Return the time-weighted average of a temporal sequence number.
Definition: tsequence.c:2888
bool synchronize_tsequence_tsequence(const TSequence *seq1, const TSequence *seq2, TSequence **sync1, TSequence **sync2, bool interpoint)
Synchronize two temporal sequences.
Definition: tsequence.c:2314
TSequenceSet * tstepseq_to_linear(const TSequence *seq)
Return a temporal sequence with continuous base type transformed from step to linear interpolation.
Definition: tsequence.c:1606
bool tsequence_make_valid(const TInstant **instants, int count, bool lower_inc, bool upper_inc, interpType interp)
Ensure the validity of the arguments when creating a temporal sequence.
Definition: tsequence.c:1124
Datum tsegment_value_at_timestamptz(Datum start, Datum end, meosType temptype, TimestampTz lower, TimestampTz upper, TimestampTz t)
Return the base value of the segment of a temporal sequence at a timestamptz.
Definition: tsequence.c:2212
bool intersection_tdiscseq_tdiscseq(const TSequence *seq1, const TSequence *seq2, TSequence **inter1, TSequence **inter2)
Temporally intersect two temporal discrete sequences.
Definition: tsequence.c:2459
double floatsegm_interpolate(double value1, double value2, long double value)
Return a float interpolated from a float segment with respect to a fraction of its total length.
Definition: tsequence.c:294
int tfloatsegm_intersection_value(Datum start, Datum end, Datum value, TimestampTz lower, TimestampTz upper, TimestampTz *t)
Return true if the segment of a temporal number intersects the base value at a timestamptz.
Definition: tsequence.c:2580
long double floatsegm_locate(double value1, double value2, double value)
Return a float in (0,1) if a float segment intersects a float with respect to an epsilon value,...
Definition: tsequence.c:227
int tcontseq_find_timestamptz(const TSequence *seq, TimestampTz t)
Return the index of the segment of a temporal continuous sequence containing a timestamp using binary...
Definition: tsequence.c:654
int tsequence_timestamps_iter(const TSequence *seq, TimestampTz *result)
Return the array of timestamptz values of a temporal sequence (iterator function)
Definition: tsequence.c:2175
TSequence * tsequence_join(const TSequence *seq1, const TSequence *seq2, bool removelast, bool removefirst)
Join two temporal sequences.
Definition: tsequence.c:601
bool intersection_tsequence_tinstant(const TSequence *seq, const TInstant *inst, TInstant **inter1, TInstant **inter2)
Temporally intersect two temporal sequences.
Definition: tsequence.c:2797
void tsequence_shift_scale_time_iter(TSequence *seq, TimestampTz delta, double scale)
Shift and/or scale the timestamps of the instants of a temporal sequence (iterator function)
Definition: tsequence.c:1692
bool ensure_increasing_timestamps(const TInstant *inst1, const TInstant *inst2, bool strict)
Ensure that the timestamp of the first temporal instant is smaller (or equal if the merge parameter i...
Definition: tsequence.c:996
int tdiscseq_find_timestamptz(const TSequence *seq, TimestampTz t)
Return the index of a timestamp in a temporal discrete sequence value using binary search.
Definition: tsequence.c:702
bool intersection_tcontseq_tdiscseq(const TSequence *seq1, const TSequence *seq2, TSequence **inter1, TSequence **inter2)
Temporally intersect two temporal sequences.
Definition: tsequence.c:2509
bool ensure_valid_tinstarr_common(const TInstant **instants, int count, bool lower_inc, bool upper_inc, interpType interp)
Ensure the validity of the arguments when creating a temporal sequence.
Definition: tsequence.c:1044
bool tsequence_norm_test(Datum value1, Datum value2, Datum value3, meosType basetype, interpType interp, TimestampTz t1, TimestampTz t2, TimestampTz t3)
Test whether we can remove the middle instant among 3 consecutive ones during normalization.
Definition: tsequence.c:419
int tsegment_intersection(Datum start1, Datum end1, Datum start2, Datum end2, meosType temptype, TimestampTz lower, TimestampTz upper, TimestampTz *t1, TimestampTz *t2)
Return true if two segments of a temporal sequence intersect at a timestamptz.
Definition: tsequence.c:2737
interpType
Enumeration that defines the interpolation types used in MEOS.
Definition: meos.h:161
External API of the Mobility Engine Open Source (MEOS) library.
int64 TimestampTz
Definition: postgres_ext_defs.in.h:22
uintptr_t Datum
Definition: postgres_ext_defs.in.h:7
Structure to represent temporal values of instant subtype.
Definition: meos.h:185
Structure to represent temporal values of sequence set subtype.
Definition: meos.h:224
Structure to represent temporal values of sequence subtype.
Definition: meos.h:202