summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/date.c30
-rw-r--r--src/backend/utils/adt/timestamp.c19
-rw-r--r--src/backend/utils/adt/varchar.c96
3 files changed, 54 insertions, 91 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 128216f2b8..952a8e6d4d 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -8,23 +8,27 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.47 2000/06/15 04:10:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.48 2000/06/19 03:54:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
-#include <limits.h>
-#include <time.h>
#include "postgres.h"
+
+#include <limits.h>
+#include <time.h>
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
+
+#include "access/hash.h"
#include "miscadmin.h"
#include "utils/date.h"
#include "utils/nabstime.h"
-static int
- date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn);
+
+static int date2tm(DateADT dateVal, int *tzp, struct tm * tm,
+ double *fsec, char **tzn);
/*****************************************************************************
@@ -762,6 +766,22 @@ timetz_cmp(PG_FUNCTION_ARGS)
PG_RETURN_INT32(0);
}
+/*
+ * timetz, being an unusual size, needs a specialized hash function.
+ */
+Datum
+timetz_hash(PG_FUNCTION_ARGS)
+{
+ TimeTzADT *key = PG_GETARG_TIMETZADT_P(0);
+
+ /*
+ * Specify hash length as sizeof(double) + sizeof(int4), not as
+ * sizeof(TimeTzADT), so that any garbage pad bytes in the structure
+ * won't be included in the hash!
+ */
+ return hash_any((char *) key, sizeof(double) + sizeof(int4));
+}
+
Datum
timetz_larger(PG_FUNCTION_ARGS)
{
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 7715942a28..71549bb925 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.29 2000/06/09 01:11:09 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.30 2000/06/19 03:54:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include <sys/timeb.h>
#endif
+#include "access/hash.h"
#include "access/xact.h"
#include "miscadmin.h"
#include "utils/builtins.h"
@@ -816,6 +817,22 @@ interval_cmp(PG_FUNCTION_ARGS)
PG_RETURN_INT32((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
}
+/*
+ * interval, being an unusual size, needs a specialized hash function.
+ */
+Datum
+interval_hash(PG_FUNCTION_ARGS)
+{
+ Interval *key = PG_GETARG_INTERVAL_P(0);
+
+ /*
+ * Specify hash length as sizeof(double) + sizeof(int4), not as
+ * sizeof(Interval), so that any garbage pad bytes in the structure
+ * won't be included in the hash!
+ */
+ return hash_any((char *) key, sizeof(double) + sizeof(int4));
+}
+
/* overlaps_timestamp()
* Implements the SQL92 OVERLAPS operator.
* Algorithm from Date and Darwen, 1997
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index 00e4c8ef39..53c6ec4167 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -8,13 +8,14 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.65 2000/06/15 03:32:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.66 2000/06/19 03:54:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
+#include "access/hash.h"
#include "catalog/pg_type.h"
#include "utils/acl.h"
#include "utils/builtins.h"
@@ -797,94 +798,19 @@ varcharcmp(char *arg1, char *arg2)
return (int32) (cmp);
}
-/*****************************************************************************
- * Hash functions (modified from hashtext in access/hash/hashfunc.c)
- *****************************************************************************/
-
-uint32
-hashbpchar(struct varlena * key)
+/*
+ * bpchar needs a specialized hash function because we want to ignore
+ * trailing blanks in comparisons. (varchar can use plain hashvarlena.)
+ */
+Datum
+hashbpchar(PG_FUNCTION_ARGS)
{
- int keylen;
+ BpChar *key = PG_GETARG_BPCHAR_P(0);
char *keydata;
- uint32 n;
- int loop;
-
- keydata = VARDATA(key);
- keylen = bcTruelen((char *) key);
-
-#define HASHC n = *keydata++ + 65599 * n
-
- n = 0;
- if (keylen > 0)
- {
- loop = (keylen + 8 - 1) >> 3;
-
- switch (keylen & (8 - 1))
- {
- case 0:
- do
- { /* All fall throughs */
- HASHC;
- case 7:
- HASHC;
- case 6:
- HASHC;
- case 5:
- HASHC;
- case 4:
- HASHC;
- case 3:
- HASHC;
- case 2:
- HASHC;
- case 1:
- HASHC;
- } while (--loop);
- }
- }
- return n;
-}
-
-uint32
-hashvarchar(struct varlena * key)
-{
int keylen;
- char *keydata;
- uint32 n;
- int loop;
keydata = VARDATA(key);
- keylen = VARSIZE(key) - VARHDRSZ;
-
-#define HASHC n = *keydata++ + 65599 * n
+ keylen = bcTruelen((char *) key);
- n = 0;
- if (keylen > 0)
- {
- loop = (keylen + 8 - 1) >> 3;
-
- switch (keylen & (8 - 1))
- {
- case 0:
- do
- { /* All fall throughs */
- HASHC;
- case 7:
- HASHC;
- case 6:
- HASHC;
- case 5:
- HASHC;
- case 4:
- HASHC;
- case 3:
- HASHC;
- case 2:
- HASHC;
- case 1:
- HASHC;
- } while (--loop);
- }
- }
- return n;
+ return hash_any(keydata, keylen);
}