MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / HMove

Method HMove

structure/hash.go:955–1031  ·  view source on GitHub ↗

HMove moves a field from a source hash to a destination hash. It takes the source key 'source', the destination key 'destination', and the field 'f' to be moved. It returns a boolean indicating the success of the move and any possible error. Parameters: source: The source hash key. destination:

(source, destination string, field interface{})

Source from the content-addressed store, hash-verified

953// bool: True if the move was successful, false otherwise.
954// error: An error if occurred during the operation, or nil on success.
955func (hs *HashStructure) HMove(source, destination string, field interface{}) (bool, error) {
956 // Convert the parameters to bytes
957 f, err, _ := interfaceToBytes(field)
958 if err != nil {
959 return false, err
960 }
961
962 // Check the parameters
963 if len(source) == 0 || len(destination) == 0 || len(f) == 0 {
964 return false, _const.ErrKeyIsEmpty
965 }
966
967 // Find the hash metadata by the given source
968 sourceMeta, err := hs.findHashMeta(source, Hash)
969 if err != nil {
970 return false, err
971 }
972
973 // If the counter is 0, return false
974 if sourceMeta.counter == 0 {
975 return false, nil
976 }
977
978 // Find the hash metadata by the given destination
979 destinationMeta, err := hs.findHashMeta(destination, Hash)
980 if err != nil {
981 return false, err
982 }
983
984 // If the counter is 0, return false
985 if destinationMeta.counter == 0 {
986 return false, nil
987 }
988
989 // Create a new HashField for the source
990 hf := &HashField{
991 field: f,
992 key: []byte(source),
993 version: sourceMeta.version,
994 }
995
996 // Encode the HashField
997 hfBuf := hf.encodeHashField()
998
999 // Create a new HashField for the destination
1000 destinationHf := &HashField{
1001 field: f,
1002 key: []byte(destination),
1003 version: destinationMeta.version,
1004 }
1005
1006 // Encode the HashField
1007 destinationHfBuf := destinationHf.encodeHashField()
1008
1009 // Get the field from the database
1010 value, err := hs.db.Get(destinationHfBuf)
1011 if err != nil && err == _const.ErrKeyNotFound {
1012 return false, nil

Callers

nothing calls this directly

Calls 8

findHashMetaMethod · 0.95
encodeHashFieldMethod · 0.95
DeleteMethod · 0.95
PutMethod · 0.95
CommitMethod · 0.95
interfaceToBytesFunction · 0.85
NewWriteBatchMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected