summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2014-07-16 17:42:56 -0400
committerSpencer T Brody <spencer@mongodb.com>2014-07-17 12:53:56 -0400
commitf9a5d666e40d462cfd13fb31e590b0aa25db3133 (patch)
treeddedf8d155efda05b9e566322fa4659dcf5ced4c /src
parent782258785ff78679c18646bd86de7cb9cb780618 (diff)
downloadmongo-f9a5d666e40d462cfd13fb31e590b0aa25db3133.tar.gz
SERVER-14587 Add hash function to OID so it can be stored in an unordered_map
Diffstat (limited to 'src')
-rw-r--r--src/mongo/bson/oid.cpp6
-rw-r--r--src/mongo/bson/oid.h10
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.h5
3 files changed, 18 insertions, 3 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index 92664fd753c..b073c8efa49 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -50,6 +50,12 @@ namespace mongo {
boost::hash_combine(seed, z);
}
+ size_t OID::Hasher::operator() (const OID& oid) const {
+ size_t seed = 0;
+ oid.hash_combine(seed);
+ return seed;
+ }
+
// machine # before folding in the process id
OID::MachineAndPid OID::ourMachine;
diff --git a/src/mongo/bson/oid.h b/src/mongo/bson/oid.h
index b98e070eeac..d5063dc5f1b 100644
--- a/src/mongo/bson/oid.h
+++ b/src/mongo/bson/oid.h
@@ -53,6 +53,16 @@ namespace mongo {
*/
class OID {
public:
+
+ /**
+ * Functor compatible with std::hash for std::unordered_{map,set}
+ * Warning: The hash function is subject to change. Do not use in cases where hashes need
+ * to be consistent across versions.
+ */
+ struct Hasher {
+ size_t operator() (const OID& oid) const;
+ };
+
OID() : a(0), b(0) { }
enum {
diff --git a/src/mongo/db/repl/repl_coordinator_impl.h b/src/mongo/db/repl/repl_coordinator_impl.h
index 62e043f9d0c..97260d0fae7 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.h
+++ b/src/mongo/db/repl/repl_coordinator_impl.h
@@ -31,7 +31,6 @@
#include <boost/scoped_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
-#include <map>
#include <vector>
#include "mongo/base/status.h"
@@ -40,6 +39,7 @@
#include "mongo/db/repl/repl_coordinator.h"
#include "mongo/db/repl/replication_executor.h"
#include "mongo/db/repl/topology_coordinator_impl.h"
+#include "mongo/platform/unordered_map.h"
#include "mongo/util/net/hostandport.h"
namespace mongo {
@@ -189,8 +189,7 @@ namespace repl {
boost::scoped_ptr<boost::thread> _topCoordDriverThread;
// Maps nodes in this replication group to the last oplog operation they have committed
- // TODO(spencer): change to unordered_map
- typedef std::map<OID, OpTime> SlaveOpTimeMap;
+ typedef unordered_map<OID, OpTime, OID::Hasher> SlaveOpTimeMap;
SlaveOpTimeMap _slaveOpTimeMap;
// Current ReplicaSet state