class_docstr: Generic supertype for cache implementations.
  
  Defines a dict-like mapping with a maximum size, where as well as mapping
  to a value, each key also maps to a score. When a write would cause the
  dict to exceed its maximum size, it first evicts the existing key with
  the smallest score, then adds the new key to the map.
  
  A key has the following lifecycle:
  
  1. key is written for the first time, the key is given the score
     self.new_entry(key, value)
  2. whenever an existing key is read or written, self.on_access(key, value,
     score) is called. This returns a new score for the key.
  3. When a key is evicted, self.on_evict(key, value, score) is called.
  
  The cache will be in a valid state in all of these cases.
  
  Implementations are expected to implement new_entry and optionally
  on_access and on_evict to implement a specific scoring strategy.
docstr: When we have made a modification to the heap such that means that
  the heap property has been violated locally around i but previously
  held for all other indexes (and no other values have been modified),
  this fixes the heap so that the heap property holds everywhere.
docstr_tok: ["When","we","have","made","a","modification","to","the","heap","such","that","means","that","the","heap","property","has","been","violated","locally","around","i","but","previously","held","for","all","other","indexes","(","and","no","other","values","have","been","modified",")",",","this","fixes","the","heap","so","that","the","heap","property","holds","everywhere","."]
code: def __balance(self, i):
      """When we have made a modification to the heap such that means that
      the heap property has been violated locally around i but previously
      held for all other indexes (and no other values have been modified),
      this fixes the heap so that the heap property holds everywhere."""
      while i > 0:
          parent = (i - 1) // 2
          if self.__out_of_order(parent, i):
              self.__swap(parent, i)
              i = parent
          else:
              break
      while True:
          children = [
              j for j in (2 * i + 1, 2 * i + 2) if j < len(self.data)
          ]
          if len(children) == 2:
              children.sort(key=lambda j: self.data[j].score)
          for j in children:
              if self.__out_of_order(i, j):
                  self.__swap(i, j)
                  i = j
                  break
          else:
              break
  
imports: from __future__ import absolute_import, division, print_function
  import attr
label_desc: Use image node_id 17 for calling the GenericCache obj's underlying member method code with example usage: obj.__balance(i) without return types