Skip to content

Commit 350b0a4

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 9cf37a5 commit 350b0a4

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);
@@ -356,6 +358,14 @@ SH_DESTROY(SH_TYPE * tb)
356358
pfree(tb);
357359
}
358360

361+
/* reset the contents of a previously created hash table */
362+
SH_SCOPE void
363+
SH_RESET(SH_TYPE * tb)
364+
{
365+
memset(tb->data, 0, sizeof(SH_ELEMENT_TYPE) * tb->size);
366+
tb->members = 0;
367+
}
368+
359369
/*
360370
* Grow a hash table to at least `newsize` buckets.
361371
*
@@ -946,6 +956,7 @@ SH_STAT(SH_TYPE * tb)
946956
/* external function names */
947957
#undef SH_CREATE
948958
#undef SH_DESTROY
959+
#undef SH_RESET
949960
#undef SH_INSERT
950961
#undef SH_DELETE
951962
#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