MobilityDB  1.0
timestampset.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 __TIMESTAMPSET_H__
37 #define __TIMESTAMPSET_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 TimestampTz timestampset_time_n(const TimestampSet *ts, int index);
48 extern const Period *timestampset_bbox_ptr(const TimestampSet *ts);
49 extern void timestampset_bbox(Period *p, const TimestampSet *ts);
50 extern TimestampSet *timestampset_make(const TimestampTz *times, int count);
51 extern TimestampSet *timestampset_make_free(TimestampTz *times, int count);
53 extern bool timestampset_find_timestamp(const TimestampSet *ts, TimestampTz t, int *loc);
54 
55 /* Input/output functions */
56 
57 extern Datum timestampset_in(PG_FUNCTION_ARGS);
58 extern Datum timestampset_out(PG_FUNCTION_ARGS);
59 extern Datum timestampset_send(PG_FUNCTION_ARGS);
60 extern Datum timestampset_recv(PG_FUNCTION_ARGS);
61 
62 extern char *timestampset_to_string(const TimestampSet *ts);
63 
64 /* Constructor function */
65 
66 extern Datum timestampset_constructor(PG_FUNCTION_ARGS);
67 
68 /* Cast function */
69 
70 extern Datum timestamp_to_timestampset(PG_FUNCTION_ARGS);
71 extern Datum timestampset_to_period(PG_FUNCTION_ARGS);
72 
73 /* Accessor functions */
74 
75 extern Datum timestampset_mem_size(PG_FUNCTION_ARGS);
76 extern Datum timestampset_timespan(PG_FUNCTION_ARGS);
77 extern Datum timestampset_num_timestamps(PG_FUNCTION_ARGS);
78 extern Datum timestampset_start_timestamp(PG_FUNCTION_ARGS);
79 extern Datum timestampset_end_timestamp(PG_FUNCTION_ARGS);
80 extern Datum timestampset_timestamp_n(PG_FUNCTION_ARGS);
81 extern Datum timestampset_timestamps(PG_FUNCTION_ARGS);
82 extern Datum timestampset_shift(PG_FUNCTION_ARGS);
83 
84 extern void timestampset_to_period_internal(Period *p, const TimestampSet *ts);
85 extern TimestampTz *timestampset_timestamps_internal(const TimestampSet *ts);
86 extern TimestampSet *timestampset_shift_internal(const TimestampSet *ts, const Interval *interval);
87 
88 /* Functions for defining B-tree index */
89 
90 extern Datum timestampset_cmp(PG_FUNCTION_ARGS);
91 extern Datum timestampset_eq(PG_FUNCTION_ARGS);
92 extern Datum timestampset_ne(PG_FUNCTION_ARGS);
93 extern Datum timestampset_lt(PG_FUNCTION_ARGS);
94 extern Datum timestampset_le(PG_FUNCTION_ARGS);
95 extern Datum timestampset_ge(PG_FUNCTION_ARGS);
96 extern Datum timestampset_gt(PG_FUNCTION_ARGS);
97 
98 extern int timestampset_cmp_internal(const TimestampSet *ts1, const TimestampSet *ts2);
99 extern bool timestampset_eq_internal(const TimestampSet *ts1, const TimestampSet *ts2);
100 extern bool timestampset_ne_internal(const TimestampSet *ts1, const TimestampSet *ts2);
101 
102 #endif
103 
104 /*****************************************************************************/
Structure to represent periods.
Definition: timetypes.h:52
Datum timestampset_le(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is less than or equal to the second one...
Definition: timestampset.c:640
TimestampTz timestampset_time_n(const TimestampSet *ts, int index)
Returns the n-th timestamp of the timestamp set value.
Definition: timestampset.c:55
TimestampSet * timestampset_make(const TimestampTz *times, int count)
Construct a timestamp set from an array of timestamps.
Definition: timestampset.c:97
void timestampset_bbox(Period *p, const TimestampSet *ts)
Copy in the first argument the bounding box of the timestamp set value.
Definition: timestampset.c:73
Datum timestampset_recv(PG_FUNCTION_ARGS)
Receive function for timestamp set values.
Definition: timestampset.c:280
Datum timestampset_ge(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is greater than or equal to the second one...
Definition: timestampset.c:656
bool timestampset_eq_internal(const TimestampSet *ts1, const TimestampSet *ts2)
Returns true if the first timestamp set value is equal to the second one (internal function) ...
Definition: timestampset.c:560
Datum timestampset_start_timestamp(PG_FUNCTION_ARGS)
Returns the start timestamp of the timestamp set value.
Definition: timestampset.c:402
Datum timestampset_constructor(PG_FUNCTION_ARGS)
Construct a timestamp set value from an array of timestamp values.
Definition: timestampset.c:300
Datum timestampset_timespan(PG_FUNCTION_ARGS)
Returns the timespan of the timestamp set value.
Definition: timestampset.c:374
Datum timestampset_eq(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is equal to the second one.
Definition: timestampset.c:581
Datum timestampset_gt(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is greater than the second one.
Definition: timestampset.c:671
Datum timestampset_shift(PG_FUNCTION_ARGS)
Shift the period set value by the interval.
Definition: timestampset.c:491
Functions for time types based on TimestampTz, that is, TimestampSet, Period, and PeriodSet...
TimestampSet * timestampset_shift_internal(const TimestampSet *ts, const Interval *interval)
Shift the period set value by the interval (internal function)
Definition: timestampset.c:473
Structure to represent timestamp sets.
Definition: timetypes.h:73
Datum timestampset_to_period(PG_FUNCTION_ARGS)
Returns the bounding period on which the timestamp set value is defined.
Definition: timestampset.c:344
Datum timestampset_in(PG_FUNCTION_ARGS)
Input function for timestamp set values.
Definition: timestampset.c:212
Datum timestampset_timestamps(PG_FUNCTION_ARGS)
Returns the timestamps of the timestamp set value.
Definition: timestampset.c:459
Datum timestampset_mem_size(PG_FUNCTION_ARGS)
Returns the size in bytes of the timestamp set value.
Definition: timestampset.c:361
const Period * timestampset_bbox_ptr(const TimestampSet *ts)
Returns a pointer to the precomputed bounding box of the timestamp set value.
Definition: timestampset.c:64
Datum timestampset_end_timestamp(PG_FUNCTION_ARGS)
Returns the end timestamp of the timestamp set value.
Definition: timestampset.c:415
Datum timestampset_ne(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is different from the second one.
Definition: timestampset.c:608
Datum timestampset_timestamp_n(PG_FUNCTION_ARGS)
Returns the n-th timestamp of the timestamp set value.
Definition: timestampset.c:428
Datum timestampset_out(PG_FUNCTION_ARGS)
Output function for timestamp set values.
Definition: timestampset.c:241
Datum timestampset_lt(PG_FUNCTION_ARGS)
Returns true if the first timestamp set value is less than the second one.
Definition: timestampset.c:624
Datum timestampset_cmp(PG_FUNCTION_ARGS)
Returns -1, 0, or 1 depending on whether the first timestamp set value is less than, equal, or greater than the second temporal value.
Definition: timestampset.c:543
Datum timestampset_num_timestamps(PG_FUNCTION_ARGS)
Returns the number of timestamps of the timestamp set value.
Definition: timestampset.c:390
int timestampset_cmp_internal(const TimestampSet *ts1, const TimestampSet *ts2)
Returns -1, 0, or 1 depending on whether the first timestamp set value is less than, equal, or greater than the second temporal value (internal function)
Definition: timestampset.c:512
bool timestampset_find_timestamp(const TimestampSet *ts, TimestampTz t, int *loc)
Returns the location of the timestamp in the timestamp set value using binary search.
Definition: timestampset.c:177
Datum timestamp_to_timestampset(PG_FUNCTION_ARGS)
Cast a timestamp value as a timestamp set value.
Definition: timestampset.c:320
bool timestampset_ne_internal(const TimestampSet *ts1, const TimestampSet *ts2)
Returns true if the first timestamp set value is different from the second one (internal function) ...
Definition: timestampset.c:598
TimestampTz * timestampset_timestamps_internal(const TimestampSet *ts)
Returns the timestamps of the timestamp set value (internal function)
Definition: timestampset.c:446
Datum timestampset_send(PG_FUNCTION_ARGS)
Send function for timestamp set values.
Definition: timestampset.c:254
TimestampSet * timestampset_make_free(TimestampTz *times, int count)
Construct a timestamp set from the array of timestamps and free the array after the creation...
Definition: timestampset.c:129
TimestampSet * timestampset_copy(const TimestampSet *ts)
Returns a copy of the timestamp set.
Definition: timestampset.c:145
char * timestampset_to_string(const TimestampSet *ts)
Returns the string representation of the timestamp set value.
Definition: timestampset.c:223
void timestampset_to_period_internal(Period *p, const TimestampSet *ts)
Returns the bounding period on which the timestamp set value is defined (internal function) ...
Definition: timestampset.c:332