1
0
Fork 0

Add hash and equals_to for EdgeDocumentToken (#8709)

This commit is contained in:
Markus Pfeiffer 2019-04-12 10:42:07 +01:00 committed by Michael Hackstein
parent b3224eed1d
commit af400d0af7
1 changed files with 27 additions and 1 deletions

View File

@ -29,6 +29,7 @@
#include "VocBase/LocalDocumentId.h"
#include "VocBase/voc-types.h"
#include <velocypack/Slice.h>
#include <velocypack/StringRef.h>
namespace arangodb {
@ -128,6 +129,15 @@ struct EdgeDocumentToken {
return equalsLocal(other);
}
size_t hash() const {
if (ServerState::instance()->isCoordinator()) {
auto vslice = arangodb::velocypack::Slice(vpack());
return vslice.hash();
}
return std::hash<LocalDocumentId>{}(_data.document.localDocumentId) ^
(_data.document.cid << 1);
}
private:
/// Identifying information for an edge documents valid on one server
/// only used on a dbserver or single server
@ -171,6 +181,22 @@ struct EdgeDocumentToken {
#endif
};
} // namespace graph
} // namespace arangodb
namespace std {
template <>
struct hash<arangodb::graph::EdgeDocumentToken> {
size_t operator()(arangodb::graph::EdgeDocumentToken const& value) const noexcept {
return value.hash();
}
};
template <>
struct equal_to<arangodb::graph::EdgeDocumentToken> {
bool operator()(arangodb::graph::EdgeDocumentToken const& lhs,
arangodb::graph::EdgeDocumentToken const& rhs) const noexcept {
return lhs.equals(rhs);
}
};
} // namespace std
#endif