summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r--src/mongo/bson/bsonelement.cpp110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 929af2878f5..34b4b07576d 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -1010,114 +1010,4 @@ int compareElementValues(const BSONElement& l,
return -1;
}
-size_t BSONElement::Hasher::operator()(const BSONElement& elem) const {
- size_t hash = 0;
-
- boost::hash_combine(hash, elem.canonicalType());
-
- const StringData fieldName = elem.fieldNameStringData();
- if (!fieldName.empty()) {
- boost::hash_combine(hash, SimpleStringDataComparator::kInstance.hash(fieldName));
- }
-
- switch (elem.type()) {
- // Order of types is the same as in compareElementValues().
-
- case mongo::EOO:
- case mongo::Undefined:
- case mongo::jstNULL:
- case mongo::MaxKey:
- case mongo::MinKey:
- // These are valueless types
- break;
-
- case mongo::Bool:
- boost::hash_combine(hash, elem.boolean());
- break;
-
- case mongo::bsonTimestamp:
- boost::hash_combine(hash, elem.timestamp().asULL());
- break;
-
- case mongo::Date:
- boost::hash_combine(hash, elem.date().asInt64());
- break;
-
- case mongo::NumberDecimal: {
- const Decimal128 dcml = elem.numberDecimal();
- if (dcml.toAbs().isGreater(Decimal128(std::numeric_limits<double>::max(),
- Decimal128::kRoundTo34Digits,
- Decimal128::kRoundTowardZero)) &&
- !dcml.isInfinite() && !dcml.isNaN()) {
- // Normalize our decimal to force equivalent decimals
- // in the same cohort to hash to the same value
- Decimal128 dcmlNorm(dcml.normalize());
- boost::hash_combine(hash, dcmlNorm.getValue().low64);
- boost::hash_combine(hash, dcmlNorm.getValue().high64);
- break;
- }
- // Else, fall through and convert the decimal to a double and hash.
- // At this point the decimal fits into the range of doubles, is infinity, or is NaN,
- // which doubles have a cheaper representation for.
- }
- case mongo::NumberDouble:
- case mongo::NumberLong:
- case mongo::NumberInt: {
- // This converts all numbers to doubles, which ignores the low-order bits of
- // NumberLongs > 2**53 and precise decimal numbers without double representations,
- // but that is ok since the hash will still be the same for equal numbers and is
- // still likely to be different for different numbers. (Note: this issue only
- // applies for decimals when they are outside of the valid double range. See
- // the above case.)
- // SERVER-16851
- const double dbl = elem.numberDouble();
- if (std::isnan(dbl)) {
- boost::hash_combine(hash, std::numeric_limits<double>::quiet_NaN());
- } else {
- boost::hash_combine(hash, dbl);
- }
- break;
- }
-
- case mongo::jstOID:
- elem.__oid().hash_combine(hash);
- break;
-
- case mongo::Code:
- case mongo::Symbol:
- case mongo::String:
- boost::hash_combine(hash,
- SimpleStringDataComparator::kInstance.hash(elem.valueStringData()));
- break;
-
- case mongo::Object:
- case mongo::Array:
- boost::hash_combine(hash, BSONObj::Hasher()(elem.embeddedObject()));
- break;
-
- case mongo::DBRef:
- case mongo::BinData:
- // All bytes of the value are required to be identical.
- boost::hash_combine(hash,
- SimpleStringDataComparator::kInstance.hash(
- StringData(elem.value(), elem.valuesize())));
- break;
-
- case mongo::RegEx:
- boost::hash_combine(hash, SimpleStringDataComparator::kInstance.hash(elem.regex()));
- boost::hash_combine(hash,
- SimpleStringDataComparator::kInstance.hash(elem.regexFlags()));
- break;
-
- case mongo::CodeWScope: {
- boost::hash_combine(hash,
- SimpleStringDataComparator::kInstance.hash(
- StringData(elem.codeWScopeCode(), elem.codeWScopeCodeLen())));
- boost::hash_combine(hash, BSONObj::Hasher()(elem.codeWScopeObject()));
- break;
- }
- }
- return hash;
-}
-
} // namespace mongo