mirror of https://github.com/citusdata/citus.git
Add some basic helpers to make use of dynahash hashtables easier.
parent
4347daaf4c
commit
883af02b54
|
@ -0,0 +1,34 @@
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* hash_helpers.c
|
||||||
|
* Helpers for dynahash.c style hash tables.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016, Citus Data, Inc.
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "distributed/hash_helpers.h"
|
||||||
|
#include "utils/hsearch.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Empty a hash, without destroying the hash table itself.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
hash_delete_all(HTAB *htab)
|
||||||
|
{
|
||||||
|
HASH_SEQ_STATUS status;
|
||||||
|
void *entry = NULL;
|
||||||
|
|
||||||
|
hash_seq_init(&status, htab);
|
||||||
|
while ((entry = hash_seq_search(&status)) != 0)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
hash_search(htab, entry, HASH_REMOVE, &found);
|
||||||
|
Assert(found);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* hash_helpers.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016, Citus Data, Inc.
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HASH_HELPERS_H
|
||||||
|
#define HASH_HELPERS_H
|
||||||
|
|
||||||
|
#include "utils/hsearch.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Combine two hash values, resulting in another hash value, with decent bit
|
||||||
|
* mixing.
|
||||||
|
*
|
||||||
|
* Similar to boost's hash_combine().
|
||||||
|
*/
|
||||||
|
static inline uint32
|
||||||
|
hash_combine(uint32 a, uint32 b)
|
||||||
|
{
|
||||||
|
a ^= b + 0x9e3779b9 + (a << 6) + (a >> 2);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void hash_delete_all(HTAB *htab);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue