MCPcopy Create free account
hub / github.com/documentdb/documentdb / HashBsonValueCompare

Function HashBsonValueCompare

pg_documentdb_core/src/query/bson_hash.c:523–757  ·  view source on GitHub ↗

* Hashes a value assuming that if ValueA == ValueB * Hash(ValueA) == Hash(ValueB) * * CODESYNC: This needs to match the behavior of CompareBsonValue in bson_compare.c */

Source from the content-addressed store, hash-verified

521 * CODESYNC: This needs to match the behavior of CompareBsonValue in bson_compare.c
522 */
523static uint64_t
524HashBsonValueCompare(const bson_value_t *value,
525 uint64 (*hash_bytes_func)(const uint8_t *bytes, uint32_t bytesLength,
526 int64 seed),
527 uint64 (*hash_combine_func)(uint64 left, uint64 right),
528 int64 seed,
529 const char *collationString)
530{
531 int typeCodeInt = (int) value->value_type;
532 switch (value->value_type)
533 {
534 case BSON_TYPE_EOD:
535 case BSON_TYPE_MINKEY:
536 {
537 typeCodeInt = (int) BSON_TYPE_MINKEY;
538 return hash_bytes_func((uint8_t *) &typeCodeInt, sizeof(int), seed);
539 }
540
541 case BSON_TYPE_UNDEFINED:
542 case BSON_TYPE_NULL:
543 {
544 typeCodeInt = (int) BSON_TYPE_UNDEFINED;
545 return hash_bytes_func((uint8_t *) &typeCodeInt, sizeof(int), seed);
546 }
547
548 case BSON_TYPE_INT32:
549 case BSON_TYPE_INT64:
550 {
551 /* All numbers are cocomparable - use a fixed type code */
552 typeCodeInt = BSON_TYPE_INT64;
553 int64_t int64Value = BsonValueAsInt64(value);
554 return hash_combine_func(
555 hash_bytes_func((uint8_t *) &typeCodeInt, sizeof(int), seed),
556 hash_bytes_func((uint8_t *) &int64Value, sizeof(int64_t), seed));
557 }
558
559 case BSON_TYPE_DOUBLE:
560 case BSON_TYPE_DECIMAL128:
561 {
562 /* All numbers are cocomparable - use a fixed type code */
563 typeCodeInt = BSON_TYPE_INT64;
564 bool checkFixedInteger = true;
565 if (IsBsonValue64BitInteger(value, checkFixedInteger))
566 {
567 int64_t int64Value = BsonValueAsInt64(value);
568 return hash_combine_func(
569 hash_bytes_func((uint8_t *) &typeCodeInt, sizeof(int), seed),
570 hash_bytes_func((uint8_t *) &int64Value, sizeof(int64_t), seed));
571 }
572
573 bson_decimal128_t decimalValue = GetBsonValueAsDecimal128(value);
574 return hash_combine_func(
575 hash_bytes_func((uint8_t *) &typeCodeInt, sizeof(int), seed),
576 hash_bytes_func((uint8_t *) &decimalValue, sizeof(bson_decimal128_t),
577 seed));
578 }
579
580 case BSON_TYPE_UTF8:

Callers 3

HashBsonValueComparableFunction · 0.85
BsonHashCompareFunction · 0.85

Calls 6

BsonValueAsInt64Function · 0.85
IsBsonValue64BitIntegerFunction · 0.85
GetBsonValueAsDecimal128Function · 0.85
IsCollationApplicableFunction · 0.85
GetCollationSortKeyFunction · 0.85
BsonHashCompareFunction · 0.85

Tested by

no test coverage detected