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
9fb0ba2a
Unverified
Commit
9fb0ba2a
authored
Jan 13, 2020
by
Ge Jun
Committed by
GitHub
Jan 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1009 from pexeer/chenzj
bugfix to the hash function HashInts32.
parents
a3b22660
660b9b32
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
hash_tables.h
src/butil/containers/hash_tables.h
+3
-0
endpoint_unittest.cpp
test/endpoint_unittest.cpp
+27
-0
No files found.
src/butil/containers/hash_tables.h
View file @
9fb0ba2a
...
...
@@ -26,6 +26,7 @@
#include "butil/basictypes.h"
#include "butil/strings/string16.h"
#include "butil/build_config.h"
#include "butil/third_party/murmurhash3/murmurhash3.h" // fmix64
#if defined(COMPILER_MSVC)
#include <hash_map>
...
...
@@ -132,6 +133,8 @@ 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
);
...
...
test/endpoint_unittest.cpp
View file @
9fb0ba2a
...
...
@@ -19,6 +19,7 @@
#include "butil/errno.h"
#include "butil/endpoint.h"
#include "butil/logging.h"
#include "butil/containers/flat_map.h"
namespace
{
...
...
@@ -121,4 +122,30 @@ TEST(EndPointTest, hash_table) {
ASSERT_EQ
(
2u
,
m
.
size
());
}
TEST
(
EndPointTest
,
flat_map
)
{
butil
::
FlatMap
<
butil
::
EndPoint
,
int
>
m
;
ASSERT_EQ
(
0
,
m
.
init
(
1024
));
uint32_t
port
=
8088
;
butil
::
EndPoint
ep1
(
butil
::
IP_ANY
,
port
);
butil
::
EndPoint
ep2
(
butil
::
IP_ANY
,
port
);
++
m
[
ep1
];
++
m
[
ep2
];
ASSERT_EQ
(
1u
,
m
.
size
());
butil
::
ip_t
ip_addr
;
butil
::
str2ip
(
"10.10.10.10"
,
&
ip_addr
);
int
ip
=
butil
::
ip2int
(
ip_addr
);
for
(
int
i
=
0
;
i
<
1023
;
++
i
)
{
butil
::
EndPoint
ep
(
butil
::
int2ip
(
++
ip
),
port
);
++
m
[
ep
];
}
butil
::
BucketInfo
info
=
m
.
bucket_info
();
LOG
(
INFO
)
<<
"bucket info max long="
<<
info
.
longest_length
<<
" avg="
<<
info
.
average_length
<<
std
::
endl
;
ASSERT_LT
(
info
.
longest_length
,
32
)
<<
"detect hash collision and it's too large."
;
}
}
// end of namespace
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