Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
8eabe513
Commit
8eabe513
authored
Jan 13, 2020
by
jamesge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make butil::HashInts32 more consistent
parent
9fb0ba2a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
21 deletions
+1
-21
hash_tables.h
src/butil/containers/hash_tables.h
+1
-21
No files found.
src/butil/containers/hash_tables.h
View file @
8eabe513
...
...
@@ -121,30 +121,10 @@ using BUTIL_HASH_NAMESPACE::hash_multiset;
using
BUTIL_HASH_NAMESPACE
::
hash_set
;
// Implement hashing for pairs of at-most 32 bit integer values.
// When size_t is 32 bits, we turn the 64-bit hash code into 32 bits by using
// multiply-add hashing. This algorithm, as described in
// Theorem 4.3.3 of the thesis "Über die Komplexität der Multiplikation in
// eingeschränkten Branchingprogrammmodellen" by Woelfel, is:
//
// h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32
//
// Contact danakj@chromium.org for any questions.
inline
std
::
size_t
HashInts32
(
uint32_t
value1
,
uint32_t
value2
)
{
uint64_t
value1_64
=
value1
;
uint64_t
hash64
=
(
value1_64
<<
32
)
|
value2
;
hash64
=
fmix64
(
hash64
);
if
(
sizeof
(
std
::
size_t
)
>=
sizeof
(
uint64_t
))
return
static_cast
<
std
::
size_t
>
(
hash64
);
uint64_t
odd_random
=
481046412LL
<<
32
|
1025306955LL
;
uint32_t
shift_random
=
10121U
<<
16
;
hash64
=
hash64
*
odd_random
+
shift_random
;
std
::
size_t
high_bits
=
static_cast
<
std
::
size_t
>
(
hash64
>>
(
8
*
(
sizeof
(
uint64_t
)
-
sizeof
(
std
::
size_t
))));
return
high_bits
;
return
static_cast
<
size_t
>
(
fmix64
(
hash64
));
}
// Implement hashing for pairs of up-to 64-bit integer values.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment