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

Commit350b0a4

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 parent9cf37a5 commit350b0a4

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);
@@ -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_SCOPEvoid
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)

[8]ページ先頭

©2009-2025 Movatter.jp