MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / DecrementFloat

Method DecrementFloat

pkg/util/cache/cache.go:615–634  ·  view source on GitHub ↗

Decrement an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to decrement it by n. Pass a negative number to decrement the value. To retrieve the decremented value, use one of the specialized methods, e.g

(k string, n float64)

Source from the content-addressed store, hash-verified

613// value. To retrieve the decremented value, use one of the specialized methods,
614// e.g. DecrementFloat64.
615func (c *cache) DecrementFloat(k string, n float64) error {
616 c.mu.Lock()
617 v, found := c.items[k]
618 if !found || v.Expired() {
619 c.mu.Unlock()
620 return fmt.Errorf("Item %s not found", k)
621 }
622 switch v.Object.(type) {
623 case float32:
624 v.Object = v.Object.(float32) - float32(n)
625 case float64:
626 v.Object = v.Object.(float64) - n
627 default:
628 c.mu.Unlock()
629 return fmt.Errorf("The value for %s does not have type float32 or float64", k)
630 }
631 c.items[k] = v
632 c.mu.Unlock()
633 return nil
634}
635
636// Decrement an item of type int by n. Returns an error if the item's value is
637// not an int, or if it was not found. If there is no error, the decremented

Callers 2

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 2