MobilityDB  1.0
tinstant.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 __TINSTANT_H__
37 #define __TINSTANT_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 #include "point/postgis.h"
46 
47 /*****************************************************************************/
48 
49 extern TInstant *tinstant_make(Datum value, TimestampTz t, Oid basetypid);
50 extern TInstant *tinstant_copy(const TInstant *inst);
51 extern Datum* tinstant_value_ptr(const TInstant *inst);
52 extern Datum tinstant_value(const TInstant *inst);
53 extern Datum tinstant_value_copy(const TInstant *inst);
54 extern void tinstant_set(TInstant *inst, Datum value, TimestampTz t);
55 
56 /* Input/output functions */
57 
58 extern char *tinstant_to_string(const TInstant *inst, char *(*value_out)(Oid, Datum));
59 extern void tinstant_write(const TInstant *inst, StringInfo buf);
60 extern TInstant *tinstant_read(StringInfo buf, Oid basetypid);
61 
62 /* Intersection function */
63 
64 extern bool intersection_tinstant_tinstant(const TInstant *inst1,
65  const TInstant *inst2, TInstant **inter1, TInstant **inter2);
66 
67 /* Merge functions
68  * Notice that tinstant_merge is used for tinstant_append_tinstant */
69 
70 extern Temporal *tinstant_merge(const TInstant *inst1, const TInstant *inst2);
71 extern Temporal *tinstant_merge_array(const TInstant **instants, int count);
72 
73 /* Cast functions */
74 
75 extern TInstant *tintinst_to_tfloatinst(const TInstant *inst);
76 extern TInstant *tfloatinst_to_tintinst(const TInstant *inst);
77 
78 /* Transformation functions */
79 
81 extern TInstant *tsequence_to_tinstant(const TSequence *seq);
83 
84 /* Accessor functions */
85 
86 extern ArrayType *tinstant_values_array(const TInstant *inst);
87 extern ArrayType *tfloatinst_ranges(const TInstant *inst);
88 extern PeriodSet *tinstant_get_time(const TInstant *inst);
89 extern void tinstant_period(Period *p, const TInstant *inst);
90 extern ArrayType *tinstant_sequences_array(const TInstant *inst);
91 extern ArrayType *tinstant_timestamps(const TInstant *inst);
92 extern const TInstant **tinstant_instants(const TInstant *inst, int *count);
93 extern ArrayType *tinstant_instants_array(const TInstant *inst);
94 extern TInstant *tinstant_shift(const TInstant *inst, const Interval *interval);
95 
96 extern bool tinstant_ever_eq(const TInstant *inst, Datum value);
97 extern bool tinstant_ever_lt(const TInstant *inst, Datum value);
98 extern bool tinstant_ever_le(const TInstant *inst, Datum value);
99 
100 extern bool tinstant_always_eq(const TInstant *inst, Datum value);
101 extern bool tinstant_always_lt(const TInstant *inst, Datum value);
102 extern bool tinstant_always_le(const TInstant *inst, Datum value);
103 
104 /* Restriction Functions */
105 
106 extern TInstant *tinstant_restrict_value(const TInstant *inst,
107  Datum value, bool atfunc);
108 extern bool tinstant_restrict_values_test(const TInstant *inst,
109  const Datum *values, int count, bool atfunc);
110  extern TInstant *tinstant_restrict_values(const TInstant *inst,
111  const Datum *values, int count, bool atfunc);
112 extern bool tnumberinst_restrict_range_test(const TInstant *inst,
113  const RangeType *range, bool atfunc);
114 extern TInstant *tnumberinst_restrict_range(const TInstant *inst,
115  const RangeType *range, bool atfunc);
116 extern bool tnumberinst_restrict_ranges_test(const TInstant *inst,
117  RangeType **normranges, int count, bool atfunc);
118 extern TInstant *tnumberinst_restrict_ranges(const TInstant *inst,
119  RangeType **normranges, int count, bool atfunc);
120 extern TInstant *tinstant_restrict_timestamp(const TInstant *inst,
121  TimestampTz t, bool atfunc);
122 extern bool tinstant_value_at_timestamp(const TInstant *inst,
123  TimestampTz t, Datum *result);
124 extern bool tinstant_restrict_timestampset_test(const TInstant *inst,
125  const TimestampSet *ts, bool atfunc);
127  const TimestampSet *ts, bool atfunc);
128 extern TInstant *tinstant_restrict_period(const TInstant *inst,
129  const Period *p, bool atfunc);
130 extern bool tinstant_restrict_periodset_test(const TInstant *inst,
131  const PeriodSet *ps, bool atfunc);
132 extern TInstant *tinstant_restrict_periodset(const TInstant *inst,
133  const PeriodSet *ps, bool atfunc);
134 
135 /* Intersection Functions */
136 
137 extern bool tinstant_intersects_timestamp(const TInstant *inst, TimestampTz t);
138 extern bool tinstant_intersects_timestampset(const TInstant *inst, const TimestampSet *ts);
139 extern bool tinstant_intersects_period(const TInstant *inst, const Period *p);
140 extern bool tinstant_intersects_periodset(const TInstant *inst, const PeriodSet *ps);
141 
142 /* Comparison functions */
143 
144 extern int tinstant_cmp(const TInstant *inst1, const TInstant *inst2);
145 extern bool tinstant_eq(const TInstant *inst1, const TInstant *inst2);
146 
147 /* Function for defining hash index */
148 
149 extern uint32 tinstant_hash(const TInstant *inst);
150 
151 /*****************************************************************************/
152 
153 #endif
void tinstant_period(Period *p, const TInstant *inst)
Returns the bounding period on which the temporal instant value is defined.
Definition: tinstant.c:463
TInstant * tfloatinst_to_tintinst(const TInstant *inst)
Cast the temporal float value as a temporal integer value.
Definition: tinstant.c:358
bool tinstant_ever_eq(const TInstant *inst, Datum value)
Returns true if temporal value is ever equal to the base value.
Definition: tinstant.c:533
bool tinstant_eq(const TInstant *inst1, const TInstant *inst2)
Returns true if the two temporal instant values are equal.
Definition: tinstant.c:871
Structure to represent periods.
Definition: timetypes.h:52
TInstant * tinstant_restrict_values(const TInstant *inst, const Datum *values, int count, bool atfunc)
Restricts the temporal value to the array of base values.
Definition: tinstant.c:627
bool tinstant_always_eq(const TInstant *inst, Datum value)
Returns true if temporal value is always equal to the base value.
Definition: tinstant.c:542
char * tinstant_to_string(const TInstant *inst, char *(*value_out)(Oid, Datum))
Returns the string representation of the temporal value.
Definition: tinstant.c:249
TInstant * tinstant_restrict_timestamp(const TInstant *inst, TimestampTz t, bool atfunc)
Restricts the temporal value to the (complement of the) timestamp.
Definition: tinstant.c:721
bool tinstant_restrict_periodset_test(const TInstant *inst, const PeriodSet *ps, bool atfunc)
Returns true if the temporal value satisfies the restriction to the timestamp set.
Definition: tinstant.c:790
TInstant * tinstant_make(Datum value, TimestampTz t, Oid basetypid)
Construct a temporal instant value from the arguments.
Definition: tinstant.c:120
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: temporal.h:241
bool tinstant_always_le(const TInstant *inst, Datum value)
Returns true if the temporal value is always less than or equal to the base value.
Definition: tinstant.c:582
bool tinstant_restrict_timestampset_test(const TInstant *inst, const TimestampSet *ts, bool atfunc)
Returns true if the temporal value satisfies the restriction to the timestamp set.
Definition: tinstant.c:750
bool tinstant_restrict_values_test(const TInstant *inst, const Datum *values, int count, bool atfunc)
Returns true if the temporal value satisfies the restriction to the (complement of the) array of base...
Definition: tinstant.c:611
TInstant * tinstantset_to_tinstant(const TInstantSet *ti)
Transform the temporal instant set value into a temporal instant value.
Definition: tinstant.c:385
ArrayType * tinstant_instants_array(const TInstant *inst)
Returns the temporal value as an array.
Definition: tinstant.c:507
bool tinstant_intersects_timestampset(const TInstant *inst, const TimestampSet *ts)
Returns true if the temporal value intersects the timestamp set.
Definition: tinstant.c:826
ArrayType * tinstant_values_array(const TInstant *inst)
Returns the base value of the temporal value as an array.
Definition: tinstant.c:429
Datum * tinstant_value_ptr(const TInstant *inst)
Returns a pointer to the base value of the temporal instant value.
Definition: tinstant.c:67
void tinstant_set(TInstant *inst, Datum value, TimestampTz t)
Sets the value and the timestamp of the temporal instant value.
Definition: tinstant.c:230
Basic functions for temporal types of any subtype.
const TInstant ** tinstant_instants(const TInstant *inst, int *count)
Returns the instants of the temporal value as a C array.
Definition: tinstant.c:495
TInstant * tinstant_restrict_period(const TInstant *inst, const Period *p, bool atfunc)
Restricts the temporal value to the period.
Definition: tinstant.c:775
bool intersection_tinstant_tinstant(const TInstant *inst1, const TInstant *inst2, TInstant **inter1, TInstant **inter2)
Temporally intersect the two temporal values.
Definition: tinstant.c:325
Structure to represent period sets.
Definition: timetypes.h:84
uint32 tinstant_hash(const TInstant *inst)
Returns the hash value of the temporal value.
Definition: tinstant.c:922
TInstant * tintinst_to_tfloatinst(const TInstant *inst)
Cast the temporal integer value as a temporal float value.
Definition: tinstant.c:344
ArrayType * tfloatinst_ranges(const TInstant *inst)
Returns the base value of the temporal float value as a range.
Definition: tinstant.c:440
TInstant * tinstant_copy(const TInstant *inst)
Returns a copy of the temporal instant value.
Definition: tinstant.c:213
Structure to represent temporal values of sequence set subtype.
Definition: temporal.h:293
Structure to represent timestamp sets.
Definition: timetypes.h:73
ArrayType * tinstant_timestamps(const TInstant *inst)
Returns the timestamp of the temporal value as an array.
Definition: tinstant.c:485
bool tnumberinst_restrict_ranges_test(const TInstant *inst, RangeType **normranges, int count, bool atfunc)
Returns true if the temporal number satisfies the restriction to the (complement of the) array of ran...
Definition: tinstant.c:685
TInstant * tinstant_restrict_periodset(const TInstant *inst, const PeriodSet *ps, bool atfunc)
Restricts the temporal value to the period set.
Definition: tinstant.c:802
PeriodSet * tinstant_get_time(const TInstant *inst)
Returns the time on which the temporal value is defined as a period set.
Definition: tinstant.c:453
PostGIS definitions that are needed in MobilityDB but are not exported in PostGIS headers...
Structure to represent temporal values of instant set subtype.
Definition: temporal.h:266
bool tinstant_intersects_timestamp(const TInstant *inst, TimestampTz t)
Returns true if the temporal value intersects the timestamp.
Definition: tinstant.c:817
TInstant * tinstant_restrict_timestampset(const TInstant *inst, const TimestampSet *ts, bool atfunc)
Restricts the temporal value to the timestamp set.
Definition: tinstant.c:763
bool tinstant_intersects_periodset(const TInstant *inst, const PeriodSet *ps)
Returns true if the temporal value intersects the period set.
Definition: tinstant.c:848
Datum tinstant_value(const TInstant *inst)
Returns the base value of the temporal value.
Definition: tinstant.c:76
TInstant * tinstant_shift(const TInstant *inst, const Interval *interval)
Shift the time span of the temporal value by the interval.
Definition: tinstant.c:516
TInstant * tsequenceset_to_tinstant(const TSequenceSet *ts)
Transform the temporal sequence set value into a temporal instant value.
Definition: tinstant.c:411
Temporal * tinstant_merge_array(const TInstant **instants, int count)
Merge the array of temporal instant values.
Definition: tinstant.c:192
TInstant * tnumberinst_restrict_ranges(const TInstant *inst, RangeType **normranges, int count, bool atfunc)
Restricts the temporal number to the (complement of the) array of ranges of base values.
Definition: tinstant.c:706
bool tnumberinst_restrict_range_test(const TInstant *inst, const RangeType *range, bool atfunc)
Returns true if the temporal number satisfies the restriction to the (complement of the) range of bas...
Definition: tinstant.c:647
TInstant * tnumberinst_restrict_range(const TInstant *inst, const RangeType *range, bool atfunc)
Restricts the temporal number to the (complement of the) range of base values.
Definition: tinstant.c:669
bool tinstant_always_lt(const TInstant *inst, Datum value)
Returns true if the temporal value is always less than the base value.
Definition: tinstant.c:572
Datum tinstant_value_copy(const TInstant *inst)
Returns a copy of the base value of the temporal instant value.
Definition: tinstant.c:90
TInstant * tsequence_to_tinstant(const TSequence *seq)
Transform the temporal sequence value into a temporal instant value.
Definition: tinstant.c:398
bool tinstant_ever_lt(const TInstant *inst, Datum value)
Returns true if the temporal value is ever less than the base value.
Definition: tinstant.c:553
bool tinstant_value_at_timestamp(const TInstant *inst, TimestampTz t, Datum *result)
Returns the base value of the temporal value at the timestamp.
Definition: tinstant.c:735
void tinstant_write(const TInstant *inst, StringInfo buf)
Write the binary representation of the temporal value into the buffer.
Definition: tinstant.c:276
ArrayType * tinstant_sequences_array(const TInstant *inst)
Returns the sequences of the temporal value as a PostgreSQL array.
Definition: tinstant.c:472
Temporal * tinstant_merge(const TInstant *inst1, const TInstant *inst2)
Merge two temporal instant values.
Definition: tinstant.c:178
bool tinstant_ever_le(const TInstant *inst, Datum value)
Returns true if the temporal value is ever less than or equal to the base value.
Definition: tinstant.c:563
bool tinstant_intersects_period(const TInstant *inst, const Period *p)
Returns true if the temporal value intersects the period.
Definition: tinstant.c:839
Structure to represent temporal values of sequence subtype.
Definition: temporal.h:279
int tinstant_cmp(const TInstant *inst1, const TInstant *inst2)
Returns -1, 0, or 1 depending on whether the first temporal value is less than, equal, or greater than the second one.
Definition: tinstant.c:892
TInstant * tinstant_read(StringInfo buf, Oid basetypid)
Returns a new temporal value from its binary representation read from the buffer. ...
Definition: tinstant.c:297
TInstant * tinstant_restrict_value(const TInstant *inst, Datum value, bool atfunc)
Restricts the temporal value to (the complement of) the base value.
Definition: tinstant.c:595
Structure to represent temporal values of instant subtype.
Definition: temporal.h:253