Skip to content

Commit 3b632a5

Browse files
committed
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
1 parent 5567d12 commit 3b632a5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/include/lib/simplehash.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
/* function declarations */
7373
#define SH_CREATE SH_MAKE_NAME(create)
7474
#define SH_DESTROY SH_MAKE_NAME(destroy)
75+
#define SH_RESET SH_MAKE_NAME(reset)
7576
#define SH_INSERT SH_MAKE_NAME(insert)
7677
#define SH_DELETE SH_MAKE_NAME(delete)
7778
#define SH_LOOKUP SH_MAKE_NAME(lookup)
@@ -140,6 +141,7 @@ typedef struct SH_ITERATOR
140141
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements,
141142
void *private_data);
142143
SH_SCOPE void SH_DESTROY(SH_TYPE * tb);
144+
SH_SCOPE void SH_RESET(SH_TYPE * tb);
143145
SH_SCOPE void SH_GROW(SH_TYPE * tb, uint32 newsize);
144146
SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE * tb, SH_KEY_TYPE key, bool *found);
145147
SH_SCOPE SH_ELEMENT_TYPE *SH_LOOKUP(SH_TYPE * tb, SH_KEY_TYPE key);
@@ -368,6 +370,14 @@ SH_DESTROY(SH_TYPE * tb)
368370
pfree(tb);
369371
}
370372

373+
/* reset the contents of a previously created hash table */
374+
SH_SCOPE void
375+
SH_RESET(SH_TYPE * tb)
376+
{
377+
memset(tb->data, 0, sizeof(SH_ELEMENT_TYPE) * tb->size);
378+
tb->members = 0;
379+
}
380+
371381
/*
372382
* Grow a hash table to at least `newsize` buckets.
373383
*
@@ -959,6 +969,7 @@ SH_STAT(SH_TYPE * tb)
959969
/* external function names */
960970
#undef SH_CREATE
961971
#undef SH_DESTROY
972+
#undef SH_RESET
962973
#undef SH_INSERT
963974
#undef SH_DELETE
964975
#undef SH_LOOKUP

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy