7de9ed742244b8c30b7ec2e7266e3fb9ae3ed552
1 /*
2 * PostRR - src/rrtimeslice.c
3 * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
28 /*
29 * A PostgreSQL data-type providing a timeslice implementing round-robin
30 * features.
31 */
33 #include "postrr.h"
34 #include "utils/pg_spi.h"
36 #include <string.h>
38 #include <postgres.h>
39 #include <fmgr.h>
41 /* Postgres utilities */
42 #include <access/hash.h>
43 #include <executor/spi.h>
44 #include <utils/array.h>
45 #include <utils/datetime.h>
46 #include <utils/timestamp.h>
47 #include <miscadmin.h> /* DateStyle */
49 #ifdef HAVE_INT64_TIMESTAMP
50 # define TSTAMP_TO_INT64(t) (t)
51 # define INT64_TO_TSTAMP(i) (i)
52 #else /* ! HAVE_INT64_TIMESTAMP */
53 # define TSTAMP_TO_INT64(t) (int64)((t) * (double)USECS_PER_SEC)
54 # define INT64_TO_TSTAMP(i) ((double)(i) / (double)USECS_PER_SEC)
55 #endif
57 /*
58 * data type
59 */
61 struct rrtimeslice {
62 TimestampTz tstamp;
63 int32 tsid;
64 uint32 seq;
65 };
67 /*
68 * internal helper functions
69 */
71 static int32
72 rrtimeslice_set_spec(int32 len, int32 num)
73 {
74 int spi_rc;
76 char query[256];
77 int32 typmod = 0;
79 if ((len <= 0) || (num <= 0))
80 ereport(ERROR, (
81 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
82 errmsg("rrtimeslice(%i, %i) "
83 "length/num may not be less than zero",
84 len, num)
85 ));
87 if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
88 ereport(ERROR, (
89 errmsg("failed to store rrtimeslice spec: "
90 "could not connect to SPI manager: %s",
91 SPI_result_code_string(spi_rc))
92 ));
94 snprintf(query, sizeof(query),
95 "SELECT tsid FROM postrr.rrtimeslices "
96 "WHERE tslen = %d AND tsnum = %d "
97 "LIMIT 1", len, num);
98 query[sizeof(query) - 1] = '\0';
100 spi_rc = pg_spi_get_int(query, 1, &typmod);
101 if (spi_rc == PG_SPI_OK) {
102 SPI_finish();
103 return typmod;
104 }
105 else if (spi_rc != PG_SPI_ERROR_NO_VALUES)
106 pg_spi_ereport(ERROR, "store rrtimeslice spec", spi_rc);
108 snprintf(query, sizeof(query),
109 "SELECT nextval('postrr.tsid'::regclass)");
110 query[sizeof(query) - 1] = '\0';
112 spi_rc = pg_spi_get_int(query, 1, &typmod);
113 if ((spi_rc != PG_SPI_OK) || (typmod <= 0))
114 pg_spi_ereport(ERROR, "retrieve nextval(postrr.tsid)", spi_rc);
116 snprintf(query, sizeof(query),
117 "INSERT INTO postrr.rrtimeslices(tsid, tslen, tsnum) "
118 "VALUES (%d, %d, %d)", typmod, len, num);
119 query[sizeof(query) - 1] = '\0';
121 spi_rc = SPI_exec(query, /* max num rows = */ 1);
122 if (spi_rc != SPI_OK_INSERT)
123 ereport(ERROR, (
124 errmsg("failed to store rrtimeslice spec: "
125 "failed to execute query: %s",
126 SPI_result_code_string(spi_rc))
127 ));
129 SPI_finish();
130 return typmod;
131 } /* rrtimeslice_set_spec */
133 static int
134 rrtimeslice_get_spec(int32 typmod, int32 *len, int32 *num)
135 {
136 int spi_rc;
138 char query[256];
140 if (typmod <= 0)
141 return -1;
143 if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
144 ereport(ERROR, (
145 errmsg("failed to determine rrtimeslice spec: "
146 "could not connect to SPI manager: %s",
147 SPI_result_code_string(spi_rc))
148 ));
150 snprintf(query, sizeof(query),
151 "SELECT tslen, tsnum FROM postrr.rrtimeslices "
152 "WHERE tsid = %d", typmod);
153 query[sizeof(query) - 1] = '\0';
155 spi_rc = pg_spi_get_int(query, 2, len, num);
156 if (spi_rc != PG_SPI_OK)
157 pg_spi_ereport(ERROR, "determine rrtimeslice spec", spi_rc);
159 SPI_finish();
160 return 0;
161 } /* rrtimeslice_get_spec */
163 static int
164 rrtimeslice_apply_typmod(rrtimeslice_t *tslice, int32 typmod)
165 {
166 int64 tstamp;
167 int64 length;
168 int64 seq;
170 int32 len = 0;
171 int32 num = 0;
173 if (rrtimeslice_get_spec(typmod, &len, &num))
174 return -1;
176 if ((len <= 0) || (num <= 0))
177 ereport(ERROR, (
178 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
179 errmsg("rrtimeslice(%i, %i) "
180 "length/num may not be less than zero",
181 len, num)
182 ));
184 tstamp = TSTAMP_TO_INT64(tslice->tstamp);
186 length = len * USECS_PER_SEC;
187 if (tstamp % length != 0)
188 tstamp = tstamp - (tstamp % length) + length;
189 seq = tstamp % (length * num) / length;
190 seq = seq % num;
192 tslice->tstamp = INT64_TO_TSTAMP(tstamp);
193 tslice->tsid = typmod;
194 tslice->seq = (uint32)seq;
195 return 0;
196 } /* rrtimeslice_apply_typmod */
198 /*
199 * rrtimeslice_cmp_unify:
200 * Unify two RRTimeslices in order to prepare them for comparison. That is, if
201 * either one of the arguments does not have any typmod applied, then apply
202 * the typmod of the other argument. Throws an error if the typmods don't
203 * match.
204 *
205 * Returns:
206 * - 0 if the arguments could be unified
207 * - 1 if only the first argument is NULL
208 * - 2 if both arguments are NULL
209 * - 3 if only the second argument is NULL
210 */
211 static int
212 rrtimeslice_cmp_unify(rrtimeslice_t *ts1, rrtimeslice_t *ts2)
213 {
214 if ((! ts1) && (! ts2))
215 return 0;
216 else if (! ts1)
217 return -1;
218 else if (! ts2)
219 return 1;
221 if (ts1->tsid && (! ts2->tsid))
222 rrtimeslice_apply_typmod(ts2, ts1->tsid);
223 else if ((! ts1->tsid) && ts2->tsid)
224 rrtimeslice_apply_typmod(ts1, ts2->tsid);
226 if (ts1->tsid != ts2->tsid) /* XXX: compare len/num */
227 ereport(ERROR, (
228 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
229 errmsg("invalid comparison: cannot compare "
230 "rrtimeslices with different typmods (yet)")
231 ));
232 return 0;
233 } /* rrtimeslice_cmp_unify */
235 /*
236 * prototypes for PostgreSQL functions
237 */
239 PG_FUNCTION_INFO_V1(rrtimeslice_validate);
241 PG_FUNCTION_INFO_V1(rrtimeslice_in);
242 PG_FUNCTION_INFO_V1(rrtimeslice_out);
243 PG_FUNCTION_INFO_V1(rrtimeslice_typmodin);
244 PG_FUNCTION_INFO_V1(rrtimeslice_typmodout);
246 PG_FUNCTION_INFO_V1(rrtimeslice_to_rrtimeslice);
247 PG_FUNCTION_INFO_V1(rrtimeslice_to_timestamptz);
249 PG_FUNCTION_INFO_V1(rrtimeslice_cmp);
251 PG_FUNCTION_INFO_V1(rrtimeslice_seq_eq);
252 PG_FUNCTION_INFO_V1(rrtimeslice_seq_ne);
253 PG_FUNCTION_INFO_V1(rrtimeslice_seq_lt);
254 PG_FUNCTION_INFO_V1(rrtimeslice_seq_gt);
255 PG_FUNCTION_INFO_V1(rrtimeslice_seq_le);
256 PG_FUNCTION_INFO_V1(rrtimeslice_seq_ge);
257 PG_FUNCTION_INFO_V1(rrtimeslice_seq_cmp);
258 PG_FUNCTION_INFO_V1(rrtimeslice_seq_hash);
260 /*
261 * public API
262 */
264 Datum
265 rrtimeslice_validate(PG_FUNCTION_ARGS)
266 {
267 char type_info[1024];
268 char *result;
269 size_t req_len;
270 size_t len;
272 if (PG_NARGS() != 1)
273 ereport(ERROR, (
274 errmsg("rrtimeslice_validate() expect one argument"),
275 errhint("Usage rrtimeslice_validate(expected_size)")
276 ));
278 req_len = (size_t)PG_GETARG_UINT32(0);
279 len = sizeof(rrtimeslice_t);
281 if (req_len != len)
282 ereport(ERROR, (
283 errmsg("length of the rrtimeslice type "
284 "does not match the expected length"),
285 errhint("Please report a bug against PostRR")
286 ));
288 snprintf(type_info, sizeof(type_info),
289 "rrtimeslice validated successfully; type length = %zu", len);
290 type_info[sizeof(type_info) - 1] = '\0';
292 result = pstrdup(type_info);
293 PG_RETURN_CSTRING(result);
294 } /* rrtimeslice_validate */
296 Datum
297 rrtimeslice_in(PG_FUNCTION_ARGS)
298 {
299 rrtimeslice_t *tslice;
301 TimestampTz tstamp = 0;
302 int32 typmod;
304 struct pg_tm tm;
305 fsec_t fsec = 0;
306 int tz = 0;
308 char *time_str;
309 int pg_dt_err;
310 char buf[MAXDATELEN + MAXDATEFIELDS];
311 char *field[MAXDATEFIELDS];
312 int ftype[MAXDATEFIELDS];
313 int num_fields = 0;
314 int dtype = 0;
316 if (PG_NARGS() != 3)
317 ereport(ERROR, (
318 errmsg("rrtimeslice_in() expects three arguments"),
319 errhint("Usage: rrtimeslice_in(col_name, oid, typmod)")
320 ));
322 tslice = (rrtimeslice_t *)palloc0(sizeof(*tslice));
323 time_str = PG_GETARG_CSTRING(0);
324 typmod = PG_GETARG_INT32(2);
326 pg_dt_err = ParseDateTime(time_str, buf, sizeof(buf),
327 field, ftype, MAXDATEFIELDS, &num_fields);
329 if (! pg_dt_err)
330 pg_dt_err = DecodeDateTime(field, ftype, num_fields,
331 &dtype, &tm, &fsec, &tz);
332 if (pg_dt_err)
333 DateTimeParseError(pg_dt_err, time_str, "rrtimeslice");
335 switch (dtype) {
336 case DTK_DATE:
337 if (tm2timestamp(&tm, fsec, &tz, &tstamp))
338 ereport(ERROR, (
339 errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
340 errmsg("timestamp out of range: %s", time_str)
341 ));
342 break;
344 case DTK_EPOCH:
345 tstamp = SetEpochTimestamp();
346 break;
348 default:
349 ereport(ERROR, (
350 errmsg("unexpected dtype %d while "
351 "parsing rrtimeslice: %s", dtype, time_str)
352 ));
353 }
355 tslice->tstamp = tstamp;
357 /* most likely, this won't happen … coerce_type
358 * (src/backend/parser/parse_coerce.c) does not pass that information to
359 * the input function but rather lets a length conversion cast do that
360 * work */
361 if (typmod > 0)
362 rrtimeslice_apply_typmod(tslice, typmod);
364 PG_RETURN_RRTIMESLICE_P(tslice);
365 } /* rrtimeslice_in */
367 Datum
368 rrtimeslice_out(PG_FUNCTION_ARGS)
369 {
370 rrtimeslice_t *tslice;
372 struct pg_tm tm;
373 fsec_t fsec = 0;
374 int tz = 0;
376 char *tz_str = NULL;
378 char ts_str[MAXDATELEN + 1];
379 char buf_l[MAXDATELEN + 1];
380 char buf_u[MAXDATELEN + 1];
381 char *result;
383 int32 len = 0;
384 int32 num = 0;
386 if (PG_NARGS() != 1)
387 ereport(ERROR, (
388 errmsg("rrtimeslice_out() expects one argument"),
389 errhint("Usage: rrtimeslice_out(rrtimeslice)")
390 ));
392 tslice = PG_GETARG_RRTIMESLICE_P(0);
394 if (TIMESTAMP_NOT_FINITE(tslice->tstamp)
395 || timestamp2tm(tslice->tstamp, &tz, &tm, &fsec, &tz_str, NULL))
396 ereport(ERROR, (
397 errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
398 errmsg("invalid (non-finite) timestamp")
399 ));
401 EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_u);
403 if (! rrtimeslice_get_spec(tslice->tsid, &len, &num)) {
404 TimestampTz lower = tslice->tstamp - (len * USECS_PER_SEC);
406 if (timestamp2tm(lower, &tz, &tm, &fsec, &tz_str, NULL))
407 ereport(ERROR, (
408 errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
409 errmsg("invalid (non-finite) lower timestamp")
410 ));
412 EncodeDateTime(&tm, fsec, &tz, &tz_str, DateStyle, buf_l);
413 }
414 else {
415 strncpy(buf_l, "ERR", sizeof(buf_l));
416 buf_l[sizeof(buf_l) - 1] = '\0';
417 }
419 snprintf(ts_str, sizeof(ts_str), "(\"%s\", \"%s\"] #%i/%i",
420 buf_l, buf_u, tslice->seq, num);
422 result = pstrdup(ts_str);
423 PG_RETURN_CSTRING(result);
424 } /* rrtimeslice_out */
426 Datum
427 rrtimeslice_typmodin(PG_FUNCTION_ARGS)
428 {
429 ArrayType *tm_array;
431 int32 *spec;
432 int spec_elems = 0;
433 int32 typmod;
435 if (PG_NARGS() != 1)
436 ereport(ERROR, (
437 errmsg("rrtimeslice_typmodin() expects one argument"),
438 errhint("Usage: rrtimeslice_typmodin(array)")
439 ));
441 tm_array = PG_GETARG_ARRAYTYPE_P(0);
443 spec = ArrayGetIntegerTypmods(tm_array, &spec_elems);
444 if (spec_elems != 2)
445 ereport(ERROR, (
446 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
447 errmsg("invalid rrtimeslice type modifier"),
448 errhint("Usage: rrtimeslice(<slice_len>, <num>)")
449 ));
451 typmod = rrtimeslice_set_spec(spec[0], spec[1]);
452 PG_RETURN_INT32(typmod);
453 } /* rrtimeslice_typmodin */
455 Datum
456 rrtimeslice_typmodout(PG_FUNCTION_ARGS)
457 {
458 int32 typmod;
459 char tm_str[1024];
460 char *result;
462 int32 len = 0;
463 int32 num = 0;
465 if (PG_NARGS() != 1)
466 ereport(ERROR, (
467 errmsg("rrtimeslice_typmodout() expects one argument"),
468 errhint("Usage: rrtimeslice_typmodout(typmod)")
469 ));
471 typmod = PG_GETARG_INT32(0);
472 if (rrtimeslice_get_spec(typmod, &len, &num))
473 tm_str[0] = '\0';
474 else if ((len <= 0) || (num <= 0))
475 snprintf(tm_str, sizeof(tm_str), "(#ERR, #ERR)");
476 else
477 snprintf(tm_str, sizeof(tm_str), "(%d, %d)", len, num);
479 result = pstrdup(tm_str);
480 PG_RETURN_CSTRING(result);
481 } /* rrtimeslice_typmodout */
483 Datum
484 rrtimeslice_to_rrtimeslice(PG_FUNCTION_ARGS)
485 {
486 rrtimeslice_t *tslice;
487 int32 typmod;
489 if (PG_NARGS() != 3)
490 ereport(ERROR, (
491 errmsg("rrtimeslice_to_rrtimeslice() "
492 "expects three arguments"),
493 errhint("Usage: rrtimeslice_to_rrtimeslice"
494 "(rrtimeslice, typmod, is_explicit)")
495 ));
497 tslice = PG_GETARG_RRTIMESLICE_P(0);
498 typmod = PG_GETARG_INT32(1);
500 if (typmod > 0) {
501 if ((! tslice->tsid) && (! tslice->seq))
502 rrtimeslice_apply_typmod(tslice, typmod);
503 else
504 ereport(ERROR, (
505 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
506 errmsg("invalid cast: cannot cast rrtimeslices "
507 "with different typmod (yet)")
508 ));
509 }
511 PG_RETURN_RRTIMESLICE_P(tslice);
512 } /* rrtimeslice_to_rrtimeslice */
514 Datum
515 rrtimeslice_to_timestamptz(PG_FUNCTION_ARGS)
516 {
517 rrtimeslice_t *tslice;
519 if (PG_NARGS() != 1)
520 ereport(ERROR, (
521 errmsg("rrtimeslice_to_timestamptz() "
522 "expects one argument"),
523 errhint("Usage: rrtimeslice_to_timestamptz"
524 "(rrtimeslice)")
525 ));
527 tslice = PG_GETARG_RRTIMESLICE_P(0);
528 PG_RETURN_TIMESTAMPTZ(tslice->tstamp);
529 } /* rrtimeslice_to_timestamptz */
531 int
532 rrtimeslice_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2)
533 {
534 int status;
536 status = rrtimeslice_cmp_unify(ts1, ts2);
537 if (status) /* [1, 3] -> [-1, 1] */
538 return status - 2;
540 if (ts1->tstamp == ts2->tstamp)
541 return 0;
542 else if ((ts1->seq == ts2->seq) && (ts1->tstamp < ts2->tstamp))
543 return -1;
544 else if (ts1->tstamp < ts2->tstamp)
545 return -2;
546 else if ((ts1->seq == ts2->seq) && (ts1->tstamp > ts2->tstamp))
547 return 1;
548 else
549 return 2;
550 } /* rrtimeslice_cmp_internal */
552 Datum
553 rrtimeslice_cmp(PG_FUNCTION_ARGS)
554 {
555 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
556 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
558 PG_RETURN_INT32(rrtimeslice_cmp_internal(ts1, ts2));
559 } /* rrtimeslice_cmp */
561 int
562 rrtimeslice_seq_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2)
563 {
564 int status;
566 status = rrtimeslice_cmp_unify(ts1, ts2);
567 if (status) /* [1, 3] -> [-1, 1] */
568 return status - 2;
570 if (ts1->seq < ts2->seq)
571 return -1;
572 else if (ts1->seq == ts2->seq)
573 return 0;
574 else
575 return 1;
576 } /* rrtimeslice_seq_cmp_internal */
578 Datum
579 rrtimeslice_seq_eq(PG_FUNCTION_ARGS)
580 {
581 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
582 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
584 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) == 0);
585 } /* rrtimeslice_seq_eq */
587 Datum
588 rrtimeslice_seq_ne(PG_FUNCTION_ARGS)
589 {
590 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
591 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
593 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) != 0);
594 } /* rrtimeslice_seq_ne */
596 Datum
597 rrtimeslice_seq_lt(PG_FUNCTION_ARGS)
598 {
599 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
600 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
602 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) < 0);
603 } /* rrtimeslice_seq_lt */
605 Datum
606 rrtimeslice_seq_le(PG_FUNCTION_ARGS)
607 {
608 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
609 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
611 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) <= 0);
612 } /* rrtimeslice_seq_le */
614 Datum
615 rrtimeslice_seq_gt(PG_FUNCTION_ARGS)
616 {
617 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
618 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
620 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) > 0);
621 } /* rrtimeslice_seq_gt */
623 Datum
624 rrtimeslice_seq_ge(PG_FUNCTION_ARGS)
625 {
626 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
627 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
629 PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) >= 0);
630 } /* rrtimeslice_seq_ge */
632 Datum
633 rrtimeslice_seq_cmp(PG_FUNCTION_ARGS)
634 {
635 rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
636 rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
638 PG_RETURN_INT32(rrtimeslice_seq_cmp_internal(ts1, ts2));
639 } /* rrtimeslice_seq_cmp */
641 Datum
642 rrtimeslice_seq_hash(PG_FUNCTION_ARGS)
643 {
644 rrtimeslice_t *ts = PG_GETARG_RRTIMESLICE_P(0);
645 return hash_uint32(ts->seq);
646 } /* rrtimeslice_seq_hash */
648 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */