MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / HLen

Method HLen

structure/hash.go:536–557  ·  view source on GitHub ↗

HLen gets the number of fields contained in a hash. It takes a string key 'k' and returns the number of fields in the hash. Parameters: k: The key of the hash table. Returns: int: The number of fields in the hash. error: An error if occurred during the operation, or nil on success.

(key string)

Source from the content-addressed store, hash-verified

534// int: The number of fields in the hash.
535// error: An error if occurred during the operation, or nil on success.
536func (hs *HashStructure) HLen(key string) (int, error) {
537 // Convert the parameters to bytes
538 k := stringToBytesWithKey(key)
539
540 // Check the parameters
541 if len(k) == 0 {
542 return 0, _const.ErrKeyIsEmpty
543 }
544
545 // Find the hash metadata by the given key
546 hashMeta, err := hs.findHashMeta(key, Hash)
547 if err != nil {
548 return 0, err
549 }
550
551 // If the counter is 0, return 0
552 if hashMeta.counter == 0 {
553 return 0, nil
554 }
555
556 return int(hashMeta.counter), nil
557}
558
559// HUpdate updates the string value of a hash field.
560// It takes a string key 'k', a field 'f', and a value 'v' to update the field's value.

Callers

nothing calls this directly

Calls 2

findHashMetaMethod · 0.95
stringToBytesWithKeyFunction · 0.85

Tested by

no test coverage detected