simplehash: Add support for resetting a hashtable's contents.
A hashtable reset just reset the hashtable entries, but does not free memory. Author: Andres Freund Discussion: https://postgr.es/m/20190114180423.ywhdg2iagzvh43we@alap3.anarazel.de Bug: #15592 #15486 Backpatch: 11, this is a prerequisite for other fixes
This commit is contained in:
parent
9cf37a527c
commit
350b0a4037
@ -72,6 +72,7 @@
|
|||||||
/* function declarations */
|
/* function declarations */
|
||||||
#define SH_CREATE SH_MAKE_NAME(create)
|
#define SH_CREATE SH_MAKE_NAME(create)
|
||||||
#define SH_DESTROY SH_MAKE_NAME(destroy)
|
#define SH_DESTROY SH_MAKE_NAME(destroy)
|
||||||
|
#define SH_RESET SH_MAKE_NAME(reset)
|
||||||
#define SH_INSERT SH_MAKE_NAME(insert)
|
#define SH_INSERT SH_MAKE_NAME(insert)
|
||||||
#define SH_DELETE SH_MAKE_NAME(delete)
|
#define SH_DELETE SH_MAKE_NAME(delete)
|
||||||
#define SH_LOOKUP SH_MAKE_NAME(lookup)
|
#define SH_LOOKUP SH_MAKE_NAME(lookup)
|
||||||
@ -140,6 +141,7 @@ typedef struct SH_ITERATOR
|
|||||||
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements,
|
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements,
|
||||||
void *private_data);
|
void *private_data);
|
||||||
SH_SCOPE void SH_DESTROY(SH_TYPE * tb);
|
SH_SCOPE void SH_DESTROY(SH_TYPE * tb);
|
||||||
|
SH_SCOPE void SH_RESET(SH_TYPE * tb);
|
||||||
SH_SCOPE void SH_GROW(SH_TYPE * tb, uint32 newsize);
|
SH_SCOPE void SH_GROW(SH_TYPE * tb, uint32 newsize);
|
||||||
SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE * tb, SH_KEY_TYPE key, bool *found);
|
SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE * tb, SH_KEY_TYPE key, bool *found);
|
||||||
SH_SCOPE SH_ELEMENT_TYPE *SH_LOOKUP(SH_TYPE * tb, SH_KEY_TYPE key);
|
SH_SCOPE SH_ELEMENT_TYPE *SH_LOOKUP(SH_TYPE * tb, SH_KEY_TYPE key);
|
||||||
@ -356,6 +358,14 @@ SH_DESTROY(SH_TYPE * tb)
|
|||||||
pfree(tb);
|
pfree(tb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset the contents of a previously created hash table */
|
||||||
|
SH_SCOPE void
|
||||||
|
SH_RESET(SH_TYPE * tb)
|
||||||
|
{
|
||||||
|
memset(tb->data, 0, sizeof(SH_ELEMENT_TYPE) * tb->size);
|
||||||
|
tb->members = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Grow a hash table to at least `newsize` buckets.
|
* Grow a hash table to at least `newsize` buckets.
|
||||||
*
|
*
|
||||||
@ -946,6 +956,7 @@ SH_STAT(SH_TYPE * tb)
|
|||||||
/* external function names */
|
/* external function names */
|
||||||
#undef SH_CREATE
|
#undef SH_CREATE
|
||||||
#undef SH_DESTROY
|
#undef SH_DESTROY
|
||||||
|
#undef SH_RESET
|
||||||
#undef SH_INSERT
|
#undef SH_INSERT
|
||||||
#undef SH_DELETE
|
#undef SH_DELETE
|
||||||
#undef SH_LOOKUP
|
#undef SH_LOOKUP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user