Code

rrtimeslice: Added hash function and operator class.
authorSebastian Harl <sh@tokkee.org>
Thu, 3 May 2012 19:44:08 +0000 (21:44 +0200)
committerSebastian Harl <sh@tokkee.org>
Thu, 3 May 2012 19:44:08 +0000 (21:44 +0200)
src/postrr.h.in
src/postrr.sql.in
src/rrtimeslice.c

index 92025db3589fe438f457000ed41f985558e048c5..9a25d4e9f0c76375cbaab4a97c6ac85273644e2a 100644 (file)
@@ -94,6 +94,8 @@ Datum
 rrtimeslice_ge(PG_FUNCTION_ARGS);
 Datum
 rrtimeslice_cmp(PG_FUNCTION_ARGS);
+Datum
+rrtimeslice_hash(PG_FUNCTION_ARGS);
 
 /*
  * internal (not fmgr-callable) functions
index ffdb3a718350859625acbef996c37a5db570c733..c2b48212784d066231cd4f7d8d27d76c81307e4a 100644 (file)
@@ -135,6 +135,11 @@ CREATE OR REPLACE FUNCTION RRTimeslice_cmp(rrtimeslice, rrtimeslice)
        AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_cmp'
        LANGUAGE 'C' IMMUTABLE STRICT;
 
+CREATE OR REPLACE FUNCTION RRTimeslice_hash(rrtimeslice)
+       RETURNS integer
+       AS 'postrr-@POSTRR_MAJOR_VERSION@.@POSTRR_MINOR_VERSION@', 'rrtimeslice_hash'
+       LANGUAGE 'C' IMMUTABLE STRICT;
+
 CREATE OPERATOR = (
        LEFTARG    = RRTimeslice,
        RIGHTARG   = RRTimeslice,
@@ -198,6 +203,11 @@ CREATE OPERATOR CLASS rrtimeslice_ops
                OPERATOR 5 > ,
                FUNCTION 1 RRTimeslice_cmp(rrtimeslice, rrtimeslice);
 
+CREATE OPERATOR CLASS rrtimeslice_hash_ops
+       FOR TYPE RRTimeslice USING hash AS
+               OPERATOR 1 = ,
+               FUNCTION 1 RRTimeslice_hash(rrtimeslice);
+
 CREATE TYPE CData;
 
 CREATE OR REPLACE FUNCTION CData_validate(integer)
index d34da914a53713f40e9c5589ed424209868791a7..b08662292178e979c71c1d1c9e41bcb9855d6fe8 100644 (file)
@@ -39,6 +39,7 @@
 #include <fmgr.h>
 
 /* Postgres utilities */
+#include <access/hash.h>
 #include <executor/spi.h>
 #include <utils/array.h>
 #include <utils/datetime.h>
@@ -214,6 +215,7 @@ PG_FUNCTION_INFO_V1(rrtimeslice_gt);
 PG_FUNCTION_INFO_V1(rrtimeslice_le);
 PG_FUNCTION_INFO_V1(rrtimeslice_ge);
 PG_FUNCTION_INFO_V1(rrtimeslice_cmp);
+PG_FUNCTION_INFO_V1(rrtimeslice_hash);
 
 /*
  * public API
@@ -561,5 +563,12 @@ rrtimeslice_cmp(PG_FUNCTION_ARGS)
        PG_RETURN_INT32(rrtimeslice_cmp_internal(ts1, ts2));
 } /* rrtimeslice_ge */
 
+Datum
+rrtimeslice_hash(PG_FUNCTION_ARGS)
+{
+       rrtimeslice_t *ts = PG_GETARG_RRTIMESLICE_P(0);
+       return hash_uint32(ts->seq);
+} /* rrtimeslice_hash */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */