Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
7831c888
Commit
7831c888
authored
Jul 24, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make UUID hashable
parent
c2be26e7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
0 deletions
+39
-0
libcaf_core/caf/hash/fnv.hpp
libcaf_core/caf/hash/fnv.hpp
+5
-0
libcaf_core/caf/uuid.hpp
libcaf_core/caf/uuid.hpp
+14
-0
libcaf_core/src/uuid.cpp
libcaf_core/src/uuid.cpp
+5
-0
libcaf_core/test/uuid.cpp
libcaf_core/test/uuid.cpp
+15
-0
No files found.
libcaf_core/caf/hash/fnv.hpp
View file @
7831c888
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include <cstdint>
#include <cstdint>
#include <type_traits>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/inspector_access.hpp"
#include "caf/inspector_access.hpp"
#include "caf/save_inspector_base.hpp"
#include "caf/save_inspector_base.hpp"
...
@@ -111,6 +112,10 @@ public:
...
@@ -111,6 +112,10 @@ public:
return
true
;
return
true
;
}
}
bool
value
(
byte
x
)
noexcept
{
return
value
(
static_cast
<
uint8_t
>
(
x
));
}
bool
value
(
bool
x
)
noexcept
{
bool
value
(
bool
x
)
noexcept
{
auto
tmp
=
static_cast
<
uint8_t
>
(
x
);
auto
tmp
=
static_cast
<
uint8_t
>
(
x
);
return
value
(
tmp
);
return
value
(
tmp
);
...
...
libcaf_core/caf/uuid.hpp
View file @
7831c888
...
@@ -107,6 +107,9 @@ public:
...
@@ -107,6 +107,9 @@ public:
/// (`randomized` UUIDs).
/// (`randomized` UUIDs).
uint64_t
node
()
const
noexcept
;
uint64_t
node
()
const
noexcept
;
/// Returns a platform-specific hash value for this UUID.
size_t
hash
()
const
noexcept
;
/// Creates a random UUID.
/// Creates a random UUID.
static
uuid
random
()
noexcept
;
static
uuid
random
()
noexcept
;
...
@@ -169,3 +172,14 @@ bool inspect(Inspector& f, uuid& x) {
...
@@ -169,3 +172,14 @@ bool inspect(Inspector& f, uuid& x) {
}
}
}
// namespace caf
}
// namespace caf
namespace
std
{
template
<
>
struct
hash
<
caf
::
uuid
>
{
size_t
operator
()(
const
caf
::
uuid
&
x
)
const
noexcept
{
return
x
.
hash
();
}
};
}
// namespace std
libcaf_core/src/uuid.cpp
View file @
7831c888
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include "caf/detail/network_order.hpp"
#include "caf/detail/network_order.hpp"
#include "caf/detail/parser/add_ascii.hpp"
#include "caf/detail/parser/add_ascii.hpp"
#include "caf/expected.hpp"
#include "caf/expected.hpp"
#include "caf/hash/fnv.hpp"
#include "caf/message.hpp"
#include "caf/message.hpp"
#include "caf/parser_state.hpp"
#include "caf/parser_state.hpp"
...
@@ -107,6 +108,10 @@ uint64_t uuid::node() const noexcept {
...
@@ -107,6 +108,10 @@ uint64_t uuid::node() const noexcept {
return
detail
::
from_network_order
(
result
);
return
detail
::
from_network_order
(
result
);
}
}
size_t
uuid
::
hash
()
const
noexcept
{
return
hash
::
fnv
<
size_t
>::
compute
(
bytes_
);
}
namespace
{
namespace
{
enum
parse_result
{
enum
parse_result
{
...
...
libcaf_core/test/uuid.cpp
View file @
7831c888
...
@@ -161,4 +161,19 @@ SCENARIO("UUIDs are inspectable") {
...
@@ -161,4 +161,19 @@ SCENARIO("UUIDs are inspectable") {
}
}
}
}
SCENARIO
(
"UUIDs are hashable"
)
{
GIVEN
(
"two UUIDs "
)
{
auto
id1
=
"2ee4ded7-69c0-4dd6-876d-02e446b21784"
_uuid
;
auto
id2
=
"a6155548-2994-4833-b4e3-9823f5f15fe9"
_uuid
;
WHEN
(
"retrieving a hash value for the UUIDs"
)
{
THEN
(
"the UUIDs return different hash values"
)
{
std
::
hash
<
uuid
>
f
;
CHECK_EQ
(
id1
.
hash
(),
f
(
id1
));
CHECK_EQ
(
id2
.
hash
(),
f
(
id2
));
CHECK_NE
(
f
(
id1
),
f
(
id2
));
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
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