MCPcopy
hub / github.com/pingcap/tidb / HashCode

Function HashCode

pkg/util/codec/codec.go:1606–1659  ·  view source on GitHub ↗

HashCode encodes a Datum into a unique byte slice. It is mostly the same as EncodeValue, but it doesn't contain truncation or verification logic in order to make the encoding lossless.

(b []byte, d types.Datum)

Source from the content-addressed store, hash-verified

1604// HashCode encodes a Datum into a unique byte slice.
1605// It is mostly the same as EncodeValue, but it doesn't contain truncation or verification logic in order to make the encoding lossless.
1606func HashCode(b []byte, d types.Datum) []byte {
1607 switch d.Kind() {
1608 case types.KindInt64:
1609 b = encodeSignedInt(b, d.GetInt64(), false)
1610 case types.KindUint64:
1611 b = encodeUnsignedInt(b, d.GetUint64(), false)
1612 case types.KindFloat32, types.KindFloat64:
1613 b = append(b, floatFlag)
1614 b = EncodeFloat(b, d.GetFloat64())
1615 case types.KindString:
1616 b = encodeString(b, d, false)
1617 case types.KindBytes:
1618 b = encodeBytes(b, d.GetBytes(), false)
1619 case types.KindMysqlTime:
1620 b = append(b, uintFlag)
1621 t := d.GetMysqlTime().CoreTime()
1622 b = encodeUnsignedInt(b, uint64(t), true)
1623 case types.KindMysqlDuration:
1624 // duration may have negative value, so we cannot use String to encode directly.
1625 b = append(b, durationFlag)
1626 b = EncodeInt(b, int64(d.GetMysqlDuration().Duration))
1627 case types.KindMysqlDecimal:
1628 b = append(b, decimalFlag)
1629 decStr := d.GetMysqlDecimal().ToString()
1630 b = encodeBytes(b, decStr, false)
1631 case types.KindMysqlEnum:
1632 b = encodeUnsignedInt(b, d.GetMysqlEnum().Value, false)
1633 case types.KindMysqlSet:
1634 b = encodeUnsignedInt(b, d.GetMysqlSet().Value, false)
1635 case types.KindMysqlBit, types.KindBinaryLiteral:
1636 val := d.GetBinaryLiteral()
1637 b = encodeBytes(b, val, false)
1638 case types.KindMysqlJSON:
1639 b = append(b, jsonFlag)
1640 j := d.GetMysqlJSON()
1641 b = append(b, j.TypeCode)
1642 b = append(b, j.Value...)
1643 case types.KindVectorFloat32:
1644 b = append(b, vectorFloat32Flag)
1645 v := d.GetVectorFloat32()
1646 b = v.SerializeTo(b)
1647 case types.KindNull:
1648 b = append(b, NilFlag)
1649 case types.KindMinNotNull:
1650 b = append(b, bytesFlag)
1651 case types.KindMaxValue:
1652 b = append(b, maxFlag)
1653 default:
1654 logutil.BgLogger().Warn("trying to calculate HashCode of an unexpected type of Datum",
1655 zap.Uint8("Datum Kind", d.Kind()),
1656 zap.Stack("stack"))
1657 }
1658 return b
1659}

Callers 3

getCorColHashCodeFunction · 0.92
getHashCodeMethod · 0.92
Hash64Function · 0.85

Calls 15

BgLoggerFunction · 0.92
encodeSignedIntFunction · 0.85
encodeUnsignedIntFunction · 0.85
EncodeFloatFunction · 0.85
encodeStringFunction · 0.85
EncodeIntFunction · 0.85
CoreTimeMethod · 0.80
GetMysqlTimeMethod · 0.80
GetMysqlDurationMethod · 0.80
GetMysqlEnumMethod · 0.80
GetMysqlSetMethod · 0.80
GetMysqlJSONMethod · 0.80

Tested by

no test coverage detected