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

Commit9ed3ee5

Browse files
committed
Simplify initialization of incremental hash state
The standalone functions fasthash{32,64} use length for two purposes:how many bytes to hash, and how to perturb the internal seed.Developers using the incremental interface may not know the lengthahead of time (e.g. for C strings). In this case, it's advised topass length to the finalizer, but initialization still needed somelength up front, in the form of a placeholder macro.Separate the concerns by having the standalone functions perturb theinternal seed themselves from their own length parameter, allowingto remove "len" from fasthash_init(), as well as the placeholder macro.Discussion:https://postgr.es/m/CANWCAZbTUk2LOyhsFo33gjLyLAHZ7ucXCi5K9u%3D%2BPtnTShDKtw%40mail.gmail.com
1 parent1f61680 commit9ed3ee5

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

‎src/backend/catalog/namespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ spcachekey_hash(SearchPathCacheKey key)
256256
fasthash_statehs;
257257
intsp_len;
258258

259-
fasthash_init(&hs,FH_UNKNOWN_LENGTH,0);
259+
fasthash_init(&hs,0);
260260

261261
hs.accum=key.roleid;
262262
fasthash_combine(&hs);

‎src/include/common/hashfn_unstable.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@
6565
* in fasthash_accum_cstring() :
6666
*
6767
* fasthash_state hs;
68-
* fasthash_init(&hs,FH_UNKNOWN_LENGTH,0);
68+
* fasthash_init(&hs, 0);
6969
* len = fasthash_accum_cstring(&hs, *str);
7070
* ...
7171
* return fasthash_final32(&hs, len);
7272
*
73-
* Here we pass FH_UNKNOWN_LENGTH as a convention, since passing zero
74-
* would zero out the internal seed as well. fasthash_accum_cstring()
75-
* returns the length of the string, which is computed on-the-fly while
76-
* mixing the string into the hash. Experimentation has found that
73+
* The length is computed on-the-fly. Experimentation has found that
7774
* SMHasher fails unless we incorporate the length, so it is passed to
7875
* the finalizer as a tweak.
7976
*/
@@ -89,20 +86,17 @@ typedef struct fasthash_state
8986

9087
#defineFH_SIZEOF_ACCUM sizeof(uint64)
9188

92-
#defineFH_UNKNOWN_LENGTH 1
9389

9490
/*
9591
* Initialize the hash state.
9692
*
97-
* 'len' is the length of the input, if known ahead of time.
98-
* If that is not known, pass FH_UNKNOWN_LENGTH.
9993
* 'seed' can be zero.
10094
*/
10195
staticinlinevoid
102-
fasthash_init(fasthash_state*hs,intlen,uint64seed)
96+
fasthash_init(fasthash_state*hs,uint64seed)
10397
{
10498
memset(hs,0,sizeof(fasthash_state));
105-
hs->hash=seed ^(len*0x880355f21e6d1965);
99+
hs->hash=seed ^0x880355f21e6d1965;
106100
}
107101

108102
/* both the finalizer and part of the combining step */
@@ -328,7 +322,10 @@ fasthash64(const char *k, int len, uint64 seed)
328322
{
329323
fasthash_statehs;
330324

331-
fasthash_init(&hs,len,seed);
325+
fasthash_init(&hs,0);
326+
327+
/* re-initialize the seed according to input length */
328+
hs.hash=seed ^ (len*0x880355f21e6d1965);
332329

333330
while (len >=FH_SIZEOF_ACCUM)
334331
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp