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

Method Size

structure/set.go:477–512  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

475}
476
477func (s *SetStructure) Size(key string) (string, error) {
478
479 members, err := s.SMembers(key)
480 if err != nil {
481 return "", err
482 }
483 var sizeInBytes int
484
485 // Calculate the size of the value
486 for _, v := range members {
487 toString, err := interfaceToString(v)
488 if err != nil {
489 return "", err
490 }
491 sizeInBytes += len(toString)
492 }
493
494 // Convert bytes to corresponding units (KB, MB...)
495 const (
496 KB = 1 << 10
497 MB = 1 << 20
498 GB = 1 << 30
499 )
500
501 var size string
502 switch {
503 case sizeInBytes < KB:
504 size = fmt.Sprintf("%dB", sizeInBytes)
505 case sizeInBytes < MB:
506 size = fmt.Sprintf("%.2fKB", float64(sizeInBytes)/KB)
507 case sizeInBytes < GB:
508 size = fmt.Sprintf("%.2fMB", float64(sizeInBytes)/MB)
509 }
510
511 return size, nil
512}
513
514func (s *SetStructure) SDel(key string) error {
515 byteKey := stringToBytesWithKey(key)

Callers

nothing calls this directly

Calls 2

SMembersMethod · 0.95
interfaceToStringFunction · 0.85

Tested by

no test coverage detected