Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b632a5

Browse files
committed
simplehash: Add support for resetting a hashtable's contents.
A hashtable reset just reset the hashtable entries, but does not freememory.Author: Andres FreundDiscussion:https://postgr.es/m/20190114180423.ywhdg2iagzvh43we@alap3.anarazel.deBug: #15592 #15486Backpatch: 11, this is a prerequisite for other fixes
1 parent5567d12 commit3b632a5

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
#defineSH_CREATE SH_MAKE_NAME(create)
7474
#defineSH_DESTROY SH_MAKE_NAME(destroy)
75+
#defineSH_RESET SH_MAKE_NAME(reset)
7576
#defineSH_INSERT SH_MAKE_NAME(insert)
7677
#defineSH_DELETE SH_MAKE_NAME(delete)
7778
#defineSH_LOOKUP SH_MAKE_NAME(lookup)
@@ -140,6 +141,7 @@ typedef struct SH_ITERATOR
140141
SH_SCOPESH_TYPE*SH_CREATE(MemoryContextctx,uint32nelements,
141142
void*private_data);
142143
SH_SCOPEvoidSH_DESTROY(SH_TYPE*tb);
144+
SH_SCOPEvoidSH_RESET(SH_TYPE*tb);
143145
SH_SCOPEvoidSH_GROW(SH_TYPE*tb,uint32newsize);
144146
SH_SCOPESH_ELEMENT_TYPE*SH_INSERT(SH_TYPE*tb,SH_KEY_TYPEkey,bool*found);
145147
SH_SCOPESH_ELEMENT_TYPE*SH_LOOKUP(SH_TYPE*tb,SH_KEY_TYPEkey);
@@ -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_SCOPEvoid
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)

[8]ページ先頭

©2009-2025 Movatter.jp