1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* hashfn.c
|
2001-10-01 07:36:17 +02:00
|
|
|
* Hash functions for use in dynahash.c hashtables
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2003-08-04 04:40:20 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/hash/hashfn.c,v 1.18 2003/08/04 02:40:06 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-11-03 07:54:38 +01:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2002-03-09 18:35:37 +01:00
|
|
|
#include "access/hash.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "utils/hsearch.h"
|
|
|
|
|
2002-03-09 18:35:37 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2001-10-01 07:36:17 +02:00
|
|
|
* string_hash: hash function for keys that are null-terminated strings.
|
|
|
|
*
|
|
|
|
* NOTE: since dynahash.c backs this up with a fixed-length memcmp(),
|
|
|
|
* the key must actually be zero-padded to the specified maximum length
|
|
|
|
* to work correctly. However, if it is known that nothing after the
|
|
|
|
* first zero byte is interesting, this is the right hash function to use.
|
|
|
|
*
|
|
|
|
* NOTE: this is the default hash function if none is specified.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-03-09 18:35:37 +01:00
|
|
|
uint32
|
2001-10-01 07:36:17 +02:00
|
|
|
string_hash(void *key, int keysize)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-03-09 18:35:37 +01:00
|
|
|
return DatumGetUInt32(hash_any((unsigned char *) key, strlen((char *) key)));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2001-10-01 07:36:17 +02:00
|
|
|
/*
|
|
|
|
* tag_hash: hash function for fixed-size tag values
|
|
|
|
*/
|
2002-03-09 18:35:37 +01:00
|
|
|
uint32
|
2001-10-01 07:36:17 +02:00
|
|
|
tag_hash(void *key, int keysize)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-03-09 18:35:37 +01:00
|
|
|
return DatumGetUInt32(hash_any((unsigned char *) key, keysize));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|