From: Sebastian Harl Date: Thu, 3 May 2012 19:44:08 +0000 (+0200) Subject: rrtimeslice: Added hash function and operator class. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0478a7da8a276444f96d4d0a0a13fa9448ce9250;p=postrr.git rrtimeslice: Added hash function and operator class. --- diff --git a/src/postrr.h.in b/src/postrr.h.in index 92025db..9a25d4e 100644 --- a/src/postrr.h.in +++ b/src/postrr.h.in @@ -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 diff --git a/src/postrr.sql.in b/src/postrr.sql.in index ffdb3a7..c2b4821 100644 --- a/src/postrr.sql.in +++ b/src/postrr.sql.in @@ -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) diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c index d34da91..b086622 100644 --- a/src/rrtimeslice.c +++ b/src/rrtimeslice.c @@ -39,6 +39,7 @@ #include /* Postgres utilities */ +#include #include #include #include @@ -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 : */