diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/commands/hashcmd.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/commands/hashcmd.cpp')
-rw-r--r-- | src/mongo/db/commands/hashcmd.cpp | 106 |
1 files changed, 56 insertions, 50 deletions
diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp index 21fc475469d..a4f7c437630 100644 --- a/src/mongo/db/commands/hashcmd.cpp +++ b/src/mongo/db/commands/hashcmd.cpp @@ -46,60 +46,66 @@ namespace mongo { - using std::string; - using std::stringstream; +using std::string; +using std::stringstream; - // Testing only, enabled via command-line. - class CmdHashElt : public Command { - public: - CmdHashElt() : Command("_hashBSONElement") {}; - virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool slaveOk() const { return true; } - // No auth needed because it only works when enabled via command line. - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) {} - virtual void help( stringstream& help ) const { - help << "returns the hash of the first BSONElement val in a BSONObj"; - } +// Testing only, enabled via command-line. +class CmdHashElt : public Command { +public: + CmdHashElt() : Command("_hashBSONElement"){}; + virtual bool isWriteCommandForConfigServer() const { + return false; + } + virtual bool slaveOk() const { + return true; + } + // No auth needed because it only works when enabled via command line. + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) {} + virtual void help(stringstream& help) const { + help << "returns the hash of the first BSONElement val in a BSONObj"; + } - /* CmdObj has the form {"hash" : <thingToHash>} - * or {"hash" : <thingToHash>, "seed" : <number> } - * Result has the form - * {"key" : <thingTohash>, "seed" : <int>, "out": NumberLong(<hash>)} - * - * Example use in the shell: - *> db.runCommand({hash: "hashthis", seed: 1}) - *> {"key" : "hashthis", - *> "seed" : 1, - *> "out" : NumberLong(6271151123721111923), - *> "ok" : 1 } - **/ - bool run(OperationContext* txn, const string& db, - BSONObj& cmdObj, - int options, string& errmsg, - BSONObjBuilder& result){ - result.appendAs(cmdObj.firstElement(),"key"); + /* CmdObj has the form {"hash" : <thingToHash>} + * or {"hash" : <thingToHash>, "seed" : <number> } + * Result has the form + * {"key" : <thingTohash>, "seed" : <int>, "out": NumberLong(<hash>)} + * + * Example use in the shell: + *> db.runCommand({hash: "hashthis", seed: 1}) + *> {"key" : "hashthis", + *> "seed" : 1, + *> "out" : NumberLong(6271151123721111923), + *> "ok" : 1 } + **/ + bool run(OperationContext* txn, + const string& db, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { + result.appendAs(cmdObj.firstElement(), "key"); - int seed = 0; - if (cmdObj.hasField("seed")){ - if (! cmdObj["seed"].isNumber()) { - errmsg += "seed must be a number"; - return false; - } - seed = cmdObj["seed"].numberInt(); + int seed = 0; + if (cmdObj.hasField("seed")) { + if (!cmdObj["seed"].isNumber()) { + errmsg += "seed must be a number"; + return false; } - result.append( "seed" , seed ); - - result.append( "out" , BSONElementHasher::hash64( cmdObj.firstElement() , seed ) ); - return true; + seed = cmdObj["seed"].numberInt(); } - }; - MONGO_INITIALIZER(RegisterHashEltCmd)(InitializerContext* context) { - if (Command::testCommandsEnabled) { - // Leaked intentionally: a Command registers itself when constructed. - new CmdHashElt(); - } - return Status::OK(); + result.append("seed", seed); + + result.append("out", BSONElementHasher::hash64(cmdObj.firstElement(), seed)); + return true; } +}; +MONGO_INITIALIZER(RegisterHashEltCmd)(InitializerContext* context) { + if (Command::testCommandsEnabled) { + // Leaked intentionally: a Command registers itself when constructed. + new CmdHashElt(); + } + return Status::OK(); +} } |